# packages
library(psych) # für deskriptive Statistik ggf. vorher installieren mit install.packages("psych")
library(afex) # für aov_ez() ggf. vorher installieren mit install.packages("afex")
## Lade nötiges Paket: lme4
## Lade nötiges Paket: Matrix
## ************
## Welcome to afex. For support visit: http://afex.singmann.science/
## - Functions for ANOVAs: aov_car(), aov_ez(), and aov_4()
## - Methods for calculating p-values with mixed(): 'S', 'KR', 'LRT', and 'PB'
## - 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests
## - Get and set global package options with: afex_options()
## - Set sum-to-zero contrasts globally: set_sum_contrasts()
## - For example analyses see: browseVignettes("afex")
## ************
## 
## Attache Paket: 'afex'
## Das folgende Objekt ist maskiert 'package:lme4':
## 
##     lmer
## Lade nötiges Paket: lme4
## Lade nötiges Paket: Matrix
## ************
## Welcome to afex. For support visit: http://afex.singmann.science/
## - Functions for ANOVAs: aov_car(), aov_ez(), and aov_4()
## - Methods for calculating p-values with mixed(): 'S', 'KR', 'LRT', and 'PB'
## - 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests
## - Get and set global package options with: afex_options()
## - Set sum-to-zero contrasts globally: set_sum_contrasts()
## - For example analyses see: browseVignettes("afex")
## ************
## 
## Attache Paket: 'afex'
## Das folgende Objekt ist maskiert 'package:lme4':
## 
##     lmer
library(effectsize) # für effektstärken, ggf. installieren mit install.packages("effectsize")
## 
## Attache Paket: 'effectsize'
## Das folgende Objekt ist maskiert 'package:psych':
## 
##     phi
## 
## Attache Paket: 'effectsize'
## Das folgende Objekt ist maskiert 'package:psych':
## 
##     phi
library(emmeans) # für Posttests, ggf. vorher installieren mit install.packages("emmeans")
## Welcome to emmeans.
## Caution: You lose important information if you filter this package's results.
## See '? untidy'
# Daten einlesen:
# setwd("~/Schreibtisch/Methodenberatung")
dat <- read.table("dat_aov.csv", header = TRUE, sep = ",")
head(dat)
##   ID Faktor_A Faktor_B MZP av
## 1  1        1        1   1  2
## 2  2        1        1   1  4
## 3  3        1        1   1  3
## 4  4        1        2   1  3
## 5  5        1        2   1  4
## 6  6        1        2   1  4
##   ID Faktor_A Faktor_B MZP av
## 1  1        1        1   1  2
## 2  2        1        1   1  4
## 3  3        1        1   1  3
## 4  4        1        2   1  3
## 5  5        1        2   1  4
## 6  6        1        2   1  4
# uvs als Faktoren
# Faktor 1, between, selbstselektiert zugewiesen (beobachtet)
dat$Gruppe <- factor(dat$Faktor_A,
                     levels = c(1, 2, 3), # Codes in den Daten
                     labels = c("Gruppe A", "Gruppe B", "Gruppe C")) # Benennung (Reihenfolge!)
# Faktor 2, between, randomisiert zugewiesen (experimentell manipuliert)
dat$Methode <- factor(dat$Faktor_B,
                      levels = c(1, 2), # Codes in den Daten
                      labels = c("Methode 1", "Methode 2")) # Benennung (Reihenfolge!)
# Faktor 3, within, Messzeitpunkt
dat$Messzeitpunkt <- factor(dat$MZP,
                            levels = c(1, 2, 3), # Codes in den Daten
                            labels = c("Prä", "Post", "Post2")) # Benennung (Reihenfolge!)
# av als numeric
dat$av <- as.numeric(dat$av)

# Hat es funktioniert? 
head(dat) # oder View(dat) und dann durch die Daten scrollen!
##   ID Faktor_A Faktor_B MZP av   Gruppe   Methode Messzeitpunkt
## 1  1        1        1   1  2 Gruppe A Methode 1           Prä
## 2  2        1        1   1  4 Gruppe A Methode 1           Prä
## 3  3        1        1   1  3 Gruppe A Methode 1           Prä
## 4  4        1        2   1  3 Gruppe A Methode 2           Prä
## 5  5        1        2   1  4 Gruppe A Methode 2           Prä
## 6  6        1        2   1  4 Gruppe A Methode 2           Prä
##   ID Faktor_A Faktor_B MZP av   Gruppe   Methode Messzeitpunkt
## 1  1        1        1   1  2 Gruppe A Methode 1           Prä
## 2  2        1        1   1  4 Gruppe A Methode 1           Prä
## 3  3        1        1   1  3 Gruppe A Methode 1           Prä
## 4  4        1        2   1  3 Gruppe A Methode 2           Prä
## 5  5        1        2   1  4 Gruppe A Methode 2           Prä
## 6  6        1        2   1  4 Gruppe A Methode 2           Prä
## ++ Deskriptive Statistiken 
# (Hinweis: Daten müssen generell im long format vorliegen, auch bei
# Messwiederholung!)

# Mittelwerte und SD der aV pro Faktorstufenkombination
describeBy(av ~ Gruppe * Methode * Messzeitpunkt, 
           data = dat)
