c("DescTools", "mvtnorm")
wants <- wants %in% rownames(installed.packages())
has <-if(any(!has)) install.packages(wants[!has])
set.seed(123)
library(mvtnorm)
c(15, 25)
Nj <- matrix(c(16,-2, -2,9), byrow=TRUE, ncol=2)
Sigma <- c(-4, 4)
mu1 <- round(rmvnorm(Nj[1], mean=mu1, sigma=Sigma)) Y1 <-
HotellingsT2()
from package DescTools
c(-1, 2)
muH0 <-library(DescTools)
HotellingsT2Test(Y1, mu=muH0)
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()
sweep(Y1, 2, muH0, "-")
Y1ctr <- anova(lm(Y1ctr ~ 1), test="Hotelling-Lawley")) (anRes <-
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
c(3, 3)
mu2 <- round(rmvnorm(Nj[2], mean=mu2, sigma=Sigma))
Y2 <- rbind(Y1, Y2)
Y12 <- factor(rep(1:2, Nj)) IV <-
library(DescTools)
HotellingsT2Test(Y12 ~ IV)
Hotelling's two sample T2-test
data: Y12 by IV
T.2 = 23.2398, 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()
anova(lm(Y12 ~ IV), test="Hotelling-Lawley")
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
summary(manova(Y12 ~ IV), test="Hotelling-Lawley")
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
20
N <- 2
P <- c(90, 100, 85, 105)
muJK <- 15
Sig <- rnorm(N, mean=muJK[1], sd=Sig)
Y1t0 <- rnorm(N, mean=muJK[2], sd=Sig)
Y1t1 <- rnorm(N, mean=muJK[3], sd=Sig)
Y2t0 <- rnorm(N, mean=muJK[4], sd=Sig)
Y2t1 <- data.frame(id=factor(rep(1:N, times=P)),
Ydf <-Y1=c(Y1t0, Y1t1),
Y2=c(Y2t0, Y2t1),
IV=factor(rep(1:P, each=N), labels=c("t0", "t1")))
aggregate(cbind(Y1, Y2) ~ id, data=Ydf, FUN=diff)
dfDiff <- data.matrix(dfDiff[ , -1])
DVdiff <- c(0, 0) muH0 <-
HotellingsT2()
from package DescTools
library(DescTools)
HotellingsT2Test(DVdiff, mu=muH0)
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()
anova(lm(DVdiff ~ 1), test="Hotelling-Lawley")
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
try(detach(package:DescTools))
try(detach(package:mvtnorm))
R markdown - markdown - R code - all posts