Traditional univariate analysis and multivariate approach.
wants <- c("car", "effectsize", "DescTools")
has <- wants %in% rownames(installed.packages())
if(any(!has)) install.packages(wants[!has])
aov()
with data in long formatset.seed(123)
N <- 10
P <- 4
muJ <- rep(c(-1, 0, 1, 2), each=N)
dfRBpL <- data.frame(id=factor(rep(1:N, times=P)),
IV=factor(rep(1:P, each=N)),
DV=rnorm(N*P, muJ, 3))
Error: id
Df Sum Sq Mean Sq F value Pr(>F)
Residuals 9 60.81 6.757
Error: id:IV
Df Sum Sq Mean Sq F value Pr(>F)
IV 3 82.51 27.504 3.851 0.0205 *
Residuals 27 192.86 7.143
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Group | Parameter | Eta2 | 90% CI
---------------------------------------
id:IV | IV | 0.25 | [0.00, 0.42]
Group | Parameter | Eta2 (partial) | 90% CI
-------------------------------------------------
id:IV | IV | 0.30 | [0.03, 0.48]
Group | Parameter | Eta2 (generalized) | 90% CI
-----------------------------------------------------
id:IV | IV | 0.25 | [0.00, 0.42]
Anova()
from package car
with data in wide formatlibrary(car)
fitRBp <- lm(cbind(DV.1, DV.2, DV.3, DV.4) ~ 1, data=dfRBpW)
inRBp <- data.frame(IV=gl(P, 1))
AnovaRBp <- Anova(fitRBp, idata=inRBp, idesign=~IV)
summary(AnovaRBp, multivariate=FALSE, univariate=TRUE)
Univariate Type III Repeated-Measures ANOVA Assuming Sphericity
Sum Sq num Df Error SS den Df F value Pr(>F)
(Intercept) 16.157 1 60.813 9 2.3912 0.15643
IV 82.512 3 192.859 27 3.8505 0.02047 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Mauchly Tests for Sphericity
Test statistic p-value
IV 0.30399 0.10403
Greenhouse-Geisser and Huynh-Feldt Corrections
for Departure from Sphericity
GG eps Pr(>F[GG])
IV 0.58505 0.04805 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
HF eps Pr(>F[HF])
IV 0.7155256 0.03663577
anova.mlm()
and mauchly.test()
with data in wide formatAnalysis of Variance Table
Contrasts orthogonal to
~1
Contrasts spanned by
~IV
Greenhouse-Geisser epsilon: 0.5851
Huynh-Feldt epsilon: 0.7155
Df F num Df den Df Pr(>F) G-G Pr H-F Pr
(Intercept) 1 3.8505 3 27 0.020472 0.048054 0.036636
Residuals 9
Mauchly's test of sphericity
Contrasts orthogonal to
~1
Contrasts spanned by
~IV
data: SSD matrix from lm(formula = cbind(DV.1, DV.2, DV.3, DV.4) ~ 1, data = dfRBpW)
W = 0.30399, p-value = 0.104
HotellingsT2Test()
from package DescTools
DVw <- data.matrix(subset(dfRBpW,
select=c("DV.1", "DV.2", "DV.3", "DV.4")))
diffMat <- combn(1:P, 2, function(x) { DVw[ , x[1]] - DVw[ , x[2]] } )
DVdiff <- diffMat[ , 1:(P-1), drop=FALSE]
muH0 <- rep(0, ncol(DVdiff))
Hotelling's one sample T2-test
data: DVdiff
T.2 = 12.267, df1 = 3, df2 = 7, p-value = 0.003555
alternative hypothesis: true location is not equal to c(0,0,0)
Anova()
from package car
Type III Repeated Measures MANOVA Tests:
------------------------------------------
Term: (Intercept)
Response transformation matrix:
(Intercept)
DV.1 1
DV.2 1
DV.3 1
DV.4 1
Sum of squares and products for the hypothesis:
(Intercept)
(Intercept) 64.6278
Multivariate Tests: (Intercept)
Df test stat approx F num Df den Df Pr(>F)
Pillai 1 0.2099135 2.391158 1 9 0.15643
Wilks 1 0.7900865 2.391158 1 9 0.15643
Hotelling-Lawley 1 0.2656842 2.391158 1 9 0.15643
Roy 1 0.2656842 2.391158 1 9 0.15643
------------------------------------------
Term: IV
Response transformation matrix:
IV1 IV2 IV3
DV.1 1 0 0
DV.2 0 1 0
DV.3 0 0 1
DV.4 -1 -1 -1
Sum of squares and products for the hypothesis:
IV1 IV2 IV3
IV1 140.04485 87.57883 121.24202
IV2 87.57883 54.76853 75.82024
IV3 121.24202 75.82024 104.96371
Multivariate Tests: IV
Df test stat approx F num Df den Df Pr(>F)
Pillai 1 0.840184 12.26683 3 7 0.0035548 **
Wilks 1 0.159816 12.26683 3 7 0.0035548 **
Hotelling-Lawley 1 5.257214 12.26683 3 7 0.0035548 **
Roy 1 5.257214 12.26683 3 7 0.0035548 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
try(detach(package:car))
try(detach(package:carData))
try(detach(package:DescTools))
try(detach(package:effectsize))
R markdown - markdown - R code - all posts