## 
##  Descriptive statistics by group 
## Gruppe: Gruppe A
## Methode: Methode 1
## Messzeitpunkt: Prä
##    vars n mean sd median trimmed  mad min max range skew kurtosis   se
## av    1 3    3  1      3       3 1.48   2   4     2    0    -2.33 0.58
## ------------------------------------------------------------ 
## Gruppe: Gruppe B
## Methode: Methode 1
## Messzeitpunkt: Prä
##    vars n  mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 10.67 2.52     11   10.67 2.97   8  13     5 -0.13    -2.33 1.45
## ------------------------------------------------------------ 
## Gruppe: Gruppe C
## Methode: Methode 1
## Messzeitpunkt: Prä
##    vars n  mean   sd median trimmed mad min max range  skew kurtosis   se
## av    1 3 19.67 2.31     21   19.67   0  17  21     4 -0.38    -2.33 1.33
## ------------------------------------------------------------ 
## Gruppe: Gruppe A
## Methode: Methode 2
## Messzeitpunkt: Prä
##    vars n mean   sd median trimmed mad min max range  skew kurtosis   se
## av    1 3 3.67 0.58      4    3.67   0   3   4     1 -0.38    -2.33 0.33
## ------------------------------------------------------------ 
## Gruppe: Gruppe B
## Methode: Methode 2
## Messzeitpunkt: Prä
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 8.67 2.52      9    8.67 2.97   6  11     5 -0.13    -2.33 1.45
## ------------------------------------------------------------ 
## Gruppe: Gruppe C
## Methode: Methode 2
## Messzeitpunkt: Prä
##    vars n mean sd median trimmed  mad min max range skew kurtosis   se
## av    1 3   18  1     18      18 1.48  17  19     2    0    -2.33 0.58
## ------------------------------------------------------------ 
## Gruppe: Gruppe A
## Methode: Methode 1
## Messzeitpunkt: Post
##    vars n mean   sd median trimmed  mad min max range skew kurtosis  se
## av    1 3 3.67 2.08      3    3.67 1.48   2   6     4 0.29    -2.33 1.2
## ------------------------------------------------------------ 
## Gruppe: Gruppe B
## Methode: Methode 1
## Messzeitpunkt: Post
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3    8 2.65      9       8 1.48   5  10     5 -0.32    -2.33 1.53
## ------------------------------------------------------------ 
## Gruppe: Gruppe C
## Methode: Methode 1
## Messzeitpunkt: Post
##    vars n mean   sd median trimmed  mad min max range skew kurtosis   se
## av    1 3   18 2.65     17      18 1.48  16  21     5 0.32    -2.33 1.53
## ------------------------------------------------------------ 
## Gruppe: Gruppe A
## Methode: Methode 2
## Messzeitpunkt: Post
##    vars n mean   sd median trimmed mad min max range  skew kurtosis   se
## av    1 3 7.67 0.58      8    7.67   0   7   8     1 -0.38    -2.33 0.33
## ------------------------------------------------------------ 
## Gruppe: Gruppe B
## Methode: Methode 2
## Messzeitpunkt: Post
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 9.67 5.86     12    9.67 2.97   3  14    11 -0.34    -2.33 3.38
## ------------------------------------------------------------ 
## Gruppe: Gruppe C
## Methode: Methode 2
## Messzeitpunkt: Post
##    vars n  mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 21.33 3.79     23   21.33 1.48  17  24     7 -0.35    -2.33 2.19
## ------------------------------------------------------------ 
## Gruppe: Gruppe A
## Methode: Methode 1
## Messzeitpunkt: Post2
##    vars n mean   sd median trimmed mad min max range skew kurtosis   se
## av    1 3 4.33 0.58      4    4.33   0   4   5     1 0.38    -2.33 0.33
## ------------------------------------------------------------ 
## Gruppe: Gruppe B
## Methode: Methode 1
## Messzeitpunkt: Post2
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 7.67 3.51      8    7.67 4.45   4  11     7 -0.09    -2.33 2.03
## ------------------------------------------------------------ 
## Gruppe: Gruppe C
## Methode: Methode 1
## Messzeitpunkt: Post2
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3   21 3.61     22      21 2.97  17  24     7 -0.26    -2.33 2.08
## ------------------------------------------------------------ 
## Gruppe: Gruppe A
## Methode: Methode 2
## Messzeitpunkt: Post2
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 7.67 1.53      8    7.67 1.48   6   9     3 -0.21    -2.33 0.88
## ------------------------------------------------------------ 
## Gruppe: Gruppe B
## Methode: Methode 2
## Messzeitpunkt: Post2
##    vars n  mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 12.67 7.57     16   12.67 2.97   4  18    14 -0.35    -2.33 4.37
## ------------------------------------------------------------ 
## Gruppe: Gruppe C
## Methode: Methode 2
## Messzeitpunkt: Post2
##    vars n  mean   sd median trimmed  mad min max range skew kurtosis   se
## av    1 3 23.33 5.13     22   23.33 4.45  19  29    10 0.24    -2.33 2.96
## 
##  Descriptive statistics by group 
## Gruppe: Gruppe A
## Methode: Methode 1
## Messzeitpunkt: Prä
##    vars n mean sd median trimmed  mad min max range skew kurtosis   se
## av    1 3    3  1      3       3 1.48   2   4     2    0    -2.33 0.58
## Gruppe: Gruppe B
## Methode: Methode 1
## Messzeitpunkt: Prä
##    vars n  mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 10.67 2.52     11   10.67 2.97   8  13     5 -0.13    -2.33 1.45
## Gruppe: Gruppe C
## Methode: Methode 1
## Messzeitpunkt: Prä
##    vars n  mean   sd median trimmed mad min max range  skew kurtosis   se
## av    1 3 19.67 2.31     21   19.67   0  17  21     4 -0.38    -2.33 1.33
## Gruppe: Gruppe A
## Methode: Methode 2
## Messzeitpunkt: Prä
##    vars n mean   sd median trimmed mad min max range  skew kurtosis   se
## av    1 3 3.67 0.58      4    3.67   0   3   4     1 -0.38    -2.33 0.33
## Gruppe: Gruppe B
## Methode: Methode 2
## Messzeitpunkt: Prä
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 8.67 2.52      9    8.67 2.97   6  11     5 -0.13    -2.33 1.45
## Gruppe: Gruppe C
## Methode: Methode 2
## Messzeitpunkt: Prä
##    vars n mean sd median trimmed  mad min max range skew kurtosis   se
## av    1 3   18  1     18      18 1.48  17  19     2    0    -2.33 0.58
## Gruppe: Gruppe A
## Methode: Methode 1
## Messzeitpunkt: Post
##    vars n mean   sd median trimmed  mad min max range skew kurtosis  se
## av    1 3 3.67 2.08      3    3.67 1.48   2   6     4 0.29    -2.33 1.2
## Gruppe: Gruppe B
## Methode: Methode 1
## Messzeitpunkt: Post
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3    8 2.65      9       8 1.48   5  10     5 -0.32    -2.33 1.53
## Gruppe: Gruppe C
## Methode: Methode 1
## Messzeitpunkt: Post
##    vars n mean   sd median trimmed  mad min max range skew kurtosis   se
## av    1 3   18 2.65     17      18 1.48  16  21     5 0.32    -2.33 1.53
## Gruppe: Gruppe A
## Methode: Methode 2
## Messzeitpunkt: Post
##    vars n mean   sd median trimmed mad min max range  skew kurtosis   se
## av    1 3 7.67 0.58      8    7.67   0   7   8     1 -0.38    -2.33 0.33
## Gruppe: Gruppe B
## Methode: Methode 2
## Messzeitpunkt: Post
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 9.67 5.86     12    9.67 2.97   3  14    11 -0.34    -2.33 3.38
## Gruppe: Gruppe C
## Methode: Methode 2
## Messzeitpunkt: Post
##    vars n  mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 21.33 3.79     23   21.33 1.48  17  24     7 -0.35    -2.33 2.19
## Gruppe: Gruppe A
## Methode: Methode 1
## Messzeitpunkt: Post2
##    vars n mean   sd median trimmed mad min max range skew kurtosis   se
## av    1 3 4.33 0.58      4    4.33   0   4   5     1 0.38    -2.33 0.33
## Gruppe: Gruppe B
## Methode: Methode 1
## Messzeitpunkt: Post2
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 7.67 3.51      8    7.67 4.45   4  11     7 -0.09    -2.33 2.03
## Gruppe: Gruppe C
## Methode: Methode 1
## Messzeitpunkt: Post2
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3   21 3.61     22      21 2.97  17  24     7 -0.26    -2.33 2.08
## Gruppe: Gruppe A
## Methode: Methode 2
## Messzeitpunkt: Post2
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 7.67 1.53      8    7.67 1.48   6   9     3 -0.21    -2.33 0.88
## Gruppe: Gruppe B
## Methode: Methode 2
## Messzeitpunkt: Post2
##    vars n  mean   sd median trimmed  mad min max range  skew kurtosis   se
## av    1 3 12.67 7.57     16   12.67 2.97   4  18    14 -0.35    -2.33 4.37
## Gruppe: Gruppe C
## Methode: Methode 2
## Messzeitpunkt: Post2
##    vars n  mean   sd median trimmed  mad min max range skew kurtosis   se
## av    1 3 23.33 5.13     22   23.33 4.45  19  29    10 0.24    -2.33 2.96
## Balanciertheit (N pro Zelle)
table(dat$Gruppe, dat$Methode, dat$Messzeitpunkt) 
## , ,  = Prä
## 
##           
##            Methode 1 Methode 2
##   Gruppe A         3         3
##   Gruppe B         3         3
##   Gruppe C         3         3
## 
## , ,  = Post
## 
##           
##            Methode 1 Methode 2
##   Gruppe A         3         3
##   Gruppe B         3         3
##   Gruppe C         3         3
## 
## , ,  = Post2
## 
##           
##            Methode 1 Methode 2
##   Gruppe A         3         3
##   Gruppe B         3         3
##   Gruppe C         3         3
## , ,  = Prä
## 
##           
##            Methode 1 Methode 2
##   Gruppe A         3         3
##   Gruppe B         3         3
##   Gruppe C         3         3
## 
## , ,  = Post
## 
##           
##            Methode 1 Methode 2
##   Gruppe A         3         3
##   Gruppe B         3         3
##   Gruppe C         3         3
## 
## , ,  = Post2
## 
##           
##            Methode 1 Methode 2
##   Gruppe A         3         3
##   Gruppe B         3         3
##   Gruppe C         3         3
## ++ Mixed (= between und within Faktoren) ANOVA
# Diesen Code kann man beliebig an alle ANOVA-Designs anpassen - einfach
# zusätzliche Faktoren mit "," getrennt in die Klammer dazuschreiben und
# in deinem Design nicht vorhandene Faktoren rausläschen. 

