Diese Musterlösung wurde erstellt von Peter Hähner (Ruhr-Universität Bochum).

(c) Luhmann: R für Einsteiger, 5. Aufl., Beltz, 2020

Vorbereitungen

Setzen Sie ein Arbeitsverzeichnis oder legen Sie ein entsprechendes R-Projekt an (Kap. 23).

Laden Sie dann die Datei pruefung.RData.

load("pruefung.RData")

Laden Sie die benötigten Pakete (ggf. müssen Sie diese vorab noch installieren).

library(psych)
library(afex)
library(emmeans)

Aufgabe 1

Führen Sie eine messwiederholte Varianzanalyse mit der unabhängigen Variablen mzp und der abhängigen Variablen ru durch. Berechnen Sie auch die deskriptiven Statistiken und stellen Sie die Ergebnisse grafisch dar. Führen Sie geeignete Post-hoc-Tests durch.

# Format des Datensatz prüfen
head(pruefung)
## # A tibble: 6 x 8
##      nr sex      kind  alter gruppe   mzp      gs    ru
##   <dbl> <fct>    <fct> <dbl> <fct>    <chr> <dbl> <dbl>
## 1     1 weiblich nein     27 Gruppe 1 1      3.25  1.25
## 2     1 weiblich nein     27 Gruppe 1 2      3.25  2.5 
## 3     1 weiblich nein     27 Gruppe 1 3      3.25  2.5 
## 4     2 männlich ja       28 Gruppe 1 1      4.5   3.5 
## 5     2 männlich ja       28 Gruppe 1 2      4.5   4   
## 6     2 männlich ja       28 Gruppe 1 3      4.5   4.5
# Deskriptive Statistiken
describeBy(pruefung$ru, pruefung$mzp, mat = TRUE)
##     item group1 vars  n     mean        sd median  trimmed      mad min max
## X11    1      1    1 96 2.554688 1.0407507   2.50 2.519231 1.297275   1   5
## X12    2      2    1 98 3.153061 0.9233739   3.25 3.175000 1.111950   1   5
## X13    3      3    1 95 4.292105 0.8232433   4.50 4.425325 0.741300   1   5
##     range       skew   kurtosis         se
## X11     4  0.2167933 -0.8909207 0.10622117
## X12     4 -0.2172961 -0.5068591 0.09327485
## X13     4 -1.4242662  2.0188297 0.08446298
# Messwiederholte Varianzanalyse
anova.1 <- aov_car(ru ~ Error(nr/mzp), data = pruefung)
## Warning: Missing values for following ID(s):
## 11, 14, 22, 43, 56, 59, 60, 61, 70, 80, 86, 87, 88, 93, 98, 99, 100, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120
## Removing those cases from the analysis.
anova.1 
## Anova Table (Type 3 tests)
## 
## Response: ru
##   Effect           df  MSE          F  ges p.value
## 1    mzp 1.96, 180.62 0.62 115.93 *** .371   <.001
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
## 
## Sphericity correction method: GG

Die ruhige vs. unruhige Stimmung verändert sich signifikant über die drei Messzeitpunkte (F(1.96, 180.62) = 115.93, p < .001, η2 = .371).

# Post-Hoc-Tests
ph.1 <- emmeans(anova.1, specs = "mzp") 
pairs(ph.1) 
##  contrast estimate    SE  df t.ratio p.value
##  X1 - X2    -0.605 0.114 184  -5.294 <.0001 
##  X1 - X3    -1.715 0.114 184 -15.011 <.0001 
##  X2 - X3    -1.110 0.114 184  -9.717 <.0001 
## 
## P value adjustment: tukey method for comparing a family of 3 estimates

Der Mittelwertsunterschied zwischen allen drei Messzeitpunkten ist signifikant (alle p < .001).

# Grafische Darstellung
afex_plot(anova.1, x = "mzp", error = "within",
             factor_levels = list(
                 mzp = c("Vor der Klausur",
                         "Während der Klausur",
                         "Nach der Klausur")))
## Renaming/reordering factor levels of 'mzp':
##   X1 -> Vor der Klausur
##   X2 -> Während der Klausur
##   X3 -> Nach der Klausur

Aufgabe 2

