Skip to content
Prev 19402 / 20628 Next

contrast sum with interaction

Not specifically a glmmTMB question, but maybe someone here can help.
I'd like to use a contrast sum constraint with an interaction between a
continuous and discrete variable, but I can't seem to get model.matrix to
do what I want.

The situation is that I want a categorical variable that is coded with a
sum constraint but only included in some rows of the model matrix (which is
why I am using the interaction with the continuous 0/1 valued variable).
Maybe there is a better way to code this.

Here is an example of what I mean:

dat<-data.frame(y=1,cont.var=rep(0:1,each=2),disc.var=rep(c("a","b"),2));
model.matrix(y~ cont.var  : disc.var  ,data=dat,contrasts.arg =
list(disc.var="contr.sum"))

What I'd like in this example is a model matrix with two columns, where the
second column has 0 when cont.var =0, 1 when cont.var=1 & disc.var = a, and
-1 when cont.var=1 and disc.var=b.



Thanks so much for your help! -Mark