fit <- afex::aov_ez(data = dat, # Name des Datensatzes
                    dv = "av", # aV
                    id = "ID", # Versuchspersonennummer-Variable
                    between = c("Gruppe", "Methode"), # between Faktoren hier
                    observed = c("Gruppe"), # alle nicht-manipulierten Faktoren hier
                    within = c("Messzeitpunkt")) # within Faktoren hier
## Contrasts set to contr.sum for the following variables: Gruppe, Methode
## Contrasts set to contr.sum for the following variables: Gruppe, Methode
# oben ANOVA Ergebnis, darunter Sphärizitätstest (nur wenn es mindestens einen
# within-Faktor mit mindestens 3 Stufen gibt) und Sphärizitätskorrektur
summary(fit)
## 
## Univariate Type III Repeated-Measures ANOVA Assuming Sphericity
## 
##                              Sum Sq num Df Error SS den Df  F value    Pr(>F)
## (Intercept)                  7257.0      1   268.00     12 324.9386 4.676e-10
## Gruppe                       2197.5      2   268.00     12  49.1973 1.650e-06
## Methode                        46.3      1   268.00     12   2.0730   0.17550
## Gruppe:Methode                  4.6      2   268.00     12   0.1028   0.90308
## Messzeitpunkt                  43.4      2   130.67     24   3.9830   0.03208
## Gruppe:Messzeitpunkt           23.5      4   130.67     24   1.0799   0.38843
## Methode:Messzeitpunkt          55.6      2   130.67     24   5.1054   0.01421
## Gruppe:Methode:Messzeitpunkt   11.5      4   130.67     24   0.5289   0.71558
##                                 
## (Intercept)                  ***
## Gruppe                       ***
## Methode                         
## Gruppe:Methode                  
## Messzeitpunkt                *  
## Gruppe:Messzeitpunkt            
## Methode:Messzeitpunkt        *  
## Gruppe:Methode:Messzeitpunkt    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Mauchly Tests for Sphericity
## 
##                              Test statistic p-value
## Messzeitpunkt                        0.8166 0.32814
## Gruppe:Messzeitpunkt                 0.8166 0.32814
## Methode:Messzeitpunkt                0.8166 0.32814
## Gruppe:Methode:Messzeitpunkt         0.8166 0.32814
## 
## 
## Greenhouse-Geisser and Huynh-Feldt Corrections
##  for Departure from Sphericity
## 
##                               GG eps Pr(>F[GG])  
## Messzeitpunkt                0.84503    0.04070 *
## Gruppe:Messzeitpunkt         0.84503    0.38533  
## Methode:Messzeitpunkt        0.84503    0.02002 *
## Gruppe:Methode:Messzeitpunkt 0.84503    0.68774  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##                                 HF eps Pr(>F[HF])
## Messzeitpunkt                0.9685146 0.03366831
## Gruppe:Messzeitpunkt         0.9685146 0.38790360
## Methode:Messzeitpunkt        0.9685146 0.01523019
## Gruppe:Methode:Messzeitpunkt 0.9685146 0.71028600
## 
## Univariate Type III Repeated-Measures ANOVA Assuming Sphericity
## 
##                              Sum Sq num Df Error SS den Df  F value    Pr(>F)
## (Intercept)                  7257.0      1   268.00     12 324.9386 4.676e-10
## Gruppe                       2197.5      2   268.00     12  49.1973 1.650e-06
## Methode                        46.3      1   268.00     12   2.0730   0.17550
## Gruppe:Methode                  4.6      2   268.00     12   0.1028   0.90308
## Messzeitpunkt                  43.4      2   130.67     24   3.9830   0.03208
## Gruppe:Messzeitpunkt           23.5      4   130.67     24   1.0799   0.38843
## Methode:Messzeitpunkt          55.6      2   130.67     24   5.1054   0.01421
## Gruppe:Methode:Messzeitpunkt   11.5      4   130.67     24   0.5289   0.71558
##                                 
## (Intercept)                  ***
## Gruppe                       ***
## Methode                         
## Gruppe:Methode                  
## Messzeitpunkt                *  
## Gruppe:Messzeitpunkt            
## Methode:Messzeitpunkt        *  
## Gruppe:Methode:Messzeitpunkt    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Mauchly Tests for Sphericity
## 
##                              Test statistic p-value
## Messzeitpunkt                        0.8166 0.32814
## Gruppe:Messzeitpunkt                 0.8166 0.32814
## Methode:Messzeitpunkt                0.8166 0.32814
## Gruppe:Methode:Messzeitpunkt         0.8166 0.32814
## 
## 
## Greenhouse-Geisser and Huynh-Feldt Corrections
##  for Departure from Sphericity
## 
##                               GG eps Pr(>F[GG])  
## Messzeitpunkt                0.84503    0.04070 *
## Gruppe:Messzeitpunkt         0.84503    0.38533  
## Methode:Messzeitpunkt        0.84503    0.02002 *
## Gruppe:Methode:Messzeitpunkt 0.84503    0.68774  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##                                 HF eps Pr(>F[HF])
## Messzeitpunkt                0.9685146 0.03366831
## Gruppe:Messzeitpunkt         0.9685146 0.38790360
## Methode:Messzeitpunkt        0.9685146 0.01523019
## Gruppe:Methode:Messzeitpunkt 0.9685146 0.71028600
# Hier nochmal die Greenhouse-Geisser Korrigierten Freiheitsgrade und p-Werte für 
# den Bericht:
fit
## Anova Table (Type 3 tests)
## 
## Response: av
##                         Effect          df   MSE         F  ges p.value
## 1                       Gruppe       2, 12 22.33 49.20 *** .834   <.001
## 2                      Methode       1, 12 22.33      2.07 .017    .176
## 3               Gruppe:Methode       2, 12 22.33      0.10 .002    .903
## 4                Messzeitpunkt 1.69, 20.28  6.44    3.98 * .016    .041
## 5         Gruppe:Messzeitpunkt 3.38, 20.28  6.44      1.08 .009    .385
## 6        Methode:Messzeitpunkt 1.69, 20.28  6.44    5.11 * .021    .020
## 7 Gruppe:Methode:Messzeitpunkt 3.38, 20.28  6.44      0.53 .004    .688
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
## 
## Sphericity correction method: GG
## Anova Table (Type 3 tests)
## 
## Response: av
##                         Effect          df   MSE         F  ges p.value
## 1                       Gruppe       2, 12 22.33 49.20 *** .834   <.001
## 2                      Methode       1, 12 22.33      2.07 .017    .176
## 3               Gruppe:Methode       2, 12 22.33      0.10 .002    .903
## 4                Messzeitpunkt 1.69, 20.28  6.44    3.98 * .016    .041
## 5         Gruppe:Messzeitpunkt 3.38, 20.28  6.44      1.08 .009    .385
## 6        Methode:Messzeitpunkt 1.69, 20.28  6.44    5.11 * .021    .020
## 7 Gruppe:Methode:Messzeitpunkt 3.38, 20.28  6.44      0.53 .004    .688
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
## 
## Sphericity correction method: GG
## ++ Effektstärken und deren 95% Konfidenzintervalle 
## generalized eta squared
eta_squared(
  fit,
  generalized = c("Gruppe"), # hier alle nicht-manipulierten uVs eintragen
  ci = 0.95,
  verbose = TRUE)
## # Effect Size for ANOVA (Type III)
## 
## Parameter                    | Eta2 (generalized) |       95% CI
## ----------------------------------------------------------------
## Gruppe                       |               0.83 | [0.63, 1.00]
## Methode                      |               0.02 | [0.00, 1.00]
## Gruppe:Methode               |           1.74e-03 | [0.00, 1.00]
## Messzeitpunkt                |               0.02 | [0.00, 1.00]
## Gruppe:Messzeitpunkt         |           8.92e-03 | [0.00, 1.00]
## Methode:Messzeitpunkt        |               0.02 | [0.00, 1.00]
## Gruppe:Methode:Messzeitpunkt |           4.37e-03 | [0.00, 1.00]
## 
## - Observed variables: Gruppe
## - One-sided CIs: upper bound fixed at [1.00].
## # Effect Size for ANOVA (Type III)
## 
## Parameter                    | Eta2 (generalized) |       95% CI
## Gruppe                       |               0.83 | [0.63, 1.00]
## Methode                      |               0.02 | [0.00, 1.00]
## Gruppe:Methode               |           1.74e-03 | [0.00, 1.00]
## Messzeitpunkt                |               0.02 | [0.00, 1.00]
## Gruppe:Messzeitpunkt         |           8.92e-03 | [0.00, 1.00]
## Methode:Messzeitpunkt        |               0.02 | [0.00, 1.00]
## Gruppe:Methode:Messzeitpunkt |           4.37e-03 | [0.00, 1.00]
## 
## - Observed variables: Gruppe
## - One-sided CIs: upper bound fixed at [1.00].
## partial eta squared
eta_squared(
  fit,
  partial = TRUE,
  ci = 0.95,
  verbose = TRUE)
