[R] Nested ANOVA with covariate using Type III sums of squares in R
Anita Narwani
anarwani at uvic.ca
Thu Jun 3 01:59:31 CEST 2010
Hello,
I have been trying to get an ANOVA table for a linear model containing a
single nested factor, two fixed factors and a covariate:
carbonmean<-lm(C.Mean~ Mean.richness + Diversity + Zoop + Diversity/Phyto
+ Zoop*Diversity/Phyto)
where, Mean.richness is a covariate, Zoop is a categorical variable (the
species), Diversity is a categorical variable (Low or High), and Phyto
(community composition) is also categorical but is nested within the level
of Diversity. Quinn & Keough's statistics text recommends using Type III
SS for a nested ANOVA with a covariate.
I get the following output using the Type I SS ANOVA:
Analysis of Variance Table
Response: C.Mean
Df Sum Sq Mean Sq F value Pr(>F)
Mean.richness 1 56385326 56385326 23.5855 3.239e-05 ***
Diversity 1 14476593 14476593 6.0554 0.019634 *
Zoop 1 13002135 13002135 5.4387 0.026365 *
Diversity:Phyto 6 126089387 21014898 8.7904 1.257e-05 ***
Diversity:Zoop 1 263036 263036 0.1100 0.742347
Diversity:Zoop:Phyto 6 61710145 10285024 4.3021 0.002879 **
Residuals 31 74110911 2390675
I have tried using both the drop1() command and the Anova() command in the
car package.
When I use the Anova command I get the following error message:
>Anova(carbonmean,type="III")
“Error in linear.hypothesis.lm(mod, hyp.matrix, summary.model = sumry,:
One or more terms aliased in model.”
I am not sure why this is aliased. There are no missing cells, and the
cells are balanced (aside from for the covariate). Each Phyto by Zoop
cross is replicated 3 times, and there are four Phyto levels within each
level of Diversity. When I remove the nested factor (Phyto), I am able to
get the Type III SS output.
Then when I use drop1(carbonmean,.~.,Test=”F”) I get the following output:
> drop1(carbonmean,.~.,Test="F")
Single term deletions
Model:
C.Mean ~ Mean.richness + Diversity + Zoop + Diversity/Phyto + Zoop *
Diversity/Phyto
Df Sum of Sq RSS AIC
<none> 74110911 718
Mean.richness 1 49790403 123901314 741
Diversity 0 0 74110911 718
Zoop 0 0 74110911 718
Diversity:Phyto 6 118553466 192664376 752
Diversity:Zoop 0 -1.49e-08 74110911 718
Diversity:Zoop:Phyto 6 61710145 135821055 735
There are zero degrees of freedom for Diversity, Zoop and their
interaction, and zero sums of sq for Diversity and Zoop. This cannot be
correct, however when I do the model simplification by dropping terms from
the models manually and comparing them using anova(), I get virtually the
same results.
I would appreciate any suggestions for things to try or pointers as to
what I may be doing incorrectly.
Thank you.
Anita Narwani.
PhD Candidate
Water & Aquatic Sciences Research Program
University of Victoria, Department of Biology
More information about the R-help
mailing list