Sei sulla pagina 1di 24

Mixed Effects Models

Rebecca Atkins and Rachel Smith


March 30, 2015
Up to now
General Linear Model (lm)
yi = + 11 + ... + + with ~ N(0, i2)
Generalized Linear Model (glm)
Non-normal error distributions for response
variable; link function
Generalized Additive Model (gam)
Identify smoothed lines of best fit for non-linear
relationships
Generalized Least Squares (gls)
Altered variance structures of Normal distribution
Residuals are normally distributed
Histogram or Q-Q plot
Residuals are homogenous or homoscedastic
(constant variance)
No autocorrelation between observations
plot residuals
No colinearity between independent variables
Pairs plot in R
The model is not biased by unduly influential
observations
Cooks Distance and leverage
Independent observations
But what about
Nested data?
Blocking?
Repeated measures?
Split-plot designs?
Spatial or temporal autocorrelation?
Use of mixed models
Mixed effects models or multilevel models
and are used when the data have a
hierarchical formwhich can have both fixed
and random coefficients together with
multiple error terms.1

Zuur et al. 2007. Analyzing Ecological Data. Pg 127


Rob Thomas
Rob Thomas
Model Structure

LMM,
GLS GLMM,
GAMM

LM, GAM,
GLM
Parameter estimation
ML = Maximum Likelihood
Common with GLM
REML = Restricted Maximum Likelihood
Corrects ML estimation for the number of fixed
covariates
Less influenced by outliers than ML estimates
Common with LMM
R packages
library(nlme) = Non-Linear Mixed Effects
lme = Linear Mixed Effects
gls = Generalised Least Squares
model<- lme (y ~ fixed, random = ~1|random,
data)
library (lme4) = Linear Mixed Effects v.4
lmer = Linear Mixed Effects REML
model <- lmer(y ~ fixed + (1|random), family =
gaussian (link = identity), data)
Nested Design Example
From Zuur 2009

Are there any differences between the NAP-


richness relationship at these 9 beaches?
NAP = tidal height, predictive variable
Species richness = response variable
Mixed Effects Model Structure
Richness-NAP
fixed effect Richness-NAP
across all random effect for
beaches each beach
richness values for
beach i, i = 1,,9

Fixed Term Random Term

From Zuur 2009


Model 1: Constant slope/intercept
yi = + i + with ~ N(0, i2)
Assumes that the richness-NAP relationship is
the same at all beaches
model1 <- gls (richness ~ 1 + NAP, method =
REML, data )

A model fitted using the REML


method, but containing no
random effects at allbasically a
REML-fitted linear regression From Zuur
2007 and
Rob Thomas
Model 2: varying intercept, same
slope
yij = + ij + aj + j where aj ~ N(0, a2)
and j ~ N(0, 2)
model2 <- lme (richness ~ NAP, random =
~1|beach, method = REML, data)

i.e. a model that fits


the same slope for
each level of the
random factor (fitted
From Zuur
by REML by default)
2007 and
Rob Thomas
Model 3: varying slope, varying
intercept
yij = + ij + aj + bjxij + j where aj ~ N(0, a2),
bj ~ N(0, b2), and j ~ N(0, 2)
model3 <-- lme (richness ~ NAP, random =
~NAP | beach, method = REML, data)

i.e. a model that fits a


different slope for each
level of the random factor
From Zuur
(fitted by REML by default)
2007 and
Rob Thomas
Additional complexity
Generalized Mixed models: lmer() and mgcv()
GLMM and GAMM; different underlying error
distributions
Mixed Effects Resources
Mixed Effects Models and Extensions in
Ecology with R (2009). Zuur, Ieno, Walker,
Saveliev and Smith. Springer
Model selection?
Check assumptions of the model (e.g.,
residuals and colinearity)
Compare competing models (R. Thomas
recommends comparing a gls (containing no
random effects) to a linear effects mixed
model to assess the importance of the
random effect).
Compare nested models using AIC
OR: stepwise model refinement
The End!
Presenting examples (how many?)
How many types of models (nested- repeated
measures, split-plot designs, nonlinear, linear)
Page 102 (online) and 71 (book) of Zuur
BDRipley 271 (pdf)
Random slope vs intercept models
Relate to R code / packages?
LME4 and NLME
General/Generalised linear model
General/Generalised additive model (GAM):
identify smoothed lines of best fit through a
dataset. A non-parametric smoothed relationship
is chosen to fit a curve.
Non-Gaussian error distributions can also be chosen
as with GLM
Generalised least squares (GLS): incorporates a
random term that takes into account
heteroskedasticity (non-homogenous variance
and/or autocorrelation structures)
Can use gls function in nlme package
Multiple variance structures to pick from
General/Generalised linear mixed modeling
nlme; lme4; asreml
Model fitting
ML (Maximum likelihood): common with GLM
REML (Restricted Maximum likelihood): corrects ML estimation
for the number of fixed covariates. Less influenced by outliers than
ML estimates
Structure
Random intercept (same autocorrelation function for all levels of
fixed factors)
Random intercept + slope (autocorrelation function varies across
different levels of the fixed factor)
Random slope and > 1 random effect
Random effect only aside from the intercept (useful as a null
model to evaluate the importance of fixed effects in a GLMM)
Fixed factors only (not really a mixed model, but useful as a null
model to evaluate the importance of random effects in a GLMM)

Generalised additive mixed modeling


Model 5: Random effect, no fixed
effect
yi= + bi+ j with j ~ N(0, 2)
model5 <-- lme(richness ~1, random =
~1|beach, method = RMEL, data)
y

i.e. a model that fits the


mean value for each
level of the random
factor (fitted by REML
by default)

From Rob Thomas x

Potrebbero piacerti anche