I meant to chime-in on this a couple of days ago. It seems to me you are going to have trouble getting what you want with the model you have fitted. Instead, fit a model that has the interaction explicitly so that the effects package (or whatever you use) can tell you want to look at an interaction. That is, fit a model of the form



      model2 <- glmer(dep.var ~ var1 + var2 + ? + time + var1:time + (1 | reff), ...)



If var1 and var2 are both numeric predictors, then I think the effects package probably offers what you want. However, I think you have var1 as a factor (you say a dichotomous variable). If you coded this as a dummy variable (0 or 1), then again you'll have better luck changing it to a factor, e.g.



        model3<- glmer(dep.var ~ factor(var1)*time + var2 + ? + (1 | reff), ...)



In that case, the lsmeans package might prove handy, as it has an lstrends function that can estimate and compare the time trends for the two levels of var1:



    library(lsmeans)

    lstrends(model3, "var1", "time")

    pairs(.Last.value)  ### For comparing the slopes



Hope this helps.



Russ

Russell V. Lenth  -  Professor Emeritus
Department of Statistics and Actuarial Science
The University of Iowa  -  Iowa City, IA 52242  USA
Voice (319)335-0712 (Dept. office)  -  FAX (319)335-3017




Message: 1

Date: Thu, 10 Jul 2014 11:46:06 +0100

From: Richard Zijdeman <richard.zijdeman@gmail.com<mailto:richard.zijdeman@gmail.com>>

To: r-sig-mixed-models@r-project.org<mailto:r-sig-mixed-models@r-project.org>

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

Message-ID: <56910434-600C-4ECB-B339-F3079F3DC193@gmail.com<mailto:56910434-600C-4ECB-B339-F3079F3DC193@gmail.com>>

Content-Type: text/plain; charset=windows-1252



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

	[[alternative HTML version deleted]]

