This repository has been archived by the owner on Mar 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
presentation.Rmd
551 lines (380 loc) · 22 KB
/
presentation.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
---
title: "Prüfungstutorium QM2"
author: "Tobi, Lukas"
date: "Rendered at `r format(Sys.time(), '%F %H:%M')`"
output:
ioslides_presentation:
css: styles.css
fig_height: 4
fig_width: 8
lib_dir: "assets"
incremental: yes
logo: RStudio-Ball.png
self_contained: no
smaller: yes
transition: slower
widescreen: yes
html_document:
fig_caption: yes
fig_width: 9
lib_dir: "assets"
number_sections: no
self_contained: no
toc: true
toc_float: true
code_folding: show
prettydoc::html_pretty:
theme: cayman
highlight: github
fig_caption: yes
fig_width: 9
lib_dir: "assets"
number_sections: no
self_contained: no
toc: true
---
```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.path = "plots/", fig.align = "center",
fig.retina = 2, echo = F, warning = F, message = F)
load(url("http://qm.jemu.name/data/ngo"))
# Package init script
# suppressWarnings(source("http://stats.jemu.name/qm/tools/package-init.R"))
library(sjPlot)
library(dplyr)
library(knitr)
library(ggplot2)
library(tadaatoolbox)
library(mosaic)
library(magrittr)
library(car)
library(broom)
library(tidyr)
library(pwr)
library(nortest)
library(haven)
# 3 digits are enough
options(digits = 3)
```
# Intro
![](img/pumped_Tld8USHlpopYA.gif)
## Diese Präsentation… {.flexbox .vcenter}
[Als Slideshow (das hier)](http://public.tadaa-data.de/QM/pruefungstutorien/qm2_sose_16/Presentation.html)
[Als Website (durchsuchbar)](http://public.tadaa-data.de/QM/pruefungstutorien/qm2_sose_16/Presentation_web.html)
$\rightarrow$ public.tadaa-data.de/QM $\leftarrow$
# Aufgabenblock 1 | Berechnungen per Software
![](img/typing_5yLgoc7NuyKE9aHTEGY.gif)
## Aufgabe 1: 𝜒²-Test
Prüfen Sie die Hypothese, ob zwischen den Merkmalen **Geschlecht** und **Abschalten**
innerhalb der Grundgesamtheit aller **NGO-SchülerInnen** eine statistische Beziehung existiert. Lassen Sie sich bei der Ausgabe eine Kontigenztabelle mitanzeigen.
Berechnen Sie den Testwert per Hand.
```{r a01_table}
t1 <- sjt.xtab(var.row = ngo$abschalt, var.col = ngo$geschl,
show.col.prc = TRUE, show.exp = TRUE, show.legend = TRUE, show.summary = FALSE,
use.viewer = F, no.output = T)
```
<div align="center">
`r t1$knitr`
$\chi^2 = \frac{(60-69)^2}{69} + \frac{(78-69)^2}{69} + \frac{(63-54)^2}{54} + \frac{(45-54)^2}{54} \approx 5.348$
</div>
## Aufgabe 2: z-Test
Es wird davon ausgegangen, dass das Merkmal **Unterrichtsstunden** in der Grundgesamtheit der **250 NGO-SchülerInnen** $N(\mu,1.5)$-verteilt ist. Es ist eine Prüfung der Nullhypothese $\mu=33$ durchzuführen!
a) Dazu ist eine Zufallsstichprobe vom **Umfang 40** zu ziehen und bezüglich der Alternativhypothese $H_1(\mu<33)$ ein Signifikanz-Test mit einem Testniveau von $\alpha = 0.05$ durchzuführen! Erklären Sie, wie sich der Testwert ermitteln lässt.
b) Zu welchem Ergebnis würde der Inferenzschluss führen, wenn anstelle des einseitigen Tests ein zweiseitiger Test zur Prüfung der Hypothese $\mu=33$ zu erfolgen hätte?
- How to z-test:
- $$ \frac {\bar{x} - \mu} {\frac{\sigma}{\sqrt{n}}} $$
## Aufgabe 2a: testing the z
$$ \frac {\bar{x} - \mu} {\frac{\sigma}{\sqrt{n}}} $$
also:
```{r a02_sample_mean, echo = T}
ngo40 <- sample_n(ngo, 40)
mean(ngo40$stunzahl)
```
- $$ \frac {`r mean(ngo40$stunzahl)` - 33} {\frac {1.5}{\sqrt{40}}} = `r (mean(ngo40$stunzahl) - 33) / (1.5 / sqrt(40))`$$
## Aufgabe 2a: Inferenzschluss in bunt
$$ \frac {`r mean(ngo40$stunzahl)` - 33} {\frac {1.5}{\sqrt{40}}} = `r (mean(ngo40$stunzahl) - 33) / (1.5 / sqrt(40))`$$
bei $\alpha = 5\%$, einseitig:
```{r a02a_bunt}
ztest <- (mean(ngo40$stunzahl) - 33) / (1.5 / sqrt(40))
ggplot(data = NULL, aes(x = -3.3:3.3)) +
stat_function(fun = dnorm, geom = "density", color = "black") +
geom_vline(aes(xintercept = qnorm(.05)), color = "red") +
geom_vline(aes(xintercept = ztest), color = "blue") +
annotate("text", x = qnorm(.05), y = 0.35, color = "dark red", size = 5,
label = paste("z[krit]", "==", round(qnorm(.05), 2)), parse = T) +
annotate("text", x = ztest - 0.5, y = 0.25, color = "dark blue", size = 7,
label = paste("z[test]", "==", round(ztest, 2)), parse = T) +
labs(x = NULL, y = NULL) +
theme_readthedown(base_family = "Palatino")
```
## Aufgabe 2b: Inferenzschluss in bunt
$$ \frac {`r mean(ngo40$stunzahl)` - 33} {\frac {1.5}{\sqrt{40}}} = `r (mean(ngo40$stunzahl) - 33) / (1.5 / sqrt(40))`$$
bei $\alpha = 5\%$, zweiseitig:
```{r a02b_bunt}
ggplot(data = NULL, aes(x = -3.3:3.3)) +
stat_function(fun = dnorm, geom = "density", color = "black") +
geom_vline(aes(xintercept = qnorm(.025)), color = "red") +
geom_vline(aes(xintercept = qnorm(.975)), color = "red") +
geom_vline(aes(xintercept = ztest), color = "blue") +
annotate("text", x = qnorm(.025) + 0.7, y = 0.35, color = "dark red", size = 5,
label = paste("z[krit]", "==", round(qnorm(.025), 2)), parse = T) +
annotate("text", x = qnorm(.975) - 0.6, y = 0.35, color = "dark red", size = 5,
label = paste("z[krit]", "==", round(qnorm(.975), 2)), parse = T) +
annotate("text", x = ztest - 0.5, y = 0.2, color = "dark blue", size = 7,
label = paste("z[test]", "==", round(ztest, 2)), parse = T) +
labs(x = NULL, y = NULL) +
theme_readthedown(base_family = "Palatino")
```
## Aufgabe 3: A priori: t-Test (einseitig)
Durch einen **einseitigen t-Test** soll eine innerhalb einer Nullhypothese postulierte Mitte auf der Basis der Risiken $\alpha=0.05$ und $\beta=0.15$ – bei der Wahl einer Effektgröße von **-0.6** – teststatistisch abgesichert werden! Wie groß ist der **optimale Stichprobenumfang** und welche Bedeutung besitzt er? Wie verändert sich der optimale Stichprobenumfang, wenn Sie $\beta$ erhöhen oder wenn die Effektgröße verringert wird? Warum ist das so?
```{r a03_intro}
ggplot(data = NULL, aes(x = -4:7)) +
stat_function(fun = dnorm, args = list(mean = 0)) +
stat_function(fun = dnorm, args = list(mean = 3)) +
geom_area(aes(x = seq(1.64, 7, .01), y = dnorm(seq(1.64, 7, .01), 3)), fill = "red", alpha = .4) +
geom_area(aes(x = seq(1.64, 7, .01), y = dnorm(seq(1.64, 7, .01))), fill = "blue", alpha = .4) +
geom_area(aes(x = seq(-4, 1.64, .01), y = dnorm(seq(-4, 1.64, .01))), fill = "green", alpha = .4) +
scale_x_continuous(breaks = seq(-5, 10, 1)) +
annotate("text", x = 0, y = .2, label = "H[0]", parse = TRUE, size = 6, family = "Palatino") +
annotate("text", x = 3, y = .2, label = "H[1]", parse = TRUE, size = 6, family = "Palatino") +
annotate("text", x = 0, y = .1, label = "1-alpha", parse = TRUE, size = 4, family = "Palatino") +
annotate("text", x = 3, y = .1, label = "1-beta", parse = TRUE, size = 6, family = "Palatino") +
annotate("text", x = 2, y = .025, label = "alpha", parse = TRUE, size = 4, family = "Palatino") +
labs(x = "x", y = expression(P(x)), title = expression("N(0,1) & N(3,1)")) +
theme_readthedown(base_family = "Palatino") +
theme(panel.grid.major = element_line(size = 0.1),
panel.grid.minor = element_line(linetype = "blank"))
```
## Aufgabe 3: A priori (Code)
```{r a03_solution, echo = T}
pwr.t.test(d = -0.6, sig.level = 0.05, power = 1 - 0.15, type = "one.sample")
pwr.t.test(d = -0.6, sig.level = 0.05, power = 1 - 0.25, type = "one.sample")$n
pwr.t.test(d = -0.3, sig.level = 0.05, power = 1 - 0.15, type = "one.sample")$n
```
## Aufgabe 4: Konfidenzintervalle
Für die aus einer Zufallsauswahl vom Umfang **36** resultierenden Werte eines **normalverteilten Merkmals** erhält man den Mittelwert **33** und den Standardfehler **1.2**. Gib für $\mu$ das zugehörige **95%-Konfidenzintervall** an und erklären Sie die Bedeutung dieses Konfidenzintervalls! Diskutieren Sie die Vor- und Nachteile, die sich beim Einsatz eines Signifikanz-Tests bzw. eines Konfidenzintervalls ergeben!
- $w_{krit} \approx `r qnorm(0.975)`$
- $CI_{lower} = 33 - 1.2 \cdot `r round(qnorm(0.975), 3)` \approx `r 33 - 1.2 * qnorm(0.975)`$
- $CI_{upper} = 33 + 1.2 \cdot `r round(qnorm(0.975), 3)` \approx `r 33 + 1.2 * qnorm(0.975)`$
```{r a04_plot, fig.height= 3, fig.width=7}
ki <- c(33 - 1.2 * qnorm(0.975), 33 + 1.2 * qnorm(0.975))
df <- data_frame(x = seq(29, 37, .01), y = dnorm(x, mean = 33, sd = 1.2))
ggplot(data = df, aes(x = x, y = y)) +
geom_line() +
geom_vline(xintercept = ki[[1]], linetype = "dotdash") +
geom_vline(xintercept = ki[[2]], linetype = "dotdash") +
geom_area(data = filter(df, x < ki[2], x > ki[1]), aes(x, y), fill = "green", alpha = .5) +
geom_area(data = filter(df, x > ki[2]), aes(x, y), fill = "red", alpha = .5) +
geom_area(data = filter(df, x < ki[1]), aes(x, y), fill = "red", alpha = .5) +
scale_x_continuous(breaks = seq(0, 100, 1), minor_breaks = seq(0, 100, .5)) +
annotate("label", x = ki[1]-0.4, y = 0.02, label = "frac(alpha,2)", parse = T) +
annotate("label", x = ki[2]+0.4, y = 0.02, label = "frac(alpha,2)", parse = T) +
annotate("label", x = 33, y = 0.1, label = "1 - alpha == 0.95", parse = T) +
labs(title = expression(N(33, 1.2)), x = "x", y = expression(P(x))) +
theme_readthedown()
```
## Aufgabe 5: t-Test / U-Test (?) {.build}
```{r a05_datainit}
student <- labels_to_factor(read_spss("http://qm.jemu.name/data/Student_Daten.sav"))
```
Berechnen Sie einen geeigneten Test für die Fragestellung, ob die Verteilungen des Alkoholkkonsums bei ernährungsbewussten StudentInnen (Vegetarier) und der fleischkonsumierenden StudentInnen gleich sind. Prüfen Sie einseitig die Annahme, dass die Tatsache Vegetarier zu sein, sich positiv auf einen geringeren Alkoholkonsum auswirkt. Wie kommt der resultierende Testwert zustande?
> $H_0:$ die Ernährungsart hat keinen Einfluss auf den Alkoholkonsum
$H_1:$ Vegetarier*innen konsumieren weniger Alkohol als Omnivore
Vorraussetzungen:
Test | Sig.-Niveau
--------------|-------------
Shapiro-Wilk | < 0.001
Levene | `< 0.05
<br />
$\rightarrow$ **Mann-Whitney-U-Test!**
## Aufgabe 5: t-Test / U-Test (?)
Berechnen Sie einen geeigneten Test für die Fragestellung, ob die Verteilungen des Alkoholkkonsums bei ernährungsbewussten StudentInnen (Vegetarier) und der fleischkonsumierenden StudentInnen gleich sind. Prüfen Sie einseitig die Annahme, dass die Tatsache Vegetarier zu sein, sich positiv auf einen geringeren Alkoholkonsum auswirkt. Wie kommt der resultierende Testwert zustande?
> $H_0:$ die Ernährungsart hat keinen Einfluss auf den Alkoholkonsum
$H_1:$ Vegetarier*innen konsumieren weniger Alkohol als Omnivore
```{r a05_wilcox.test}
student %<>% mutate(Trinkverhalten = as.numeric(Trinkverhalten))
tadaa_wilcoxon(student, Trinkverhalten, Ernährungstyp, print = "markdown")
```
## Aufgabe 6: ANOVA + posthoc
Die Hypothese, dass es für die Schülerinnen keine **jahrgangsstufenspezifischen** Unterschiede im Hinblick auf die Anzahl von Wochentagen gibt, an denen für das Fach **Deutsch** gelernt wird, ist mit den für die **NGO-SchülerInnen** erhobenen Daten teststatistisch zu prüfen!
Falls ein signifikantes Testergebnis vorliegt, ist die **empirische Effektgröße** zu ermitteln und zu überprüfen, zwischen welchen Jahrgängen Unterschiede bestehen könnten!
- Was ist zu tun?
- ANOVA: `aov()`
- Effektgröße $\eta^2$: `lsr::etaSquared()`
- Untergruppen-Test (Bonferroni, Scheffé): `asbio::pairw.anova()`
## Aufgabe 6: ANOVA + posthoc (Code)
```{r a06_1, echo = T}
probe6 <- ngo %>% filter(geschl == "Weiblich")
anova6 <- aov(deutsch ~ jahrgang, data = probe6)
anova6 %>% tidy() %>% kable(digits = 8)
lsr::etaSquared(anova6, type = 3)
```
## Aufgabe 6: ANOVA + posthoc (Code)
```{r a06_2, echo = T}
asbio::pairw.anova(probe6$deutsch, probe6$jahrgang, method = "scheffe")$summary %>% kable(digits = 8)
```
## Aufgabe 7: ANOVA {.incremental}
In 3 Kursen (A, B, C) der 11. Jahrgangsstufe werden Schüler und Schülerinnen nach unterschiedlichen Methoden unterrichtet. Aus jedem der 3 Kurse werden jeweils 9 SchülerInnen durch eine Zufallsauswahl bestimmt. Bei einem abschließenden Leistungstest werden die folgenden Ergebnisse erzielt:
SchülerInnen des Kurses A: `10, 19, 21, 24, 22, 16, 11, 21, 19`
SchülerInnen des Kurses B: `16, 19, 18, 16, 11, 19, 19, 16, 21`
SchülerInnen des Kurses C: `22, 17, 12, 20, 16, 21, 22, 11, 21`
Wenden Sie einen geeigneten Test an.
```{r a07_df}
kurse <- data.frame(A = c(10, 19, 21, 24, 22, 16, 11, 21, 19),
B = c(16, 19, 18, 16, 11, 19, 19, 16, 21),
C = c(22, 17, 12, 20, 16, 21, 22, 11, 21)) %>%
gather(Kurs, Ergebnis, A, B, C)
```
<div class="columns-2">
![](img/jehova_l41lGAcThnMc29u2Q.gif)
<font size = "18">
$$ \rightarrow \text{ANOVA!} $$
</font></div>
## Aufgabe 7: ANOVA
```{r a07_anova}
tadaa_aov(Ergebnis ~ Kurs, data = kurse, print = "markdown")
```
## Aufgabe 8: Optimales N & t-Test (abhängig)
Auf dem Testniveau $\alpha=0.05$ ist zu prüfen, ob bei den Schülerinnen Mittelwertunterschiede bei den Merkmalen **Mathe** und **Deutsch** festzustellen sind! Dazu ist zu unterstellen, dass beide Merkmale innerhalb der Grundgesamtheit der **125 NGO-Schülerinnen** normalverteilt sind! Es ist ein **zweiseitiger** Test durchzuführen und der **Stichprobenumfang** so zu wählen, dass ein **mittlerer Effekt** mit einer Wahrscheinlichkeit von mindestens **0.85** aufgedeckt werden kann. Wie viele Stichprobenelemente wären für die Durchführung eines **einseitigen Tests** angemessen gewesen?
## Aufgabe 8: Optimales N & t-Test (abhängig)
Auf dem Testniveau $\alpha=0.05$ ist zu prüfen, ob bei den Schülerinnen Mittelwertunterschiede bei den Merkmalen **Mathe** und **Deutsch** festzustellen sind! Dazu ist zu unterstellen, dass beide Merkmale innerhalb der Grundgesamtheit der **125 NGO-Schülerinnen** normalverteilt sind! Es ist ein **zweiseitiger** Test durchzuführen und der **Stichprobenumfang** so zu wählen, dass ein **mittlerer Effekt** mit einer Wahrscheinlichkeit von mindestens **0.85** aufgedeckt werden kann. Wie viele Stichprobenelemente wären für die Durchführung eines **einseitigen Tests** angemessen gewesen?
```{r a08_pwr_paired_twosided, echo = T}
pwr.t.test(d = 0.5, sig.level = 0.05, power = 0.85,
type = "paired", alternative = "two.sided")
```
## Aufgabe 8: Optimales N & t-Test (abhängig)
Wie viele Stichprobenelemente wären für die Durchführung eines **einseitigen Tests** angemessen gewesen?
```{r a08_pwr_paired_onesided, echo = T}
pwr.t.test(d = 0.5, sig.level = 0.05, power = 0.85,
type = "paired", alternative = "greater")
```
## Aufgabe 9: Optimales N & t-Test (unabhängig)
Auf dem Testniveau von $\alpha=0.01$ ist zu prüfen, ob **geschlechtsspezifische** Mittelwertunterschiede beim Merkmal **Deutsch** festzustellen sind! Dazu ist zu unterstellen, dass das Merkmal **Deutsch** innerhalb der beiden Grundgesamtheiten der jeweiligen **125 NGO-Schüler und Schülerinnen** normalverteilt ist! Zur Prüfung der **zweiseitigen** Fragestellung ist der **Umfang** der beiden Zufallsstichproben so zu wählen, dass ein durch die **Effektgröße 0.9** beschriebener Effekt mit einer Wahrscheinlichkeit von mindestens **0.85** aufgedeckt werden kann! Wie berechnet sich der Testwert?
```{r a09_pwr_unpaired, echo = T}
pwr.t.test(d = 0.9, sig.level = 0.01, power = 0.85,
type = "two.sample", alternative = "two.sided")
```
## Aufgabe 10: ANOVA
a) Es ist zu prüfen, ob die These **Das Geschlecht und die Jahrgangsstufe üben einen Interaktionseffekt auf *Deutsch* aus, und das Geschlecht wirkt *nicht* als Haupteffekt.** akzeptabel ist!
b) Welche Voraussetzungen sind zu erfüllen, damit eine 2-faktorielle Varianzanalyse durchgeführt werden kann?
c) Welche Feststellungen lassen sich – auf der Basis eines Testniveaus von $\alpha=0.05$ - über potentiell wirksame Effekte treffen?
d) Wie viele SchülerInnen wären für jede der 6 Zellen des Versuchsplans erforderlich gewesen, um – auf der Basis des Testniveaus $\alpha=0.05$ - einen tatsächlich vorliegenden, nach Cohen als **stark** taxierten Interaktionseffekt mit einer Mindest-Teststärke von **0.8** „aufdecken“ zu können?
## Aufgabe 10: ANOVA + Voraussetzungen (a-c)
```{r a10_anova, echo = FALSE}
aov(deutsch ~ geschl * jahrgang, data = ngo) %>%
tidy() %>%
kable()
```
<br />
Vorraussetzungen:
Vorraussetzung | Test | p-Wert
--------------------|---------------|----------
Normalverteilung | Shapiro-Wilk | `r shapiro.test(ngo$deutsch)$p.value`
Varianzhomogenität | Levene | `r leveneTest(deutsch ~ geschl * jahrgang, data = ngo)$Pr[1]`
## Aufgabe 10: ANOVA: A priori (d)
Effektgröße für die Software ist: $f = \sqrt{\frac{\eta^2}{1 - \eta^2}}$
Gilt für G*Power sowie die R-funktionen aus dem `pwr` package!
```{r a10_anova_apriori, echo = TRUE}
pwr.anova.test(k = 6, f = sqrt(0.14 / (1 - 0.14)), sig.level = 0.05, power = 0.8)
```
## Aufgabe 11: Kruskal-Wallis & Wilcoxon-Test (1)
Wählen Sie selbst für Sie interessante Variablen einmal für eine Varianzanalyse, einmal für den Kruskal-Wallis-Test & einmal für den Wilcoxon-Test aus dem Psychologie-Datensatz aus und interpretieren Sie die Daten.
**Anzahl sexueller Partner\*innen und Parteipräferenz**
Anova:
```{r a11_psystat_aov}
psych <- labels_to_factor(read_spss("http://qm.jemu.name/data/qm_2_survey_final.sav"))
tadaa_aov(sex_partner ~ partei, psych, print = "markdown")
```
Kruskal-Wallis:
```{r a11_kw}
tadaa_kruskal(sex_partner ~ partei, psych, print = "markdown")
```
## Aufgabe 11: Kruskal-Wallis & Wilcoxon-Test (2)
***"Wie viele Stunden Schlaf brauchst du im Schnitt, um dich ausgeschlafen zu fühlen?"***
und
***"Hattest du schon mal einen One Night Stand?*"**
Wilcoxon:
```{r a11_wilcoxon}
tadaa_wilcoxon(psych, schlaf, sex_one_night_stand, print = "markdown")
```
# Aufgabenblock 2 | Berechnungen per Hand ಠ_ಠ
![](img/despair_oEsUZ3jmzHGFi.gif)
## Aufgabe 13: ANOVA (1)
Berechnen Sie auf Basis folgender Daten die **Binnenvarianz**, die **Treatmentvarianz**, den **F-Wert** und den **kritischen Wert**:
<img src='http://dump.jemu.name/VkCCo.png' width = 90%>
Zu welchem Inferenzschluss gelangen Sie?
```{r a13, echo=T}
a13 <- data.frame(hormon_1 = c(9, 12, 8), hormon_2 = c(4, 2, 5), kontrolle = c(3, 6, 3))
a13 %<>% gather(Gruppe, Wert)
a13 %>% group_by(Gruppe) %>%
summarize(mean = mean(Wert),
variation = var(Wert) * (length(Wert) - 1)) %>%
select(variation) %>% sum %>% divide_by(6) # 6 = n - k = 9 - 3
```
## Aufgabe 13: ANOVA (2)
<img src='http://dump.jemu.name/VkCCo.png' width = 90%>
<div class="columns-2">
Binnenvarianz $MS_{within}$:
$$\sum_{j=1}^k \sum_{i=1}^n \frac{(x_{i, j} - \bar{x_j})^2}{n - k}$$
Treatmentvarianz $MS_{between}$:
$$\sum_{j=1}^k n_j \frac{(x_{j} - \bar{x})^2}{k -1}$$
F-Wert:
$$F = \frac{MS_{between}}{MS_{within}}$$
$F_{krit}$:
$$\text{df}_F = (k-1, n-k)$$
</div>
## Aufgabe 13: ANOVA (3)
```{r a13_2, echo=T}
a13 %>% group_by(Gruppe) %>%
summarize(mean = mean(Wert)) %>%
mutate(meandiffsquared = 3 * (mean(a13$Wert) - mean)^2) %>%
select(meandiffsquared) %>% sum %>% divide_by(2) # 2 = k - 1
```
- $$MS_{between} = \frac{SS_{between}}{k-1} = 34.11$$
- $$MS_{within} = \frac{SS_{within}}{n - k} = 3.22$$
- $$F_{(k-1, n-k)} = \frac{MS_{between}}{MS_{within}} = \frac{34.11}{3.22} \approx 10.586$$
- $$F {(2, 6)}_{krit} = 5.143$$
## Aufgabe 14
Sie haben folgende Testwerte von 6 frühgeborenen Kindern bezüglich ihrer motorischen Fähigkeiten vorliegen: `7, 8, 11, 9, 8, 10`. Welches Intervall enthält mit einer **Mutmaßlichkeit von 99%** den wahren Mittelwert der motorischen Fähigkeiten? Erklären Sie: Wie ist es möglich anhand des Konfidenzintervalls eine Aussage über die Mutmaßlichkeeit einer Mitte zu treffen?
- $$CI_{\text{lower}} = \bar{x} - S_{\bar{x}} \cdot z_{1 - \frac{\alpha}{2}} \quad CI_{\text{upper}} = \bar{x} + S_{\bar{x}} \cdot z_{1 - \frac{\alpha}{2}}$$
- $$\bar{x} \approx 8.83 \quad S_{\bar{x}} \approx 0.6 \quad z_{1 - \frac{\alpha}{2}} \approx 2.576$$
```{r a14_plot, fig.height= 3, fig.width=7}
values <- c(7, 8, 11, 9, 8, 10)
alpha <- 0.01/2
m <- mean(values)
sem <- sd(values)/sqrt(length(values))
ki <- c(m - sem * qnorm(1-alpha), m + sem * qnorm(1-alpha))
df <- data_frame(x = seq(m-3, m+3, .01), y = dnorm(x, mean = m, sd = sem))
ggplot(data = df, aes(x = x, y = y)) +
geom_line() +
geom_vline(xintercept = ki[[1]], linetype = "dotdash") +
geom_vline(xintercept = ki[[2]], linetype = "dotdash") +
geom_area(data = filter(df, x < ki[2], x > ki[1]), aes(x, y), fill = "green", alpha = .5) +
geom_area(data = filter(df, x > ki[2]), aes(x, y), fill = "red", alpha = .5) +
geom_area(data = filter(df, x < ki[1]), aes(x, y), fill = "red", alpha = .5) +
scale_x_continuous(breaks = seq(0, 100, 1), minor_breaks = seq(0, 100, .5)) +
annotate("label", x = ki[1]-0.4, y = 0.02, label = "frac(alpha,2)", parse = T) +
annotate("label", x = ki[2]+0.4, y = 0.02, label = "frac(alpha,2)", parse = T) +
annotate("label", x = m, y = 0.1, label = "1 - alpha == 0.99", parse = T) +
labs(title = expression(N(8.83, 0.6)), x = "x", y = expression(P(x))) +
theme_readthedown()
```
## Aufgabe 15
Nutzen Sie die Standardnormalverteilungstabelle in Studip. Wiederholen Sie die Kenntnisse aus der Deskriptiven Statistik, indem Sie die Wahrscheinlichkeiten von Werten in folgenden Bereichen berechnen:
Wie wahrscheinlich ist es, dass Werte im Bereich
- 2 bis 2.5
- 0.75 bis 1.3
- $-\infty$ bis -0.2 liegen?
### Lösungen:
- $P(2, 2.5) = `r round(pnorm(2.5) - pnorm(2), 4)`$
- $P(0.75, 1.3) = `r round(pnorm(1.3) - pnorm(0.75), 4)`$
- $P(-\infty, -0.2) = `r round(pnorm(-0.2), 4)`$
## Aufgabe 16
10 Frauen in der Alterskategorie 40+ wurden in einer Studie über ihre sportlichen Aktivitäten befragt. Jede dieser Frauen war in den letzten Monaten als Mitglied im Fitnessstudio registriert. Berechnen Sie auf Basis der nachfolgenden Daten den Standardfehler und die Standardabweichung. Vergleichen Sie die Werte.
<img src='http://dump.jemu.name/wlc4l.png' width=50%>
## Aufgabe 16: Rechnung
- $x = \{1,7,1,2,1,3,2,1,1,1\}$
- $n = 10$
- $\bar{x} = `r mean(c(1,7,1,2,1,3,2,1,1,1))`$
- $S_x = \sqrt{\frac{1}{10 - 1} (2-1)^2 + (2-7)^2 + \ldots + (2-1)^2 + (2-1)^2} = \sqrt{\frac{32}{9}} \approx 1.886$
- $S_{\bar{x}} = \frac{S_x}{\sqrt{n}} = \frac{1.886}{\sqrt{10}} \approx 0.5963$
- $$S_{\bar{x}} \leq S_x$$