title: Visualising GLMM predictions with interaction of categorical and continuous variables
body: <p>I am working in R with a GLMM with a mixture of continuous and categorical variables with some interactions. I have used the dredge and model.avg functions in MuMIn to obtain effect estimates for each variable. My problem is in how best to plot the results. I want to make a figure showing the effect of one variable (forest) on my data where the trendline reflects the forest parameter estimate, but I can't figure out how to hold the categorical variables and interaction variables at their 'average' so that the trendline only reflects the effect of forest.</p>
  
  <p>Here's the model and plot set-up:</p>
  
  <pre><code>#load packages and document
  cuckoo&lt;-read.table("http://www.acsu.buffalo.edu/~ciaranwi/home_range.txt", 
  header=T,sep="\t")
  require(lme4)
  require(MuMIn)
  as.factor (cuckoo$ID)
  as.factor (cuckoo$Sex)
  as.factor(cuckoo$MS_bin)
  options(na.action = "na.fail")
  
  # create global model and fit
  fm&lt;- lmer(log(KD_95)~ MS_bin + Forest + NDVI + Sex + Precip + MS_bin*Forest 
  + MS_bin*NDVI  + MS_bin*Sex + MS_bin*Precip + Argos + Sample + (1|ID), data 
  = cuckoo, REML = FALSE)
  
  # dredge but always include argos and sample
  KD95&lt;-dredge(fm,fixed=c("Argos","Sample"))
  
  # model averaging 
  avgmod&lt;-model.avg(KD95, fit=TRUE)
  summary(avgmod)
  
  #plot data
  plot(cuckoo$Forest, (log(cuckoo$KD_95)),
   xlab = "Mean percentage of forest cover",
   ylab = expression(paste(plain("Log of Kernel density estimate, 95%    
  utilisation, km"^{2}))),
   pch = c(15,17)[as.numeric(cuckoo$MS_bin)],  
   main = "Forest cover",
   col="black", 
   ylim=c(14,23))
  legend(80,22, c("Breeding","Nonbreeding"), pch=c(15, 17),  cex=0.7)
  </code></pre>
  
  <p>Then I get stuck with how to include a trendline. So far I have:</p>
  
  <pre><code>#parameter estimates from model.avg
  argos_est&lt;- -1.6
  MS_est&lt;- -1.77
  samp_est&lt;-0.01
  forest_est&lt;--0.02
  sex_est&lt;-0.0653
  precip_est&lt;-0.0004
  ndvi_est&lt;--0.00003
  model_intercept&lt;-22.7
  
  #calculate mean values for parameters
  argos_mean&lt;-mean(cuckoo$Argos)
  samp_mean&lt;-mean(cuckoo$Sample)
  forest_mean&lt;-mean(cuckoo$Forest)
  ndvi_mean&lt;-mean(cuckoo$NDVI)
  precip_mean&lt;-mean(cuckoo$Precip)
  
  #calculate the intercept and add trend line
  intercept&lt;-(model_intercept + (forest_est*cuckoo$Forest) +    
  (argos_est*argos_mean) + (samp_est * samp_mean) + (ndvi_est*ndvi_mean) +  
  (precip_est*precip_mean) )
  
  abline(intercept, forest_est)
  </code></pre>
  
  <p>But this doesn't consider the interactions or the categorical variables and the intercept looks way too high. Any ideas?</p>