LMM Instruction

Read Dataset

fullData <- read_csv("C:/R/exp_1/results/eeg/fullData.csv")

Behavioural Data

# lmer(rtDet ~ 1 + group + trialType + cuePos + (1|id), data = data)

Select Comparisons

# Change for every comparisons

data <- fullData |>
  filter(cuePos == "Left",
         hemis == "right",
         ROI == "Occ")

EEG Data

#QQ

#Residual QQ plot
qq_p  <- lm(alpha ~ group*trialType, data = data) 
ggqqplot(residuals(qq_p))

Normality Testing

normality <- data |> 
  group_by(group, trialType) |>
  shapiro_test(alpha) #must be P >.05
normality
## # A tibble: 6 × 5
##   group trialType variable statistic      p
##   <chr> <chr>     <chr>        <dbl>  <dbl>
## 1 C     G         alpha        0.950 0.569 
## 2 C     NG        alpha        0.781 0.0709
## 3 MA    G         alpha        0.988 0.794 
## 4 MA    NG        alpha        0.881 0.328 
## 5 MO    G         alpha        0.831 0.191 
## 6 MO    NG        alpha        0.997 0.893

LMM

# Do this for each ROI(4) in each cuePos(2, with or without neutral subtraction??)

lmm <- lmer(alpha ~ group * trialType * (1|id), data = data)
summary(lmm)
## Linear mixed model fit by REML ['lmerMod']
## Formula: alpha ~ group * trialType * (1 | id)
##    Data: data
## 
## REML criterion at convergence: 40.4
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.73255 -0.32851  0.01463  0.43882  1.62406 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  id       (Intercept) 0.0000   0.0000  
##  Residual             0.9833   0.9916  
## Number of obs: 18, groups:  id, 9
## 
## Fixed effects:
##                     Estimate Std. Error t value
## (Intercept)          -0.3263     0.5725  -0.570
## groupMA              -0.4926     0.8097  -0.608
## groupMO              -2.3297     0.8097  -2.877
## trialTypeNG          -0.3503     0.8097  -0.433
## groupMA:trialTypeNG   0.4135     1.1450   0.361
## groupMO:trialTypeNG   0.3371     1.1450   0.294
## 
## Correlation of Fixed Effects:
##             (Intr) gropMA gropMO trlTNG gMA:TN
## groupMA     -0.707                            
## groupMO     -0.707  0.500                     
## trialTypeNG -0.707  0.500  0.500              
## grpMA:trTNG  0.500 -0.707 -0.354 -0.707       
## grpMO:trTNG  0.500 -0.354 -0.707 -0.707  0.500
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')

ANOVA Base

anova <- aov(alpha ~ group * trialType, data = data)
summary(anova)
##                 Df Sum Sq Mean Sq F value  Pr(>F)   
## group            2 16.539   8.269   8.410 0.00521 **
## trialType        1  0.045   0.045   0.046 0.83397   
## group:trialType  2  0.145   0.073   0.074 0.92923   
## Residuals       12 11.800   0.983                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

ANOVA rstatix

anova_rstatix <- anova_test(data = data,
                            formula = alpha ~ group * trialType,
                            dv = alpha,
                            wid = id,
                            between = c(group, trialType),
                            effect.size = "pes") #"Effect Size (ƞ2p)"
anova_rstatix
## ANOVA Table (type II tests)
## 
##            Effect DFn DFd     F     p p<.05   pes
## 1           group   2  12 8.410 0.005     * 0.584
## 2       trialType   1  12 0.046 0.834       0.004
## 3 group:trialType   2  12 0.074 0.929       0.012
# anova_rstatix |>
#   kbl() |>
#   kable_minimal()


#Cohen's D Benchmarks
#.01: Small effect size
#.06: Medium effect size
#.14 or higher: Large effect size