wants <- c("DescTools", "mvtnorm")
has <- wants %in% rownames(installed.packages())
if(any(!has)) install.packages(wants[!has])
set.seed(123)
library(mvtnorm)
Nj <- c(15, 25)
Sigma <- matrix(c(16,-2, -2,9), byrow=TRUE, ncol=2)
mu1 <- c(-4, 4)
Y1 <- round(rmvnorm(Nj[1], mean=mu1, sigma=Sigma))
HotellingsT2()
from package DescTools
Hotelling's one sample T2-test
data: Y1
T.2 = 5.3252, df1 = 2, df2 = 13, p-value = 0.02045
alternative hypothesis: true location is not equal to c(-1,2)
anova.mlm()
Analysis of Variance Table
Df Hotelling-Lawley approx F num Df den Df Pr(>F)
(Intercept) 1 0.81925 5.3252 2 13 0.02045 *
Residuals 14
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
HotellingsT2()
from package DescTools
mu2 <- c(3, 3)
Y2 <- round(rmvnorm(Nj[2], mean=mu2, sigma=Sigma))
Y12 <- rbind(Y1, Y2)
IV <- factor(rep(1:2, Nj))
Hotelling's two sample T2-test
data: Y12 by IV
T.2 = 23.24, df1 = 2, df2 = 37, p-value = 2.901e-07
alternative hypothesis: true location difference is not equal to c(0,0)
anova.mlm()
or manova()
Analysis of Variance Table
Df Hotelling-Lawley approx F num Df den Df Pr(>F)
(Intercept) 1 1.3742 25.423 2 37 1.130e-07 ***
IV 1 1.2562 23.240 2 37 2.901e-07 ***
Residuals 38
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Df Hotelling-Lawley approx F num Df den Df Pr(>F)
IV 1 1.2562 23.24 2 37 2.901e-07 ***
Residuals 38
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
N <- 20
P <- 2
muJK <- c(90, 100, 85, 105)
Sig <- 15
Y1t0 <- rnorm(N, mean=muJK[1], sd=Sig)
Y1t1 <- rnorm(N, mean=muJK[2], sd=Sig)
Y2t0 <- rnorm(N, mean=muJK[3], sd=Sig)
Y2t1 <- rnorm(N, mean=muJK[4], sd=Sig)
Ydf <- data.frame(id=factor(rep(1:N, times=P)),
Y1=c(Y1t0, Y1t1),
Y2=c(Y2t0, Y2t1),
IV=factor(rep(1:P, each=N), labels=c("t0", "t1")))
dfDiff <- aggregate(cbind(Y1, Y2) ~ id, data=Ydf, FUN=diff)
DVdiff <- data.matrix(dfDiff[ , -1])
muH0 <- c(0, 0)
HotellingsT2()
from package DescTools
Hotelling's one sample T2-test
data: DVdiff
T.2 = 6.0014, df1 = 2, df2 = 18, p-value = 0.01007
alternative hypothesis: true location is not equal to c(0,0)
anova.mlm()
Analysis of Variance Table
Df Hotelling-Lawley approx F num Df den Df Pr(>F)
(Intercept) 1 0.66682 6.0014 2 18 0.01007 *
Residuals 19
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
R markdown - markdown - R code - all posts