[R] type III sums of squares in R

John Fox jfox at mcmaster.ca
Thu Nov 24 18:57:23 CET 2005


Dear Stefanie and Mike,

To elaborate slightly on Mike's points, the Anova() function in car
calculates "Type-III" (and "Type-II") tests differently from SAS. (The
difference originates in the fact that SAS uses a deficient-rank
parametrization of the model while R uses a full-rank parametrization; it
would be possible to mimic SAS's behaviour more closely, but I think that
there are problems with it.) As a consequence, you have to use a
contrast-generating function, such as contr.helmert or contr.sum (but not
contr.SAS), that provides contrasts that are orthogonal in the row-basis of
the model matrix. 

I should probably elaborate the warning about "Type-III" tests in the help
page for Anova(), but perhaps it would help to know that the issue is
discussed at greater length in the book with which the car package is
associated.

I hope this helps,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
-------------------------------- 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Mike Sears
> Sent: Thursday, November 24, 2005 1:54 PM
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] type III sums of squares in R
> 
> If you use the Anova function in the car package and specify 
> contr.sum or contr.SAS for the contrasts for your categorical 
> factors, you will get the same results as outputted by SAS. 
> I've tried this with a variety of data sets and it works.
> 
> On Thu November 24 2005 08:27, Stefanie von Felten, IPW&IfU wrote:
> > Hi everyone,
> >
> > Can someone explain me how to calculate SAS type III sums 
> of squares 
> > in R? Not that I would like to use them, I know they are 
> problematic. 
> > I would like to know how to calculate them in order to demonstrate 
> > that strange things happen when you use them (for a course for 
> > example). I know you can use drop1(lm(), test="F") but for an 
> > lm(y~A+B+A:B), type III SSQs are only calculated for the A:B 
> > interaction. If I specify lm(y~A+B), it calculates type II 
> SSQ for the 
> > main effects (as type III only differs from type II if interactions 
> > are included). Thus, this approach doesn't help.
> >
> > Another approach is the Anova(, type="III") function within the 
> > library(car). But somehow it produces strange results. 
> Somebody told 
> > me I have to change the contrast settings using 
> > options(contrasts=c("contr.helmert", "contr.poly"))  But I had the 
> > impression that my results are still impossible.
> > Are the calculations dependent from the version of R I use? I am 
> > currently using R2.1.1
> >
> > The only thing that seems to work is a trick: Specify a separate 
> > column AB that codes a new variable for the interaction of A:B. Now 
> > you can fit A,B, and AB (as 3 main effects) in 3 different 
> sequential 
> > models with each one of them in the end once. For the term 
> in the end 
> > you then get type III SSQ which seem to be correct.
> >
> > Cheers
> > Steffi
> 
> --
> Michael W. Sears, Ph.D.
> Postdoctoral Fellow
> Department of Biology/MS 314
> University of Nevada, Reno
> Reno, NV 89557
> 
> Assistant Professor
> Department of Zoology
> Southern Illinois University
> Carbondale, IL 62901
> 
> phone: 775.784.8008
> cell:  775.232.3520
> web:    http://www.unr.edu/homepage/msears
>         http://www.science.siu.edu/zoology/sears
> 
> "Natural selection is a mechanism for generating
>  an exceedingly high degree of improbability."
>                         -Sir Ronald Fisher (1890-1962)
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list