Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I'm analyzing data from an unbalanced factorial experiment both with SAS and R. Both SAS and R provide similar Type I sum of squares but their Type III sum of squares are different from each other. Below are SAS and R codes and outputs.

DATA ASD;
INPUT Y T B;
DATALINES;
 20 1 1
 25 1 2
 26 1 2
 22 1 3
 25 1 3
 25 1 3
 26 2 1
 27 2 1
 22 2 2
 31 2 3
;

PROC GLM DATA=ASD;
CLASS T B;
MODEL Y=T|B;
RUN;

Type I SS from SAS

Source  DF       Type I SS     Mean Square    F Value    Pr > F
T       1     17.06666667     17.06666667       9.75    0.0354
B       2     12.98000000      6.49000000       3.71    0.1227
T*B     2     47.85333333     23.92666667      13.67    0.0163

Type III SS from SAS

Source  DF     Type III SS     Mean Square    F Value    Pr > F
T       1     23.07692308     23.07692308      13.19    0.0221
B       2     31.05333333     15.52666667       8.87    0.0338
T*B     2     47.85333333     23.92666667      13.67    0.0163

R Code

Y <- c(20, 25, 26, 22, 25, 25, 26, 27, 22, 31)
T <- factor(x=rep(c(1, 2), times=c(6, 4)))
B <- factor(x=rep(c(1, 2, 3, 1, 2, 3), times=c(1, 2, 3, 2, 1, 1)))
Data <- data.frame(Y, T, B)
Data.lm <- lm(Y~T*B, data = Data)
anova(Data.lm)
drop1(Data.lm,~.,test="F") 

Type I SS from R

Analysis of Variance Table

Response: Y
          Df Sum Sq Mean Sq F value  Pr(>F)  
T          1 17.067  17.067  9.7524 0.03543 *
B          2 12.980   6.490  3.7086 0.12275  
T:B        2 47.853  23.927 13.6724 0.01629 *
Residuals  4  7.000   1.750                  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Type III SS from R

Single term deletions

Model:
Y ~ T * B
       Df Sum of Sq    RSS     AIC F value  Pr(>F)  
<none>               7.000  8.4333                  
T       1    28.167 35.167 22.5751 16.0952 0.01597 *
B       2    20.333 27.333 18.0552  5.8095 0.06559 .
T:B     2    47.853 54.853 25.0208 13.6724 0.01629 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Am I missing something here? If not which one is correct Type III ss. Thanks in advance for your help.

share|improve this question
See John Fox's response here: tolstoy.newcastle.edu.au/R/help/05/11/16368.html – Aaron Feb 20 '12 at 21:59

migrated from stackoverflow.com Feb 20 '12 at 22:09

1 Answer

up vote 15 down vote accepted

Type III SS depend on the parameterization used. If I set options(contrasts=c("contr.sum","contr.poly")) before running drop1(Data.lm,~.,test="F") I get exactly the same type III SS as SAS does. For the R-community dogma on this issue, you should read Venables' Exegeses on linear models ( http://www.stats.ox.ac.uk/pub/MASS3/Exegeses.pdf )

See also: How does one do a Type-III SS ANOVA in R with contrast codes?

share|improve this answer
Thanks for your help. It works fine. Thanks again. – MYaseen208 Feb 20 '12 at 22:16
Would this be the right place to put a contrasting view to the exegeses that @Ben links to? – Peter Flom Feb 20 '12 at 22:37
1  
@Peter If you think it can fit in a comment, why not. I don't think so, so why not asking a new question (and link to this one)? – chl Feb 20 '12 at 22:40
@chl My basic point is that main effects do have meaning in the presence of interactions - they are the effect when the other variable is 0. Often this is meaningful. Not sure it's worth a whole thread. – Peter Flom Feb 21 '12 at 0:20
I agree that there are situations where the main effects can be interpreted -- Venables takes a very strong line -- but there are lots of situations where they are difficult. I think "don't do this unless you know what you're doing" is a reasonable default setting ... – Ben Bolker Feb 21 '12 at 1:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.