Dear R community
I currently try to get post hoc multiple comparisons with the package
multcomp from a cox mixed-effects model, where the survival is explained
by two variables (cover with levels: nocover and cover; treatment with
levels: tx, uv, meta), whose interaction is significant.
I read Hothorn, T. 2011: Additional multcomp Examples and there is an
example involving a two-way ANOVA with significant interaction. Using
this guideline I wanted to compare the levels of treatment in my data
within the levels of cover.
My model is as follows:
m.lapf<-coxme(Surv(day,status)~cover*treatment+(1|r.brood)+(1|r.worker)+(1|species/brood),data=removal.lapf)
First I constructed a contrast matrix based on Tukey-contrasts as follows:
Tukey<-contrMat(table(removal.lapf$treatment), "Tukey")
Tukey
K1<-cbind(Tukey,matrix(0,nrow=nrow(Tukey),ncol=ncol(Tukey)))
K1
rownames(K1)<-paste(levels(removal.lapf$cover)[1],rownames(K1),sep=":")
K1
K2<-cbind(matrix(0,nrow=nrow(Tukey),ncol=ncol(Tukey)),Tukey)
K2
rownames(K2)<-paste(levels(removal.lapf$cover)[2],rownames(K1),sep=":")
K2
K<-rbind(K1,K2)
colnames(K)<-c(colnames(Tukey),colnames(Tukey))
K
This gives the following matrix
meta tx uv meta tx uv
cocooned:tx - meta -1 1 0 0 0 0
cocooned:uv - meta -1 0 1 0 0 0
cocooned:uv - tx 0 -1 1 0 0 0
naked:cocooned:tx - meta 0 0 0 -1 1 0
naked:cocooned:uv - meta 0 0 0 -1 0 1
naked:cocooned:uv - tx 0 0 0 0 -1 1
then I constructed a secon matrix
tmp<-expand.grid(treatment=unique(removal.lapf$treatment),cover=unique(removal.lapf$cover))
X<-model.matrix(~cover*treatment,data=tmp)
X
which gives the following
(Intercept) covernaked treatmenttx treatmentuv covernaked:treatmenttx
covernaked:treatmentuv
1 1 1 1 0
1 0
2 1 1 0 1
0 1
3 1 1 0 0
0 0
4 1 0 1 0
0 0
5 1 0 0 1
0 0
6 1 0 0 0
0 0
attr(,"assign")
[1] 0 1 2 2 3 3
attr(,"contrasts")
attr(,"contrasts")$cover
[1] "contr.treatment"
attr(,"contrasts")$treatment
[1] "contr.treatment"
however when performing the tests via
summary(glht(m.lapf,linfct=K%*%X))
I get the following error message
Error in summary(glht(m.lapf, linfct = K %*% X)) :
error in evaluating the argument 'object' in selecting a method for
function 'summary': Error in glht.matrix(m.lapf, linfct = K %*% X) :
'ncol(linfct)' is not equal to 'length(coef(model))'
Performing exactly the same routine with the same data on a logistic
model with family=binomial does not give this error message.
So my question is, what am I missing here?
Thanks, for any possible input
--
Simon Tragust
Animal Ecology I
University Bayreuth
D-95440 Bayreuth
+49 921 552464
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.