[R-sig-ME] contrast sum with interaction
b|mono@om @end|ng |rom gm@||@com
Sun Jul 18 17:09:37 CEST 2021
"The situation is that I want a categorical variable that is coded with a
sum constraint but only included in some rows "
Almost sounds like you could also simply delete all cont=0 rows... But I
assume you want something like this?
model.matrix(y~ cont.var+cont.var:disc.var ,data=dat,contrasts.arg =
If you dont want to have the "cont.var0:disc.var1" column in this matrix,
then all you need is a numeric (nonfactor) "dummy variable" in the data
which you then can multiply with the interaction in the actual model
glmr(y~ cont.var+cont.var:disc.var*dummy ...)
As dummy is continuous it will always set the interaction term to 0 if
cont=0; this means if cont=0 there will only be an intercept estimate which
then is the effective mean of both a & b together (if cont=0). Not sure you
Hope this helps.
Am Do., 15. Juli 2021 um 20:44 Uhr schrieb Mark Sorel <marks6 using uw.edu>:
> 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:
> model.matrix(y~ cont.var : disc.var ,data=dat,contrasts.arg =
> 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
> Mark Sorel
> Doctoral Student
> Washington Cooperative Fish and Wildlife Research Unit
> School of Aquatic and Fishery Sciences
> University of Washington
> Cell: 607-351-7352
> He/ him/ his
> *The University of Washington acknowledges the Coast Salish peoples of this
> land, the land which touches the shared waters of all tribes and bands
> within the Suquamish, Tulalip and Muckleshoot nations*.
> [[alternative HTML version deleted]]
> R-sig-mixed-models using r-project.org mailing list
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models