[R] glht() and contrast() comparison

array chip arrayprofile at yahoo.com
Sat Jan 12 00:04:00 CET 2008


Hi, I have been trying glht() from multcomp package
and contrast() from contrast package to test a
contrast that I am interested in. 

With the following simulated dataset (fixed effect
"type" with 3 levels (b, m, t), and random effect
"batch" of 4 levels, a randomized block design with
interaction), sometimes both glht() and contrast()
worked and gave nearly the same p values; other times,
glht()worked, but contrast() didn't and gave the error
message: 
"Error in dimnames(X) <- list(dn[[1L]],
unlist(collabs, use.names = FALSE)) : length of
'dimnames' [2] not equal to array extent". 

so apparently, the error message from contrast() is
data dependent. glht() always worked.

Here is the code, I just copy and paste in R
repeatedly:

batch<-as.factor(rep(1:4,3,each=20))
type<-as.factor(rep(c('b','m','t'),each=80))
y<-2*(type=='m')+4*(type=='t')+rnorm(240,100,20)
dat<-cbind(as.data.frame(y),type=type,batch=batch)
rm(batch,type,y)

library(nlme)
dat.lme<-lme(y~type, random=~1|batch/type, data=dat)

library(multcomp)
summary(glht(dat.lme, linfct = mcp(type
=c("b+t-2*m=0"))),test=Chisqtest())

library(contrast)
contrast(dat.lme, a=list(type=c('b','t')),
            b=list(type='m'),type='average')

Does anybody have a clue?

Thanks,

John


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.




More information about the R-help mailing list