1
$\begingroup$

I have a statistical analysis / data analysis problem:

I am analyzing data using a factorial three-way ANOVA with a-priori contrasts and type III sums of squares. (Please don't speak about type I SS vs. type III SS. That's not the point of my question.) I get the contrasts like I need using summary.aov(), however that uses type I SS. When I use the Anova() function from library(car) to get type III SS, I don't get the contrasts. Why don't I get contrasts?

I have also tried using drop1() with the lm() model, but I get the same results as Anova() (without the contrasts). I have also tried the following, all without a resolution to my issue: ezANOVA() from library(ez), glht() from library(multcomp) which returned the error Error in glht.matrix(EpiLM, linfct = con) : ‘ncol(linfct)’ is not equal to ‘length(coef(model))’, and C(). Why do I get this error? How do I resolve this error? I have searched extensively online for answers to this error message as well as this issue generally, but without finding a solution.

How do I get the results of a factorial ANOVA with a-priori contrasts and type III SS as shown in my example code below?

Sample data:

DF <- structure(list(Code = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L,  
3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 9L, 9L, 
9L, 10L, 10L, 10L, 11L, 11L, 11L, 12L, 12L, 12L), .Label = c("A", 
"B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"), class = 
"factor"), GzrTreat = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,  2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), contrasts = structure(c(1, 
-2, 1, 1, 0, -1), .Dim = c(3L, 2L), .Dimnames = list(c("I", 
"N", "R"), NULL)), .Label = c("I", "N", "R"), class = "factor"), 
BugTreat = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = 
c("Immigration", "Initial", "None"), class = "factor"), TempTreat =   
structure(c(2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 
1L, 1L, 1L, 1L, 1L), .Label = c("Not Warm", "Warmed"), class = 
"factor"), ShadeTreat = structure(c(2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 
2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 
1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L), .Label = c("Light", 
"Shaded"), class = "factor"), EpiChla = c(0.268482353, 0.423119608, 
0.579507843, 0.738839216, 0.727856863, 0.523960784, 0.405801961, 
0.335964706, 0.584441176, 0.557543137, 0.436456863, 0.563909804, 
0.432398039, 0.344956863, 0.340309804, 0.992884314, 0.938390196, 
0.663270588, 0.239833333, 0.62875098, 0.466011765, 0.536182353, 
0.340309804, 0.721172549, 0.752082353, 0.269372549, 0.198180392, 
1.298882353, 0.298354902, 0.913139216, 0.846129412, 0.922317647, 
0.727033333, 1.187662745, 0.35622549, 0.073547059), log_EpiChla = 
c(0.10328443, 0.153241402, 0.198521787, 0.240259426, 0.237507762, 
0.182973791, 0.147924145, 0.125794985, 0.19987612, 0.192440084, 
0.157292589, 0.194211702, 0.156063718, 0.128708355, 0.127205194, 
0.299482089, 0.287441205, 0.220962908, 0.093363308, 0.21185469, 
0.166137456, 0.186442772, 0.127205194, 0.235824411, 0.243554515, 
0.103589102, 0.078522208, 0.361516746, 0.113393422, 0.281746574, 
0.266262141, 0.283825153, 0.23730072, 0.339980371, 0.132331903, 
0.030821087), MeanZGrowthAFDM_g = c(0.00665, 0.003966667, 0.004466667, 
0.01705, 0.0139, 0.0129, 0.0081, 0.003833333, 0.00575, 0.011266667, 
0.0103, 0.009, 0.0052, 0.00595, 0.0105, 0.0091, 0.00905, 0.0045, 0.0031, 
0.006466667, 0.0053, 0.009766667, 0.0181, 0.00725, 0, 0.0012, 5e-04, 
0.0076, 0.00615, 0.0814, NA, 0.0038, 0.00165, 0.0046, 0, 0.0015)), 
.Names = c("Code", "GzrTreat", "BugTreat", "TempTreat", "ShadeTreat", 
"EpiChla", "log_EpiChla", "MeanZGrowthAFDM_g"), class = "data.frame", 
row.names = c(NA, -36L))

Code:

## a-priori contrasts
library(stats)
contrasts(DF$GzrTreat) <- cbind(c(1,-2,1), c(1,0,-1))
    round(crossprod(contrasts(DF$GzrTreat)))
c_labels <- list(GzrTreat=list('presence'=1, 'immigration'=2))

## model  
library(car)
EpiLM <- lm(log_EpiChla~TempTreat*GzrTreat*ShadeTreat, DF)
summary.aov(EpiLM, split=c_labels) ### MUST USE summary.aov(), to get 
#contrast results, but sadly this uses Type I SS
Anova(EpiLM, split=c_labels, type="III") # Uses Type III SS, but NO     
#CONTRASTS!!!!!

# I need contrast results like from summary.aov(), AND Type III SS 
# like from Anova()
$\endgroup$
3
  • $\begingroup$ If your question is purely searching for an R function, you might like to try the resources available at some of the support links we maintain. $\endgroup$
    – Glen_b
    Commented Jun 6, 2015 at 1:00
  • $\begingroup$ Thanks for the suggestion, but I've already posted to R-help and Stack Overflow. No solution yet, hence my post here. $\endgroup$ Commented Jun 10, 2015 at 22:15
  • $\begingroup$ Although some of these error messages obviously are specific to R packages (they are not being given the data structures they expect), I think the careful exploration of alternative codes, all of which produce errors, is testimony to the possibility of some underlying purely statistical problem that is independent of any computing platform. If that is correct, then answers might either explain why Type III SS do not make sense for these data or else they would show formulas or algorithms for their computation--and all of that seems on topic here. $\endgroup$
    – whuber
    Commented Jun 10, 2015 at 22:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.