## # Effect Size for ANOVA (Type III)
## 
## Parameter                    | Eta2 (partial) |       95% CI
## ------------------------------------------------------------
## Gruppe                       |           0.89 | [0.75, 1.00]
## Methode                      |           0.15 | [0.00, 1.00]
## Gruppe:Methode               |           0.02 | [0.00, 1.00]
## Messzeitpunkt                |           0.25 | [0.01, 1.00]
## Gruppe:Messzeitpunkt         |           0.15 | [0.00, 1.00]
## Methode:Messzeitpunkt        |           0.30 | [0.04, 1.00]
## Gruppe:Methode:Messzeitpunkt |           0.08 | [0.00, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
## # Effect Size for ANOVA (Type III)
## 
## Parameter                    | Eta2 (partial) |       95% CI
## Gruppe                       |           0.89 | [0.75, 1.00]
## Methode                      |           0.15 | [0.00, 1.00]
## Gruppe:Methode               |           0.02 | [0.00, 1.00]
## Messzeitpunkt                |           0.25 | [0.01, 1.00]
## Gruppe:Messzeitpunkt         |           0.15 | [0.00, 1.00]
## Methode:Messzeitpunkt        |           0.30 | [0.04, 1.00]
## Gruppe:Methode:Messzeitpunkt |           0.08 | [0.00, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
## ++ post-tests 
# für Faktor Gruppe (Automatisch Tukey-adjusted für multiples Testen)
posthoc_Gruppe <- emmeans(fit, specs = "Gruppe") 
## NOTE: Results may be misleading due to involvement in interactions
## NOTE: Results may be misleading due to involvement in interactions
pairs(posthoc_Gruppe, 
      adjust="holm") # hier: Bonferroni-Holm-korrektur für diese 3 Vergleiche
