Four response variables
# setwd("C:/...")
dat <- read.table("wechsler.txt", header = TRUE)
str(dat)
## 'data.frame': 37 obs. of 5 variables:
## $ ID : int 1 2 3 4 5 6 7 8 9 10 ...
## $ Info : int 7 8 16 8 6 11 12 8 14 13 ...
## $ Sim : int 5 8 18 3 3 8 7 11 12 13 ...
## $ Arith: int 9 5 11 7 13 10 9 9 11 13 ...
## $ Pic : int 8 6 9 9 9 10 8 3 4 6 ...

mu0 <- rep(10, 4) # H0: mu = 10 for all response variables
X <- subset(dat, select = -ID) |> as.matrix() # without ID
n <- nrow(X)
p <- ncol(X)
x_bar <- colMeans(X) |> print()
## Info Sim Arith Pic
## 12.567568 9.567568 11.486486 7.972973
## Info Sim Arith Pic
## Info 11.474474 9.0855856 6.382883 2.0713213
## Sim 9.085586 12.0855856 5.938438 0.5435435
## Arith 6.382883 5.9384384 11.090090 1.7912913
## Pic 2.071321 0.5435435 1.791291 3.6936937
T2 <- n * t(x_bar - mu0) %*% solve(S) %*% (x_bar - mu0)
(F <- (n - p) / (p * (n - 1)) * T2)
## [,1]
## [1,] 43.06022
(p.value <- 1 - pf(F, p, n - p))
## [,1]
## [1,] 1.187939e-12
qF <- qf(.95, p, n - p) # critical quantile
m1 <- lm(X ~ 1) # multivariate model
confint(m1, level = 1 - .05/p) # Bonferroni adjusted CIs
## 0.625 % 99.375 %
## Info:(Intercept) 11.103265 14.03187
## Sim:(Intercept) 8.064777 11.07036
## Arith:(Intercept) 10.046919 12.92605
## Pic:(Intercept) 7.142176 8.80377
m2 <- lm(X ~ offset(rep(10, n))) # H0: mu = 10
summary(m2) # univariate t tests
## Response Info :
##
## Call:
## lm(formula = Info ~ offset(rep(10, n)))
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.5676 -2.5676 0.4324 2.4324 6.4324
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.5676 0.5569 4.611 4.91e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.387 on 36 degrees of freedom
##
##
## Response Sim :
##
## Call:
## lm(formula = Sim ~ offset(rep(10, n)))
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.5676 -2.5676 0.4324 2.4324 8.4324
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.4324 0.5715 -0.757 0.454
##
## Residual standard error: 3.476 on 36 degrees of freedom
##
##
## Response Arith :
##
## Call:
## lm(formula = Arith ~ offset(rep(10, n)))
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.4865 -2.4865 -0.4865 2.5135 5.5135
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.4865 0.5475 2.715 0.0101 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.33 on 36 degrees of freedom
##
##
## Response Pic :
##
## Call:
## lm(formula = Pic ~ offset(rep(10, n)))
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.973 -0.973 0.027 1.027 3.027
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.027 0.316 -6.415 1.94e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.922 on 36 degrees of freedom
anova(m2) # multivariate test
## Analysis of Variance Table
##
## Df Pillai approx F num Df den Df Pr(>F)
## (Intercept) 1 0.83921 43.06 4 33 1.188e-12 ***
## Residuals 36
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Alternatively: univariate t tests
t <- lapply(dat[, -1], t.test, mu = 10, conf.level = 1 - 0.05/p)
sapply(t, "[[", "conf.int")
## Info Sim Arith Pic
## [1,] 11.10326 8.064777 10.04692 7.142176
## [2,] 14.03187 11.070358 12.92605 8.803770
Two response variables
x_bar <- colMeans(dat[, c("Sim", "Arith")])
S <- cov(dat[, c("Sim", "Arith")])
p <- length(x_bar)
qF <- qf(.95, p, n - p)
d <- sqrt((n - 1)*p/((n - p)*n) * qF) # Mahalanobis distance
m1 <- lm(cbind(Sim, Arith) ~ 1, data = dat)
m2 <- lm(cbind(Sim, Arith) ~ offset(rep(10, n)), data = dat)
anova(m2)
## Analysis of Variance Table
##
## Df Pillai approx F num Df den Df Pr(>F)
## (Intercept) 1 0.2748 6.6312 2 35 0.003614 **
## Residuals 36
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ci_sim <- confint(m1)["Sim:(Intercept)", ]
ci_ari <- confint(m1)["Arith:(Intercept)", ]
ci_sim_b <- confint(m1, level = 1 - .05/p)["Sim:(Intercept)", ]
ci_ari_b <- confint(m1, level = 1 - .05/p)["Arith:(Intercept)", ]
par(mai = c(.6, .6, .1, .1), mgp = c(2, .7, 0), pty = "s")
plot(Arith ~ Sim, dat,
xlab = "Similarities", ylab = "Arithmetic", col = "gray", asp = 1)
abline(v = ci_sim, h = ci_ari, lty = 2)
abline(v = ci_sim_b, h = ci_ari_b, col = "darkgray")
car::ellipse(x_bar, S, d,
col = "darkblue", center.pch = NULL, lwd = 1)
points(t(x_bar), pch = 4, col = "darkblue")
points(10, 10, pch = 16, col = "darkgreen")
