# 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)
)
# Return model fit statistics
rsquared(shipley2009.modlist)
# }
# NOT RUN {
# Get R2 for linear model
lm.mod = lm(DD ~ lat, data = shipley2009)
rsquared(lm.mod)
# Get R2 for generalized linear model
glm.mod = glm(Live ~ Growth, family = "binomial", data = shipley2009)
rsquared(glm.mod)
# Get R2 for generalized least-squares model
library(nlme)
gls.mod = gls(DD ~ lat, na.action = na.omit, data = shipley2009)
rsquared(gls.mod)
# Can supply the models as a list
# Use lm and gls -- should produce very similar R2s, will also produce delta AIC
rsquared(list(lm.mod, gls.mod))
# Get R2 for linear mixed effects model (nlme)
lme.mod = lme(DD ~ lat, random = ~1|site/tree, na.action = na.omit, data = shipley2009)
rsquared(lme.mod)
# Get R2 for linear mixed effects model (lme4)
library(lme4)
lmer.mod = lmer(DD ~ lat + (1|site/tree), data = shipley2009)
rsquared(lmer.mod)
# Get R2 for generalized linear mixed effects model (lme4)
glmer.mod = glmer(Live ~ Growth + (1|site/tree), family = "binomial", data = shipley2009)
rsquared(glmer.mod)
# }
Run the code above in your browser using DataLab