##  contrast            estimate   SE df t.ratio p.value
##  Gruppe A - Gruppe B    -4.56 1.58 12  -2.892  0.0135
##  Gruppe A - Gruppe C   -15.22 1.58 12  -9.663  <.0001
##  Gruppe B - Gruppe C   -10.67 1.58 12  -6.771  <.0001
## 
## Results are averaged over the levels of: Methode, Messzeitpunkt 
## P value adjustment: holm method for 3 tests
##  contrast            estimate   SE df t.ratio p.value
##  Gruppe A - Gruppe B    -4.56 1.58 12  -2.892  0.0135
##  Gruppe A - Gruppe C   -15.22 1.58 12  -9.663  <.0001
##  Gruppe B - Gruppe C   -10.67 1.58 12  -6.771  <.0001
## 
## Results are averaged over the levels of: Methode, Messzeitpunkt 
## P value adjustment: holm method for 3 tests
# für Faktor Messzeitpunkt
posthoc_MZP <- emmeans(fit, specs = "Messzeitpunkt") 
pairs(posthoc_MZP, adjust="tukey") # hier: Tukey family-wise error für diese 3 Vergleiche
##  contrast     estimate    SE df t.ratio p.value
##  Prä - Post     -0.778 0.813 12  -0.957  0.6164
##  Prä - Post2    -2.167 0.892 12  -2.428  0.0759
##  Post - Post2   -1.389 0.598 12  -2.321  0.0910
## 
## Results are averaged over the levels of: Gruppe, Methode 
## P value adjustment: tukey method for comparing a family of 3 estimates
##  contrast     estimate    SE df t.ratio p.value
##  Prä - Post     -0.778 0.813 12  -0.957  0.6164
##  Prä - Post2    -2.167 0.892 12  -2.428  0.0759
##  Post - Post2   -1.389 0.598 12  -2.321  0.0910
## 
## Results are averaged over the levels of: Gruppe, Methode 
## P value adjustment: tukey method for comparing a family of 3 estimates
# für Faktor Interaktion Methode x Messzeitpunkt
posthoc_Int <- emmeans(fit, specs = c("Methode", "Messzeitpunkt")) 
pairs(posthoc_Int, adjust="fdr") # hier: False discovery rate angepasste p-Werte für 15 Vergleiche
##  contrast                          estimate    SE df t.ratio p.value
##  Methode 1 Prä - Methode 2 Prä        1.000 0.868 12   1.152  0.4000
##  Methode 1 Prä - Methode 1 Post       1.222 1.150 12   1.063  0.4000
##  Methode 1 Prä - Methode 2 Post      -1.778 1.270 12  -1.395  0.3529
##  Methode 1 Prä - Methode 1 Post2      0.111 1.260 12   0.088  0.9313
##  Methode 1 Prä - Methode 2 Post2     -3.444 1.560 12  -2.203  0.1795
##  Methode 2 Prä - Methode 1 Post       0.222 1.270 12   0.174  0.9262
##  Methode 2 Prä - Methode 2 Post      -2.778 1.150 12  -2.417  0.1625
##  Methode 2 Prä - Methode 1 Post2     -0.889 1.560 12  -0.569  0.6694
##  Methode 2 Prä - Methode 2 Post2     -4.444 1.260 12  -3.522  0.0631
##  Methode 1 Post - Methode 2 Post     -3.000 1.580 12  -1.900  0.2044
##  Methode 1 Post - Methode 1 Post2    -1.111 0.846 12  -1.313  0.3562
##  Methode 1 Post - Methode 2 Post2    -4.667 1.820 12  -2.563  0.1625
##  Methode 2 Post - Methode 1 Post2     1.889 1.820 12   1.037  0.4000
##  Methode 2 Post - Methode 2 Post2    -1.667 0.846 12  -1.970  0.2044
##  Methode 1 Post2 - Methode 2 Post2   -3.556 2.030 12  -1.748  0.2270
## 
## Results are averaged over the levels of: Gruppe 
## P value adjustment: fdr method for 15 tests
##  contrast                          estimate    SE df t.ratio p.value
##  Methode 1 Prä - Methode 2 Prä        1.000 0.868 12   1.152  0.4000
##  Methode 1 Prä - Methode 1 Post       1.222 1.149 12   1.063  0.4000
##  Methode 1 Prä - Methode 2 Post      -1.778 1.274 12  -1.395  0.3529
##  Methode 1 Prä - Methode 1 Post2      0.111 1.262 12   0.088  0.9313
##  Methode 1 Prä - Methode 2 Post2     -3.444 1.563 12  -2.203  0.1795
##  Methode 2 Prä - Methode 1 Post       0.222 1.274 12   0.174  0.9262
##  Methode 2 Prä - Methode 2 Post      -2.778 1.149 12  -2.417  0.1625
##  Methode 2 Prä - Methode 1 Post2     -0.889 1.563 12  -0.569  0.6694
##  Methode 2 Prä - Methode 2 Post2     -4.444 1.262 12  -3.522  0.0631
##  Methode 1 Post - Methode 2 Post     -3.000 1.579 12  -1.900  0.2044
##  Methode 1 Post - Methode 1 Post2    -1.111 0.846 12  -1.313  0.3562
##  Methode 1 Post - Methode 2 Post2    -4.667 1.821 12  -2.563  0.1625
##  Methode 2 Post - Methode 1 Post2     1.889 1.821 12   1.037  0.4000
##  Methode 2 Post - Methode 2 Post2    -1.667 0.846 12  -1.970  0.2044
##  Methode 1 Post2 - Methode 2 Post2   -3.556 2.034 12  -1.748  0.2270
## 
## Results are averaged over the levels of: Gruppe 
## P value adjustment: fdr method for 15 tests
## ++ Grafische Darstellung der Ergebnisse
afex::afex_plot(object = fit,
                x = "Messzeitpunkt", # Faktor Messzeitpunkt auf x-Achse
                trace = "Methode", # Faktor Methode als Linien in verschiedenen Farben 
                panel = "Gruppe", # Faktor Gruppe in verschiedenen Plots
                mapping = "color")
