Summary of experiment
- Within subjects design repeated measures with factors of valence condition (pos and negative) fully crossed with three different experiment types (pic, pair, sound).
- Dependent variable is EEG data.
- 23 total subjects (no missing data)
- each subject recieves a positive and negative valence condition paired with 3 different experiments.
- Tests to perform
- a within subjects main effect of difference in valence condition
- a within subjects main effect of difference in experimental condition
- a within subjects interaction between valence and experimental condition
Diagnostic plots
boxplot(DB.df)
library(GGally)

library(ggplot2)
p <- ggpairs(DB.df, mapping = ggplot2::aes(alpha = 0.5), lower = list(continuous = "points"), upper = list(continuous = "cor"))
print(p)

Variance across repeated measures
knitr::kable(DB.var,col.names="Variance")
| POS.PAIR_E |
11.806543 |
| NEG.PAIR_E |
10.948640 |
| POS.PIC_E |
14.200591 |
| NEG.PIC_E |
16.422483 |
| POS.SOUND_E |
5.701284 |
| NEG.SOUND_E |
2.660697 |
Univariate Repeated measures ANOVA (2x3)
library(car)
P <- 2 #positive vs negative valeance
Q <- 3 #levels (pair,pic, sound)
fitRBFpq <- lm(cbind(POS.PAIR_E,NEG.PAIR_E,POS.SOUND_E,NEG.SOUND_E,POS.PIC_E,NEG.PIC_E) ~ 1,data=DB.df)
inRBFpq <- expand.grid(Neg.Pos=gl(P, 1), Exp.type=gl(Q, 1))
options(contrasts=c("contr.sum","contr.poly"))
AnovaRBFpq <- Anova(fitRBFpq, idata=inRBFpq, idesign=~Neg.Pos*Exp.type,type=3)
summary(AnovaRBFpq, multivariate=FALSE, univariate=TRUE) #Univariatie Output
##
## Univariate Type III Repeated-Measures ANOVA Assuming Sphericity
##
## SS num Df Error SS den Df F Pr(>F)
## (Intercept) 848.66 1 1027.55 22 18.1699 0.0003177 ***
## Neg.Pos 5.33 1 23.86 22 4.9153 0.0372619 *
## Exp.type 52.41 2 233.02 44 4.9478 0.0115286 *
## Neg.Pos:Exp.type 0.97 2 73.86 44 0.2878 0.7512879
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Mauchly Tests for Sphericity
##
## Test statistic p-value
## Exp.type 0.72808 0.035720
## Neg.Pos:Exp.type 0.77341 0.067344
##
##
## Greenhouse-Geisser and Huynh-Feldt Corrections
## for Departure from Sphericity
##
## GG eps Pr(>F[GG])
## Exp.type 0.78622 0.01889 *
## Neg.Pos:Exp.type 0.81527 0.70667
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## HF eps Pr(>F[HF])
## Exp.type 0.8362697 0.01682371
## Neg.Pos:Exp.type 0.8714597 0.72137603
Multivariate MANOVA for repeated measures
- Full model including interaction
summary(AnovaRBFpq, multivariate=TRUE, univariate=FALSE) #Multivariate Output
##
## Type III Repeated Measures MANOVA Tests:
##
## ------------------------------------------
##
## Term: (Intercept)
##
## Response transformation matrix:
## (Intercept)
## POS.PAIR_E 1
## NEG.PAIR_E 1
## POS.SOUND_E 1
## NEG.SOUND_E 1
## POS.PIC_E 1
## NEG.PIC_E 1
##
## Sum of squares and products for the hypothesis:
## (Intercept)
## (Intercept) 5091.933
##
## Sum of squares and products for error:
## (Intercept)
## (Intercept) 6165.284
##
## Multivariate Tests: (Intercept)
## Df test stat approx F num Df den Df Pr(>F)
## Pillai 1 0.4523261 18.16989 1 22 0.00031768 ***
## Wilks 1 0.5476739 18.16989 1 22 0.00031768 ***
## Hotelling-Lawley 1 0.8259040 18.16989 1 22 0.00031768 ***
## Roy 1 0.8259040 18.16989 1 22 0.00031768 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## ------------------------------------------
##
## Term: Neg.Pos
##
## Response transformation matrix:
## Neg.Pos1
## POS.PAIR_E 1
## NEG.PAIR_E -1
## POS.SOUND_E 1
## NEG.SOUND_E -1
## POS.PIC_E 1
## NEG.PIC_E -1
##
## Sum of squares and products for the hypothesis:
## Neg.Pos1
## Neg.Pos1 31.98502
##
## Sum of squares and products for error:
## Neg.Pos1
## Neg.Pos1 143.1589
##
## Multivariate Tests: Neg.Pos
## Df test stat approx F num Df den Df Pr(>F)
## Pillai 1 0.1826214 4.915311 1 22 0.037262 *
## Wilks 1 0.8173786 4.915311 1 22 0.037262 *
## Hotelling-Lawley 1 0.2234232 4.915311 1 22 0.037262 *
## Roy 1 0.2234232 4.915311 1 22 0.037262 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## ------------------------------------------
##
## Term: Exp.type
##
## Response transformation matrix:
## Exp.type1 Exp.type2
## POS.PAIR_E 1 0
## NEG.PAIR_E 1 0
## POS.SOUND_E 0 1
## NEG.SOUND_E 0 1
## POS.PIC_E -1 -1
## NEG.PIC_E -1 -1
##
## Sum of squares and products for the hypothesis:
## Exp.type1 Exp.type2
## Exp.type1 13.24368 50.78734
## Exp.type2 50.78734 194.76112
##
## Sum of squares and products for error:
## Exp.type1 Exp.type2
## Exp.type1 233.7272 178.6513
## Exp.type2 178.6513 643.9756
##
## Multivariate Tests: Exp.type
## Df test stat approx F num Df den Df Pr(>F)
## Pillai 1 0.2323805 3.178653 2 21 0.062235 .
## Wilks 1 0.7676195 3.178653 2 21 0.062235 .
## Hotelling-Lawley 1 0.3027288 3.178653 2 21 0.062235 .
## Roy 1 0.3027288 3.178653 2 21 0.062235 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## ------------------------------------------
##
## Term: Neg.Pos:Exp.type
##
## Response transformation matrix:
## Neg.Pos1:Exp.type1 Neg.Pos1:Exp.type2
## POS.PAIR_E 1 0
## NEG.PAIR_E -1 0
## POS.SOUND_E 0 1
## NEG.SOUND_E 0 -1
## POS.PIC_E -1 -1
## NEG.PIC_E 1 1
##
## Sum of squares and products for the hypothesis:
## Neg.Pos1:Exp.type1 Neg.Pos1:Exp.type2
## Neg.Pos1:Exp.type1 2.029744 -0.6567750
## Neg.Pos1:Exp.type2 -0.656775 0.2125161
##
## Sum of squares and products for error:
## Neg.Pos1:Exp.type1 Neg.Pos1:Exp.type2
## Neg.Pos1:Exp.type1 132.7784 125.8952
## Neg.Pos1:Exp.type2 125.8952 214.6993
##
## Multivariate Tests: Neg.Pos:Exp.type
## Df test stat approx F num Df den Df Pr(>F)
## Pillai 1 0.0473668 0.5220802 2 21 0.60079
## Wilks 1 0.9526332 0.5220802 2 21 0.60079
## Hotelling-Lawley 1 0.0497219 0.5220802 2 21 0.60079
## Roy 1 0.0497219 0.5220802 2 21 0.60079
## No id variables; using all as measure variables
Multilevel Model (experiment, valence and interaction terms) for repeated measures with post hoc comparisons
library(nlme)
library(multcomp)
lme_DB_empty <- lme(score~1,random=~1|subj,data=DB.df.long,weights=varIdent(form=~1|condition))
summary(lme_DB_empty)
## Linear mixed-effects model fit by REML
## Data: DB.df.long
## AIC BIC logLik
## 622.6519 646.0117 -303.3259
##
## Random effects:
## Formula: ~1 | subj
## (Intercept) Residual
## StdDev: 3.079258 0.9309695
##
## Variance function:
## Structure: Different standard deviations per stratum
## Formula: ~1 | condition
## Parameter estimates:
## POS.PAIR_E NEG.PAIR_E POS.PIC_E NEG.PIC_E POS.SOUND_E NEG.SOUND_E
## 1.000000 1.320635 1.877713 1.924483 2.687531 2.557708
## Fixed effects: score ~ 1
## Value Std.Error DF t-value p-value
## (Intercept) 2.614 0.6540915 115 3.996383 1e-04
##
## Standardized Within-Group Residuals:
## Min Q1 Med Q3 Max
## -3.40633818 -0.55978754 -0.03324946 0.59650307 1.99622527
##
## Number of Observations: 138
## Number of Groups: 23
ICC <- 3.079^2/(3.079^2+ 0.93^2)
ICC
## [1] 0.9163955
lme_DB_full <- lme(score~valeance*exp,random=~1|subj,data=DB.df.long,weights=varIdent(form=~1|condition))
summary(lme_DB_full)
## Linear mixed-effects model fit by REML
## Data: DB.df.long
## AIC BIC logLik
## 624.9934 662.4698 -299.4967
##
## Random effects:
## Formula: ~1 | subj
## (Intercept) Residual
## StdDev: 3.056297 0.9301308
##
## Variance function:
## Structure: Different standard deviations per stratum
## Formula: ~1 | condition
## Parameter estimates:
## POS.PAIR_E NEG.PAIR_E POS.PIC_E NEG.PIC_E POS.SOUND_E NEG.SOUND_E
## 1.000000 1.248765 1.902186 1.827594 2.433500 2.405657
## Fixed effects: score ~ valeance * exp
## Value Std.Error DF t-value p-value
## (Intercept) 2.4798544 0.6544521 110 3.789207 0.0002
## valeance1 0.1965433 0.1489267 110 1.319732 0.1897
## exp1 0.2320526 0.1737868 110 1.335272 0.1845
## exp2 0.6114640 0.2097399 110 2.915344 0.0043
## valeance1:exp1 0.1150435 0.1737868 110 0.661981 0.5094
## valeance1:exp2 -0.0334908 0.2097399 110 -0.159678 0.8734
## Correlation:
## (Intr) valnc1 exp1 exp2 vln1:1
## valeance1 0.002
## exp1 -0.124 0.062
## exp2 -0.003 -0.033 -0.210
## valeance1:exp1 0.014 -0.547 0.063 -0.020
## valeance1:exp2 -0.007 -0.012 -0.020 -0.016 -0.210
##
## Standardized Within-Group Residuals:
## Min Q1 Med Q3 Max
## -3.20268286 -0.57797780 0.08375137 0.71606802 1.76235459
##
## Number of Observations: 138
## Number of Groups: 23
anova(lme_DB_full)
## numDF denDF F-value p-value
## (Intercept) 1 110 16.207451 0.0001
## valeance 1 110 4.007393 0.0478
## exp 2 110 6.197087 0.0028
## valeance:exp 2 110 0.219332 0.8034
summary(glht(lme_DB_full, linfct=mcp(exp="Tukey")))
## Warning in mcp2matrix(model, linfct = linfct): covariate interactions found
## -- default contrast might be inappropriate
##
## Simultaneous Tests for General Linear Hypotheses
##
## Multiple Comparisons of Means: Tukey Contrasts
##
##
## Fit: lme.formula(fixed = score ~ valeance * exp, data = DB.df.long,
## random = ~1 | subj, weights = varIdent(form = ~1 | condition))
##
## Linear Hypotheses:
## Estimate Std. Error z value Pr(>|z|)
## pic - pair == 0 0.3794 0.2992 1.268 0.40742
## sound - pair == 0 -1.0756 0.3663 -2.936 0.00876 **
## sound - pic == 0 -1.4550 0.4190 -3.473 0.00138 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)
Multilevel Model (main effect of exp only) for repeated measures with post hoc comparisons
## Linear mixed-effects model fit by REML
## Data: DB.df.long
## AIC BIC logLik
## 618.4265 650.3028 -298.2133
##
## Random effects:
## Formula: ~1 | subj
## (Intercept) Residual
## StdDev: 3.054533 0.930108
##
## Variance function:
## Structure: Different standard deviations per stratum
## Formula: ~1 | condition
## Parameter estimates:
## POS.PAIR_E NEG.PAIR_E POS.PIC_E NEG.PIC_E POS.SOUND_E NEG.SOUND_E
## 1.000000 1.246744 1.884932 1.811538 2.410820 2.384064
## Fixed effects: score ~ exp + valeance
## Value Std.Error DF t-value p-value
## (Intercept) 2.4737148 0.6537492 112 3.783890 0.0002
## exp1 0.2247026 0.1723507 112 1.303752 0.1950
## exp2 0.6141748 0.2078633 112 2.954706 0.0038
## valeance1 0.2494311 0.1226799 112 2.033187 0.0444
## Correlation:
## (Intr) exp1 exp2
## exp1 -0.124
## exp2 -0.003 -0.211
## valeance1 0.010 0.115 -0.056
##
## Standardized Within-Group Residuals:
## Min Q1 Med Q3 Max
## -3.29055607 -0.53429756 0.07976385 0.68661992 1.73032222
##
## Number of Observations: 138
## Number of Groups: 23
## numDF denDF F-value p-value
## (Intercept) 1 112 16.228289 0.0001
## exp 2 112 6.253652 0.0027
## valeance 1 112 4.133848 0.0444
##
## Simultaneous Tests for General Linear Hypotheses
##
## Multiple Comparisons of Means: Tukey Contrasts
##
##
## Fit: lme.formula(fixed = score ~ exp + valeance, data = DB.df.long,
## random = ~1 | subj, weights = varIdent(form = ~1 | condition))
##
## Linear Hypotheses:
## Estimate Std. Error z value Pr(>|z|)
## pic - pair == 0 0.3895 0.2967 1.313 0.38240
## sound - pair == 0 -1.0636 0.3630 -2.930 0.00924 **
## sound - pic == 0 -1.4531 0.4150 -3.501 0.00128 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)
##
## Simultaneous Tests for General Linear Hypotheses
##
## Multiple Comparisons of Means: Tukey Contrasts
##
##
## Fit: lme.formula(fixed = score ~ exp + valeance, data = DB.df.long,
## random = ~1 | subj, weights = varIdent(form = ~1 | condition))
##
## Linear Hypotheses:
## Estimate Std. Error z value Pr(>|z|)
## pos - neg == 0 -0.4989 0.2454 -2.033 0.042 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)

