c("car")
wants <- wants %in% rownames(installed.packages())
has <-if(any(!has)) install.packages(wants[!has])
set.seed(123)
100
N <- rnorm(N, 175, 7)
X1 <- rnorm(N, 30, 8)
X2 <- abs(rnorm(N, 60, 30))
X3 <- 0.2*X1 - 0.3*X2 - 0.4*X3 + 10 + rnorm(N, 0, 10)
Y1 <- -0.3*X2 + 0.2*X3 + rnorm(N, 10)
Y2 <- cbind(Y1, Y2)
Y <- data.frame(X1, X2, X3, Y1, Y2) dfRegr <-
lm(cbind(Y1, Y2) ~ X1 + X2 + X3, data=dfRegr)) (fit <-
Call:
lm(formula = cbind(Y1, Y2) ~ X1 + X2 + X3, data = dfRegr)
Coefficients:
Y1 Y2
(Intercept) 23.08395 16.32336
X1 0.12078 -0.03185
X2 -0.24223 -0.31782
X3 -0.41913 0.19836
coef(lm(Y1 ~ X1 + X2 + X3, data=dfRegr))
(Intercept) X1 X2 X3
23.0839518 0.1207848 -0.2422273 -0.4191290
coef(lm(Y2 ~ X1 + X2 + X3, data=dfRegr))
(Intercept) X1 X2 X3
16.32335532 -0.03185035 -0.31782397 0.19836272
summary(manova(fit), test="Hotelling-Lawley")
Df Hotelling-Lawley approx F num Df den Df Pr(>F)
X1 1 0.760 36.12 2 95 2.158e-12 ***
X2 1 5.910 280.74 2 95 < 2.2e-16 ***
X3 1 35.086 1666.58 2 95 < 2.2e-16 ***
Residuals 96
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(manova(fit), test="Wilks")
summary(manova(fit), test="Roy")
summary(manova(fit), test="Pillai")
No possibility to use confint()
for multivariate models.
Since no interaction is present in the model, SS type II and III are equivalent here.
library(car) # for Manova()
Manova(fit, type="II")
Type II MANOVA Tests: Pillai test statistic
Df test stat approx F num Df den Df Pr(>F)
X1 1 0.04655 2.32 2 95 0.1039
X2 1 0.86848 313.66 2 95 <2e-16 ***
X3 1 0.97229 1666.58 2 95 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
try(detach(package:car))
R markdown - markdown - R code - all posts