## Warning: Panel(s) show a mixed within-between-design.
## Error bars do not allow comparisons across all means.
## Suppress error bars with: error = "none"

## Warning: Panel(s) show a mixed within-between-design.
## Error bars do not allow comparisons across all means.
## Suppress error bars with: error = "none"


# Violinplot (hier erkennt man auch Verteilungen, also auch Heteroskedastizität z.B.)
library(ggplot2) # ggf. installieren mit install.packages("ggplot2")
## 
## Attache Paket: 'ggplot2'
## Die folgenden Objekte sind maskiert von 'package:psych':
## 
##     %+%, alpha
## 
## Attache Paket: 'ggplot2'
## Die folgenden Objekte sind maskiert von 'package:psych':
## 
##     %+%, alpha
plot_JOL <- afex_plot(fit, x = "Messzeitpunkt", trace = "Methode", panel = "Gruppe",
                      mapping = c("shape", "color"),
                      factor_levels = list(Messzeitpunkt = c("Prä", "Post", "Post 2"), 
                                           Methode = c("Methode 1", "Methode 2"),
                                           Gruppe = c("Gruppe A", "Gruppe B", "Gruppe C")),
                      legend_title = "Methode",
                      error = "model",
                      error_ci = T,
                      data_geom = geom_violin) +
  labs(y = "Offline Judgement of Learning (%)", x = "Time Interval")
## Renaming/reordering factor levels of 'Messzeitpunkt':
##   Prä -> Prä
##   Post -> Post
##   Post2 -> Post 2
## Renaming/reordering factor levels of 'Methode':
##   Methode 1 -> Methode 1
##   Methode 2 -> Methode 2
## Renaming/reordering factor levels of 'Gruppe':
##   Gruppe A -> Gruppe A
##   Gruppe B -> Gruppe B
##   Gruppe C -> Gruppe C
## Warning: Panel(s) show a mixed within-between-design.
## Error bars do not allow comparisons across all means.
## Suppress error bars with: error = "none"
## Renaming/reordering factor levels of 'Messzeitpunkt':
##   Prä -> Prä
##   Post -> Post
##   Post2 -> Post 2
## Renaming/reordering factor levels of 'Methode':
##   Methode 1 -> Methode 1
##   Methode 2 -> Methode 2
## Renaming/reordering factor levels of 'Gruppe':
##   Gruppe A -> Gruppe A
##   Gruppe B -> Gruppe B
##   Gruppe C -> Gruppe C
## Warning: Panel(s) show a mixed within-between-design.
## Error bars do not allow comparisons across all means.
## Suppress error bars with: error = "none"
plot_JOL + theme_minimal() # oder theme_bw()

## ++ Voraussetzungsprüfungen 
# (Achtung: Manche der Befehle benötigen das fit-Objekt, das geht also erst nachdem 
# die ANOVA gerechnet wurde! (und ja, das ist "erlaubt" in der Reihenfolge)

