PredictGLMER: Predicted values for GLMERs

View source: R/PredictGLMER.R

PredictGLMERR Documentation

Predicted values for GLMERs

Description

Generates predicted values from a generalized linear mixed-effects model and a data frame with values of the explanatory variables

Usage

PredictGLMER(model,data,se.fit=FALSE,seMultiplier = 1.96)

Arguments

model

A mixed-effects model, of class 'lmerMod' or 'glmerMod'

data

A data frame containing values of the explanatory variables for which to make predictions

se.fit

Whether to estimate uncertainty around the predictions (default is False)

seMultiplier

The multiplier to apply to the uncertainty estimates (default is 1.96, which generates 95

Details

Code for calculating predicted values and confidence intervals was taken from the GLMM wiki (see references).

Value

A data frame either containing a single column 'y', when uncertainty is not calculated, or 3 columns ('y', 'yplus' and 'yminus'), when uncertainty is calculated

Author(s)

Tim Newbold <t.newbold@ucl.ac.uk>

References

http://glmm.wikidot.com/faq

Examples

# Load example data (site-level effects of land use on biodiversity from the PREDICTS database)
data(PREDICTSSiteData)

# Run a model of species richness as a function of land use, human population density
# and distance to nearest road (with an interaction between human population density
# and road distance)
m1 <- GLMER(modelData = PREDICTSSites,responseVar = "Species_richness",fitFamily = "poisson",
fixedStruct = "LandUse",randomStruct = "(1|SS)+(1|SSB)+(1|SSBS)",REML = TRUE)

predDat <- data.frame(LandUse=factor(c("Primary Vegetation","Secondary Vegetation",
"Plantation forest","Cropland","Pasture","Urban"),levels=levels(m1$data$LandUse)),
Species_richness=0)

# Generate predicted values for each land use, with uncertainty of 1 standard error
# about the predicted mean values
preds <- PredictGLMER(preds <- PredictGLMER(model = m1$model,data = predDat,
se.fit = TRUE,seMultiplier = 1))

timnewbold/StatisticalModels documentation built on Aug. 25, 2023, 4:58 p.m.