
14.3 Three-Way Tables 545
A. sagrei A. distichus
Perch Diameter Perch Diameter
≤4 >4 ≤4 >4
Perch Height >4.75 32 11 61 41
(in feet)
≤4.75 86 35 73 70
The data is classified with respect to three dichotomous factors: Height at
levels Low (
≤4.75) and High (>4.75), Diameter at levels Small (≤4) and Large
(
> 4), and Species with levels A. sagrei and A. distichus. Are these three fac-
tors independent? The null hypothesis is that the factors are independent and
the alternative is that they are not. The MATLAB program
tablerxcxp.m
calculates the expected frequencies (under mutual independence hypothesis)
and provides the
χ
2
statistic, its degrees of freedom, and the p-value. This
program also outputs the expected frequencies in the format that matches the
input data. Here, Height is the row factor R, Diameter is the column factor C,
and Species is the page factor P.
anolis = [32 11; 86 35];
anolis(:,:,2)=[61 41; 73 70];
[ch2 df pv exp]=tablerxcxp(anolis)
%ch2 = 23.9055
%df = 4
%pv =8.3434e-005
%exp(:,:,1) =
% 35.8233 22.3185
% 65.2231 40.6351
%exp(:,:,2) =
% 53.5165 33.3417
% 97.4370 60.7048
The hypothesis H
0
is rejected (with p-value < 5%), and we infer that the
three factors are not independent. However, this analysis does not fully ex-
plain the dependencies responsible for rejecting H
0
. Are all three factors de-
pendent, or maybe two of the factors are mutually dependent and the third
is independent of both? When H
0
is rejected, we need a partial independence
test, similar to pairwise comparisons in the case where the ANOVA hypothesis
is rejected. The MATLAB program for this test is
partialrxcxp.m.
[ch2 df pv exp]=partialrxcxp(anolis,’r
_
cp’)
%ch2 = 12.3028; df=3; pv = 0.0064, exp=...
[ch2 df pv exp]=partialrxcxp(anolis,’c
_
pr’)
%ch2 = 14.4498; df=3; pv = 0.0024, exp=...
[ch2 df pv exp]=partialrxcxp(anolis,’p
_
rc’)
%ch2 = 23.9792; df=3; pv =2.5231e-005, exp=...
Three tests are performed: (i) the row factor independent of column/page
factors (
partial = ’r
_
cp’), (ii) the column factor independent of row/page fac-
tors (
partial = ’c
_
rp’), and (iii) the page factor independent of row/column
factors (
partial = ’p
_
rc’). It is evident from the output that all three tests