# Korrekte Spezifikation
# residual vs fitted plot (Punkte sollten sich vertikal unsystematisch und 
# über die gesamte x-Achse gleich streuend um die 0 verteilen)
plot(x = fitted(fit), y = resid(fit)) 
## Data was changed during ANOVA calculation. Thus, fitted values cannot be added to original data.
## fitted(..., append = TRUE) will return data and fitted values.
## Data was changed during ANOVA calculation. Thus, residuals cannot be added to original data.
## residuals(..., append = TRUE) will return data and residuals.

## Data was changed during ANOVA calculation. Thus, fitted values cannot be added to original data.
## fitted(..., append = TRUE) will return data and fitted values.
## Data was changed during ANOVA calculation. Thus, residuals cannot be added to original data.
## residuals(..., append = TRUE) will return data and residuals.


## Normalverteilung
# exemplarisches Histogram zur grafischen Prüfung der Normalverteilung in der 
# Faktorkombination Post x Methode 1 (empfohlen, hier erkennt man auch Decken-
# effekte gut)
hist(dat$av[dat$Messzeitpunkt == "Post" & 
              dat$Methode == "Methode 1"]) # nicht gut erkennbar bei kleinem N

# shapiro-wilck test (NICHT EMPFOHLEN)
shapiro.test(dat$av[dat$Messzeitpunkt == "Post" & 
                      dat$Methode == "Methode 1"]) 
## 
##  Shapiro-Wilk normality test
## 
## data:  dat$av[dat$Messzeitpunkt == "Post" & dat$Methode == "Methode 1"]
## W = 0.92642, p-value = 0.448
## 
##  Shapiro-Wilk normality test
## 
## data:  dat$av[dat$Messzeitpunkt == "Post" & dat$Methode == "Methode 1"]
## W = 0.92642, p-value = 0.448
## Heteroskedastizität prüfen
# standardabweichungen pro Zelle deskriptiv prüfen
# sd der av pro Faktorstufenkombination (in Spalte av)
aggregate(av ~ Gruppe * Methode * Messzeitpunkt, 
          dat,
          function(x) sd(x)) 
##      Gruppe   Methode Messzeitpunkt        av
## 1  Gruppe A Methode 1           Prä 1.0000000
## 2  Gruppe B Methode 1           Prä 2.5166115
## 3  Gruppe C Methode 1           Prä 2.3094011
## 4  Gruppe A Methode 2           Prä 0.5773503
## 5  Gruppe B Methode 2           Prä 2.5166115
## 6  Gruppe C Methode 2           Prä 1.0000000
## 7  Gruppe A Methode 1          Post 2.0816660
## 8  Gruppe B Methode 1          Post 2.6457513
## 9  Gruppe C Methode 1          Post 2.6457513
## 10 Gruppe A Methode 2          Post 0.5773503
## 11 Gruppe B Methode 2          Post 5.8594653
## 12 Gruppe C Methode 2          Post 3.7859389
## 13 Gruppe A Methode 1         Post2 0.5773503
## 14 Gruppe B Methode 1         Post2 3.5118846
## 15 Gruppe C Methode 1         Post2 3.6055513
## 16 Gruppe A Methode 2         Post2 1.5275252
## 17 Gruppe B Methode 2         Post2 7.5718778
## 18 Gruppe C Methode 2         Post2 5.1316014
##      Gruppe   Methode Messzeitpunkt        av
## 1  Gruppe A Methode 1           Prä 1.0000000
## 2  Gruppe B Methode 1           Prä 2.5166115
## 3  Gruppe C Methode 1           Prä 2.3094011
## 4  Gruppe A Methode 2           Prä 0.5773503
## 5  Gruppe B Methode 2           Prä 2.5166115
## 6  Gruppe C Methode 2           Prä 1.0000000
## 7  Gruppe A Methode 1          Post 2.0816660
## 8  Gruppe B Methode 1          Post 2.6457513
## 9  Gruppe C Methode 1          Post 2.6457513
## 10 Gruppe A Methode 2          Post 0.5773503
## 11 Gruppe B Methode 2          Post 5.8594653
## 12 Gruppe C Methode 2          Post 3.7859389
## 13 Gruppe A Methode 1         Post2 0.5773503
## 14 Gruppe B Methode 1         Post2 3.5118846
## 15 Gruppe C Methode 1         Post2 3.6055513
## 16 Gruppe A Methode 2         Post2 1.5275252
## 17 Gruppe B Methode 2         Post2 7.5718778
## 18 Gruppe C Methode 2         Post2 5.1316014
# Levene-Test (NICHT EMPFOHLEN)
library(car) # für leveneTest, ggf. vorher installieren mit install.packages("car")
## Lade nötiges Paket: carData
## 
## Attache Paket: 'car'
## Das folgende Objekt ist maskiert 'package:psych':
## 
##     logit
## Lade nötiges Paket: carData
## 
## Attache Paket: 'car'
## Das folgende Objekt ist maskiert 'package:psych':
## 
##     logit
leveneTest(av ~ Gruppe * Methode * Messzeitpunkt, 
           data = dat, 
           center = median) 
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group 17  0.6584 0.8205
##       36
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group 17  0.6584 0.8205
##       36
## Sphärizität
# siehe Output summary(fit)

## Ausreißer: Boxplot pro Faktorkombination (Zelle)
boxplot(dat$av ~ dat$Faktor_A * dat$Faktor_B * dat$ Messzeitpunkt)