I am attempting my first efforts at nonlinear mixed effect modeling for experimental data using the R package lme4. The model predicts Choice (binary 0/1) data using two independent variables that change on each trial, across two conditions, nested in the random effects of each participant (SubjectID). I have provided a more concrete example below. I have within-subjects design with repeated measures, in each of two conditions.

Ultimately, I'm interested in how to compare the relative predictive power of each independent variables across conditions.

For example, we have participants who must choose which product to buy between a stock product used as a comparison in every trial, and a new product with varying Size and Time of Assembly. BuyNew (both independent variables are continuous where Size positively predicts buying the new product and Time of Assembly negatively predicts buying the new product). These products are repeatedly shown to the same individual with different Brand-labeling (a manipulated condition with 2 levels). The glmer function for the full model would look like the following:

ME.model <- glmer(formula = BuyNew ~ Size*AssemblyTime + Brand + (1| SubjectID), family = “binomial”, data = .)

Let’s assume Brand is a significant predictor of Buy and there are many Brands. I would like to compare the betas for Size, AssemblyTime, and Size:AssemblyTime to see how they vary depending on the Brand. The emphasis is on how the relationships change, rather than the presence/absence of an interaction effect.

To do this, I might split the data by Brand to make separate models for each Brand and compare the betas, but if I do this, can I hold the random effects the same for all models (force them to use the ranef() from the initial model)? Is there a better way to compare the betas between Brands?

Another idea is to create independent variables for each Brand (when present) and 0 when the new product does not have that particular brand:

glmer(formula = Buy ~ Sizeb1*AssemblyTimeb1 + Sizeb2*AssemblyTimeb2 +...  Sizebj*AssemblyTimebj + (1| SubjectID), data = ., family =“binomial”)

Where bj refers to the Size and AssemblyTime of a product when it has a particular Brand(j) and 0 otherwise. This seems less elegant/formal because it involves creating several variables that are highly correlated, but would be able to compare the overall beta-sizes between conditions.

Thanks in advance for the help!


I would like to compare the betas for Size, AssemblyTime, and Size:AssemblyTime to see how they vary depending on the Brand.

A three-way interaction with Size, AssemblyTime and Brand will give you the possiblitiy to see how the effect of Size varies with AssemblyTime and Brand, and how the effect of AssemblyTime varies with Size and Brand.

Note that care must be taken when interpreting the estimates of the fitted model, since they do not have their usual meanings anymore. E.g. the beta for certain level of Brand represents the effect of that level (in comparison to the reference level) when Size and AssemblyTime is zero.

I recommmend the package effects to visualize the results.

All this has really nothing to do with mixed-models, it's plain old multiple regression analysis. Sure, thanks to lme4 we can apply due control for the non-indepence of the repated measure design, but my advice would be just as applicable without that design.

With lme4 the model would be

fm <- glmer(BuyNew ~ Size*AssemblyTime*Brand + (1 | SubjectID), data = ., family = binomial)

To analyse the fitted model with the effects package, try:

my.eff <- Effect(c("Size", "AssemblyTime", "Brand"), fm)

To extract the values used in the plots, use


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.