[R-sig-ME] visualising interaction with predict.merMod

Henrik Singmann henrik.singmann at psychologie.uni-freiburg.de
Thu Jul 10 14:49:27 CEST 2014


Hi Richard,

did you already check out the effects package? This probably can do what you want. See the following example:


require(effects)
require(lme4)

gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
               data = cbpp, family = binomial)
plot(Effect("period", gm1), rescale.axis = FALSE, ylim = c(0, 1))

rescale.axis = FALSE here leads to the probability scale being equally spaced on the y-axis.

Otherwise you probably want to create a new data.frame using mean values for all other variables than the one you are interested in and with the values you want to plot for the variable you are interested in (and most likely ignoring the random effects for the first try). expand.grid is usually your friend for doing so. An example is given in the prediction section of: http://rpubs.com/bbolker/glmmchapter

Note however, that for factors you need to have all levels present and need to aggregate across them after having obtained the predictions.

Hope that helps,
Henrik

Am 10.07.2014 12:46, schrieb Richard Zijdeman:
> Dear all,
>
> I’ve fitted a model with the lme4 (version 1.1.7) package, using the glmer command. The only random component in the model is the intercept. The model contains an interaction with time and a dichotomous variable and I would like to visualise this interaction (the model actually contains more interactions and variables, but I don’t think this matters):
>
> model1 <- glmer(dep.var ~ var1 + var2 + … + time + var1_time + (1 | reff), data = data, family = binomial("logit”)) # where var1_time is the interaction
>
> To visualise the interaction, I think I would need to predict new values from the model. To do so, I have used the actual data, but I don’t think that’s right:
>
> pred.values <- predict(model1, type = "response")
>
> I think I should create a new dataset, in which all variables are held at constant value (e.g. the mean), except for, in this case the main effects of the interaction and the interaction.
>
> My questions are:
> - could someone please comment on my reflection (do I indeed need to create a new dataset)?
> - If I indeed would need to create such a new dataset, with average values, how would I do that (my model actually contains a lot of variables)?
>
> Thanks in advance,
>
> Richard
>

-- 
Dr. Henrik Singmann
Albert-Ludwigs-Universität Freiburg, Germany
http://www.psychologie.uni-freiburg.de/Members/singmann



More information about the R-sig-mixed-models mailing list