[R-sig-eco] plotting models with confidence bands from glmer
Hi all, I'm wondering if someone can help me figure out how to produce plots of model fits that include 95% CI bands for a generalized linear mixed model. I'm using glmer in lme4 to run essentially an ANCOVA to investigate a three-way interaction between one categorical variable (3 different species) and 2 continuous variables to investigate survival probability (0 or 1) of trees. I've found a 3-way interaction between these variables. I have produced a stacked graph showing how the survival probabilities for different species (3 different lines) vary across a gradient of one of the variable and at 2 levels of one of the other variables (shown by 2 panels). I used the parameter estimates to produce the predicted models as line graphs, but I'd like to add a confidence band around the models. I've been looking in Zuur et al's Mixed effects models and extensions in ecology in R, but wonder if someone has a trick to doing this. Thanks for any insights! Travis Travis Belote, Ph.D. Research Ecologist The Wilderness Society | Northern Rockies Regional Office 503 W. Mendenhall, Bozeman, MT 59715 office: 406.586.1600 x110 | cell: 406.581.3808 ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] plotting models with confidence bands from glmer
Travis: I wonder if you can modify the example from predict.lm to do something comparable (saw this posting recently) with mixed effects models from glmer(). ?predict.lm Offers this example, which seems to meet the request x - rnorm(15) y - x + rnorm(15) predict(lm(y ~ x)) new - data.frame(x = seq(-3, 3, 0.5)) predict(lm(y ~ x), new, se.fit = TRUE) pred.w.plim - predict(lm(y ~ x), new, interval = prediction) pred.w.clim - predict(lm(y ~ x), new, interval = confidence) matplot(new$x, cbind(pred.w.clim, pred.w.plim[,-1]), lty = c(1,2,2,3,3), type = l, ylab = predicted y) Brian Brian S. Cade, PhD U. S. Geological Survey Fort Collins Science Center 2150 Centre Ave., Bldg. C Fort Collins, CO 80526-8818 email: ca...@usgs.gov brian_c...@usgs.gov tel: 970 226-9326 On Thu, Feb 27, 2014 at 12:48 PM, Travis Belote travis_bel...@tws.orgwrote: Hi all, I'm wondering if someone can help me figure out how to produce plots of model fits that include 95% CI bands for a generalized linear mixed model. I'm using glmer in lme4 to run essentially an ANCOVA to investigate a three-way interaction between one categorical variable (3 different species) and 2 continuous variables to investigate survival probability (0 or 1) of trees. I've found a 3-way interaction between these variables. I have produced a stacked graph showing how the survival probabilities for different species (3 different lines) vary across a gradient of one of the variable and at 2 levels of one of the other variables (shown by 2 panels). I used the parameter estimates to produce the predicted models as line graphs, but I'd like to add a confidence band around the models. I've been looking in Zuur et al's Mixed effects models and extensions in ecology in R, but wonder if someone has a trick to doing this. Thanks for any insights! Travis Travis Belote, Ph.D. Research Ecologist The Wilderness Society | Northern Rockies Regional Office 503 W. Mendenhall, Bozeman, MT 59715 office: 406.586.1600 x110 | cell: 406.581.3808 ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology [[alternative HTML version deleted]] ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] plotting models with confidence bands from glmer
As with a GLM, I wouldn't expect there to be a difference between prediction and confidence intervals for a GLMM. Also, and related, the `interval` argument is particular to the `lm` method of `predict`. Ben Bolker has an example for a particular lme4 model on his GLMM wiki FAQ. Go to http://glmm.wikidot.com/faq and find the section Predictions and/or confidence (or prediction) intervals on predictions Another way that spring to mind would be to simulate from the posterior distribution of the model parameters, but again, this would require doing it by hand as to the best of my knowledge there is no function in lem4 for this. HTH Gavin On 27 February 2014 14:17, Cade, Brian ca...@usgs.gov wrote: Travis: I wonder if you can modify the example from predict.lm to do something comparable (saw this posting recently) with mixed effects models from glmer(). ?predict.lm Offers this example, which seems to meet the request x - rnorm(15) y - x + rnorm(15) predict(lm(y ~ x)) new - data.frame(x = seq(-3, 3, 0.5)) predict(lm(y ~ x), new, se.fit = TRUE) pred.w.plim - predict(lm(y ~ x), new, interval = prediction) pred.w.clim - predict(lm(y ~ x), new, interval = confidence) matplot(new$x, cbind(pred.w.clim, pred.w.plim[,-1]), lty = c(1,2,2,3,3), type = l, ylab = predicted y) Brian Brian S. Cade, PhD U. S. Geological Survey Fort Collins Science Center 2150 Centre Ave., Bldg. C Fort Collins, CO 80526-8818 email: ca...@usgs.gov brian_c...@usgs.gov tel: 970 226-9326 On Thu, Feb 27, 2014 at 12:48 PM, Travis Belote travis_bel...@tws.orgwrote: Hi all, I'm wondering if someone can help me figure out how to produce plots of model fits that include 95% CI bands for a generalized linear mixed model. I'm using glmer in lme4 to run essentially an ANCOVA to investigate a three-way interaction between one categorical variable (3 different species) and 2 continuous variables to investigate survival probability (0 or 1) of trees. I've found a 3-way interaction between these variables. I have produced a stacked graph showing how the survival probabilities for different species (3 different lines) vary across a gradient of one of the variable and at 2 levels of one of the other variables (shown by 2 panels). I used the parameter estimates to produce the predicted models as line graphs, but I'd like to add a confidence band around the models. I've been looking in Zuur et al's Mixed effects models and extensions in ecology in R, but wonder if someone has a trick to doing this. Thanks for any insights! Travis Travis Belote, Ph.D. Research Ecologist The Wilderness Society | Northern Rockies Regional Office 503 W. Mendenhall, Bozeman, MT 59715 office: 406.586.1600 x110 | cell: 406.581.3808 ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology [[alternative HTML version deleted]] ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology -- Gavin Simpson, PhD ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology