Calculating the MANOVA table

2000-12-06


The data are from Example 6.8 on page 323 of Johnson & Wichern. You should recognize all the results given there in the Splus calculations below.

> manex<-data.frame(y1=c(9,6,9,0,2,3,1,2),y2=c(3,2,7,4,0,8,9,7),pop=factor(
+ c(1,1,1,2,2,3,3,3)))
> manex
  y1 y2 pop
1  9  3   1
2  6  2   1
3  9  7   1
4  0  4   2
5  2  0   2
6  3  8   3
7  1  9   3
8  2  7   3
> manex.out<-manova(cbind(y1,y2)~pop,data=manex)
> manex.out
Call:
   manova(cbind(y1, y2) ~ pop, data = manex)
 
Terms:
                pop Residuals
Deg. of Freedom   2         5
 
Estimated effects may be unbalanced
> summary(manex.out,test="wilks")
          Df Wilks Lambda approx. F num df    den df     P-value
      pop 2  0.038455      8.19886         4         8  0.006234
Residuals 5
> predict(manex.out)
  y1 y2
1  8  4
2  8  4
3  8  4
4  1  2
5  1  2
6  2  8
7  2  8
8  2  8
> manex.treat <- sweep(predict(manex.out),2,apply(manex[,1:2],2,mean))
> manex.treat
  y1 y2
1  4 -1
2  4 -1
3  4 -1
4 -3 -3
5 -3 -3
6 -2  3
7 -2  3
8 -2  3
> t(manex.treat)%*%manex.treat
    y1  y2
y1  78 -12
y2 -12  48
> coef(manex.out)
                    y1        y2
(Intercept)  3.6666667  4.666667
       pop1 -3.5000000 -1.000000
       pop2 -0.8333333  1.666667
> residuals(manex.out)
             y1            y2
1  1.000000e+00 -1.000000e+00
2 -2.000000e+00 -2.000000e+00
3  1.000000e+00  3.000000e+00
4 -1.000000e+00  2.000000e+00
5  1.000000e+00 -2.000000e+00
6  1.000000e+00 -2.220446e-16
7 -1.000000e+00  1.000000e+00
8 -1.665335e-16 -1.000000e+00
> t(residuals(manex.out))%*%residuals(manex.out)
   y1 y2
y1 10  1
y2  1 24
> var(manex[, 1:2], Sum = T)
    y1  y2
y1  88 -11
y2 -11  72
> var(manex[, 1:2], Sum = T) - t(residuals(manex.out)) %*% residuals(manex.out)
    y1  y2
y1  78 -12
y2 -12  48
>

Statistics 4M03