# NOT RUN {
# Load example data
data(shipley2009)
# Load model packages
library(lme4)
library(nlme)
# Create list of models
shipley2009.modlist = list(
lme(DD ~ lat, random = ~1|site/tree, na.action = na.omit,
data = shipley2009),
lme(Date ~ DD, random = ~1|site/tree, na.action = na.omit,
data = shipley2009),
lme(Growth ~ Date, random = ~1|site/tree, na.action = na.omit,
data = shipley2009),
glmer(Live ~ Growth+(1|site)+(1|tree),
family=binomial(link = "logit"), data = shipley2009)
)
# Create new data for predictions
shipley2009.new = data.frame(
DD = seq(min(shipley2009$DD, na.rm = TRUE),
max(shipley2009$DD, na.rm = TRUE),
by = 0.01)
)
# Generate predictions
shipley2009.new.pred = sem.predict(shipley2009.modlist, shipley2009.new)
head(shipley2009.new.pred)
# Plot predicted fit
plot(shipley2009$Date ~ shipley2009$DD, col = "grey60")
lines(shipley2009.new.pred$Date.fit ~ shipley2009.new.pred$DD, lwd = 2, col = "red")
# Generate predictions with standard errors (based on fixed effects only)
shipley2009.new.pred = sem.predict(shipley2009.modlist, shipley2009.new, sefit = TRUE)
# Add 95 percent confidence intervals
lines(shipley2009.new.pred$DD,
shipley2009.new.pred$Date.fit + 2 * shipley2009.new.pred$Date.se.fit,
lwd = 1.5, lty = 2, col = "red")
lines(shipley2009.new.pred$DD,
shipley2009.new.pred$Date.fit - 2 * shipley2009.new.pred$Date.se.fit,
lwd = 1.5, lty = 2, col = "red")
# }
Run the code above in your browser using DataLab