[R] type III sums of squares in R
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Thu Nov 24 17:53:12 CET 2005
"Stefanie von Felten, IPW&IfU" <sfelten at uwinst.unizh.ch> writes:
> 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.
I think you need to qualify "correct", "strange", and "impossible"...
In particular, since you're hinting at a bug in "car", I'm sure its
author would like to know what it is you think is wrong.
Also, in the "trick" you don't specify *how* you code the three terms.
I don't think it is immaterial, and I'm not sure which of the possible
versions (if any) matches up with e.g. SAS's version of type III for
main effects in the presence of interaction.
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list