I’m analyzing data from an unbalanced factorial experiment both with
SAS
andR
. BothSAS
andR
provide similar Type I sum of squares but their Type III sum of squares are different from each other. Below areSAS
andR
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?
Answer
Type III SS depend on the parameterization used. If I set
options(contrasts=c("contr.sum","contr.poly"))
before running lm()
and then drop1()
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.
See also: How does one do a Type-III SS ANOVA in R with contrast codes?
Attribution
Source : Link , Question Author : MYaseen208 , Answer Author : Community