Überprüfen Sie, ob sich Frauen und Männer (sex) darin unterscheiden, wie sich ihre ruhige vs. unruhige Stimmung (ru) über die Zeit verändert. Berechnen Sie dazu eine gemischte Varianzanalyse mit Typ-II-Quadratsummen. Berechnen Sie auch die deskriptiven Statistiken und stellen Sie die Ergebnisse grafisch dar. Führen Sie geeignete Post-Hoc-Tests durch.

# Deskriptive Statistiken
describeBy(pruefung$ru, list(pruefung$mzp, pruefung$sex), mat = TRUE)
##     item group1   group2 vars  n     mean        sd median  trimmed      mad
## X11    1      1 weiblich    1 76 2.430921 0.9870821  2.250 2.399194 1.297275
## X12    2      2 weiblich    1 78 3.131410 0.9255784  3.250 3.148438 1.111950
## X13    3      3 weiblich    1 75 4.280000 0.8331802  4.500 4.409836 0.741300
## X14    4      1 männlich    1 18 3.000000 1.1631600  3.250 3.000000 1.297275
## X15    5      2 männlich    1 18 3.166667 0.9587062  3.250 3.187500 0.926625
## X16    6      3 männlich    1 18 4.319444 0.8305099  4.625 4.406250 0.555975
##      min max range        skew   kurtosis         se
## X11 1.00   5  4.00  0.22997504 -0.8499183 0.11322609
## X12 1.00   5  4.00 -0.16589984 -0.6421742 0.10480112
## X13 1.00   5  4.00 -1.46925749  2.2628094 0.09620736
## X14 1.00   5  4.00 -0.04964456 -1.3586874 0.27415944
## X15 1.00   5  4.00 -0.23183250 -0.2966726 0.22596923
## X16 2.25   5  2.75 -1.08457925  0.1024122 0.19575307
# Gemischte Varianzanalyse mit Typ-II-Quadratsummen
anova.2 <- aov_car(ru ~ sex + Error(nr/mzp),
                   data = pruefung, type = 2)
## Warning: Missing values for following ID(s):
## 11, 14, 22, 43, 56, 59, 60, 61, 70, 74, 80, 85, 86, 87, 88, 93, 98, 99, 100, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120
## Removing those cases from the analysis.
## Contrasts set to contr.sum for the following variables: sex
anova.2 
## Anova Table (Type 2 tests)
## 
## Response: ru
##    Effect           df  MSE          F  ges p.value
## 1     sex        1, 89 1.39       1.26 .008    .265
## 2     mzp 1.97, 175.50 0.61 115.87 *** .377   <.001
## 3 sex:mzp 1.97, 175.50 0.61       2.22 .011    .112
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
## 
## Sphericity correction method: GG

Es liegt ein signifikanter Haupteffekt des Messzeitpunkts vor (F(1.97, 175.50) = 115.87, p < .001, η2 = .377), aber kein signifikanter Haupteffekt des Geschlechts (F(1, 89) = 1.26, p = .265, η2 = .008). Auch die Interaktion wird nicht signifikant (F(1.97, 175.50) = 2.22, p = .112, η2 = .112).

# Post-Hoc-Test
ph.2 <- emmeans(anova.2, ~ mzp | sex) 
pairs(ph.2)
## sex = weiblich:
##  contrast estimate    SE  df t.ratio p.value
##  X1 - X2    -0.712 0.128 178  -5.547 <.0001 
##  X1 - X3    -1.825 0.128 178 -14.214 <.0001 
##  X2 - X3    -1.113 0.128 178  -8.667 <.0001 
## 
## sex = männlich:
##  contrast estimate    SE  df t.ratio p.value
##  X1 - X2    -0.167 0.259 178  -0.644 0.7957 
##  X1 - X3    -1.319 0.259 178  -5.102 <.0001 
##  X2 - X3    -1.153 0.259 178  -4.458 <.0001 
## 
## P value adjustment: tukey method for comparing a family of 3 estimates

Die Post-Hoc-Tests zeigen, dass sich die Stimmung bei Frauen zu allen Messzeitpunkt signifikant voneinander unterscheidet (alle p < .001). Bei Männern verändert sich die Stimmung vom ersten zum zweiten Messzeitpunkt hingegen nicht signifikant (t(178) = -0.64, p = .796).

# Grafische Darstellung
afex_plot(anova.2, x = "mzp", trace = "sex",
          error = "between")
## Warning: Panel(s) show a mixed within-between-design.
## Error bars do not allow comparisons across all means.
## Suppress error bars with: error = "none"