Re: [R] Nested ANOVA with covariate using Type III sums of squares

From: Joris Meys <jorismeys_at_gmail.com>
Date: Fri, 04 Jun 2010 02:23:20 +0200

SPSS uses a different calculation. As far as I understood, they test main effects without the covariate. Regarding the difference between my and your results, did you use sum contrasts?
options(contrasts=c("contr.sum","contr.poly"))

On Fri, Jun 4, 2010 at 2:19 AM, Anita Narwani <anitanarwani_at_gmail.com>wrote:

> Hi Joris,
> That seems to have worked and the contrasts look correct.
> I have tried comparing the results to what SPSS produces for the same
> model. The two programs produce very different results, although the model F
> statistics, R squared and adjusted R squared values are identical. The
> results are so different that I don't know what to trust.
>
> For the same model you coded I got:
>
> test <- lm(C.Mean~ Mean.richness + Diversity + Zoop + Diversity/Phyto +
> + Zoop*Diversity/Phyto)
> > Anova(test,type="III")
> Anova Table (Type III tests)
>
> Response: C.Mean
> Sum Sq Df F value Pr(>F)
> (Intercept) 28223311 1 11.8056 0.001701 **
> Mean.richness 49790403 1 20.8269 7.471e-05 ***
> Diversity 31055477 1 12.9903 0.001082 **
> Zoop 2736238 1 1.1445 0.292953
> Diversity:Phyto 27943313 6 1.9481 0.104103
> Diversity:Zoop 168184 1 0.0703 0.792584
> Diversity:Zoop:Phyto 61710145 6 4.3021 0.002879 **
> Residuals 74110911 31
> ---
> Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
>
> (Also sightly different from your result)
>
> and
>
> > summary(test)
>
> Call:
> lm(formula = C.Mean ~ Mean.richness + Diversity + Zoop + Diversity/Phyto +
> +Zoop * Diversity/Phyto)
>
> Residuals:
> Min 1Q Median 3Q Max
> -3555.26 -479.53 49.94 423.49 4073.20
>
> Coefficients:
> Estimate Std. Error t value Pr(>|t|)
> (Intercept) -8562.9 2492.2 -3.436 0.00170 **
> Mean.richness 4605.7 1009.2 4.564 7.47e-05 ***
> DiversityL 6576.9 1824.8 3.604 0.00108 **
> ZoopD -1414.4 1322.1 -1.070 0.29295
> DiversityH:PhytoP2 -4307.5 1824.8 -2.361 0.02472 *
> DiversityL:PhytoP2 -268.4 1262.5 -0.213 0.83300
> DiversityH:PhytoP3 -2233.4 1393.0 -1.603 0.11900
> DiversityL:PhytoP3 -1571.4 1262.5 -1.245 0.22257
> DiversityH:PhytoP4 -7914.8 2647.2 -2.990 0.00543 **
> DiversityL:PhytoP4 -1612.8 1262.5 -1.277 0.21092
> DiversityL:ZoopD 484.9 1828.0 0.265 0.79258
> DiversityH:ZoopD:PhytoP2 683.9 1855.3 0.369 0.71493
> DiversityL:ZoopD:PhytoP2 6346.4 1785.4 3.555 0.00124 **
> DiversityH:ZoopD:PhytoP3 4922.8 1786.3 2.756 0.00971 **
> DiversityL:ZoopD:PhytoP3 1085.4 1785.4 0.608 0.54766
> DiversityH:ZoopD:PhytoP4 3261.8 1985.6 1.643 0.11055
> DiversityL:ZoopD:PhytoP4 681.9 1785.4 0.382 0.70513
> ---
> Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
>
> Residual standard error: 1546 on 31 degrees of freedom
> Multiple R-squared: 0.7858, Adjusted R-squared: 0.6753
> F-statistic: 7.109 on 16 and 31 DF, p-value: 1.810e-06
>
> From SPSS I got
> Tests of Between-Subjects Effects
>
>
>
>
> Dependent Variable:C Mean
>
>
>
>
> Source Type III Sum of Squares df Mean Square F Sig. Corrected Model
> 2.719E+08 16 1.700E+07 7.109 .000 Intercept 2.394E+07 1 2.394E+07 10.012
> .003 Meanrichness 4.979E+07 1 4.979E+07 20.827 .000 Diversity 3.581E+07
> 1 3.581E+07 14.978 .001 Zoop 1.079E+07 1 1.079E+07 4.515 .042 Diversity
> * Zoop 261789.172 1 261789.172 .110 .743 Phyto(Diversity) 1.186E+08 6
> 1.976E+07 8.265 .000 Phyto * Zoop(Diversity) 6.171E+07 6 1.029E+07 4.302
> .003 Error 7.411E+07 31 2.391E+06
>
> Total 7.959E+08 48
>
>
> Corrected Total 3.460E+08 47
>
>
>
>
> Which, gives some similar results, but a completely different F statistic
> and P-value for the main effect of Zoop and the nested effect of Phyto.
> Obviously SPSS is not necessarily the perfect reference, but when using the
> Type I SS, the results did agree. Any thoughts on why this might be? Could
> the two programs be calculating the Type III SS differently? Might it be
> wise to stick to Type I SS?
>
> Thanks very much for your time and effort. It has been very helpful.
> Anita.
>
>
> On Thu, Jun 3, 2010 at 4:25 PM, Joris Meys <jorismeys_at_gmail.com> wrote:
>
>> I see where my confusion comes from. I counted 4 levels of Phyto, but
>> you have 8, being 4 in every level of Diversity. There's your
>> aliasing.
>>
>> > table(Diversity,Phyto)
>> Phyto
>> Diversity M1 M2 M3 M4 P1 P2 P3 P4
>> H 0 0 0 0 6 6 6 6
>> L 6 6 6 6 0 0 0 0
>>
>> There's no need to code them differently for every level of Diversity.
>> If you don't, all is fine :
>>
>> > Phyto <- gsub("M","P",as.character(Phyto))
>> > Phyto <- as.factor(Phyto)
>> >
>> > test <- lm(C.Mean~ Mean.richness + Diversity + Zoop + Diversity/Phyto +
>> + Zoop*Diversity/Phyto)
>> >
>> > Anova(test,type="III")
>> Anova Table (Type III tests)
>>
>> Response: C.Mean
>> Sum Sq Df F value Pr(>F)
>> (Intercept) 23935609 1 10.0121 0.0034729 **
>> Mean.richness 49790385 1 20.8269 7.471e-05 ***
>> Diversity 35807205 1 14.9779 0.0005234 ***
>> Zoop 10794614 1 4.5153 0.0416688 *
>> Diversity:Phyto 118553464 6 8.2650 2.184e-05 ***
>> Diversity:Zoop 261789 1 0.1095 0.7429356
>> Diversity:Zoop:Phyto 61710162 6 4.3021 0.0028790 **
>> Residuals 74110938 31
>> ---
>> Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
>> >
>>
>> You can check with summary(test) that the model is fitted correctly.
>>
>> On Fri, Jun 4, 2010 at 12:48 AM, Anita Narwani <anitanarwani_at_gmail.com>
>> wrote:
>> >
>> > You have everything right except that there are only 2 zooplankton
>> species (C & D, which stand for Ceriodaphnia and Daphnia).
>> >
>>
>
>

-- 
Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Joris.Meys_at_Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

	[[alternative HTML version deleted]]


______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

Received on Fri 04 Jun 2010 - 00:25:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 Jun 2010 - 00:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive