Mixed Effects Models are used when there is one or more predictor variables with multiple values for each unit of observation. Mixed Effects Models are prominently used in research involving human and animal subjects in fields ranging from genetics to marketing, and have also been used in baseball and industrial statistics.
I found that the best and simple explanation of Mixed Effects Models is presented by Christoph Scherber in his video “Mixed effects models with R”. The video showing basic usage of the “lme” command (nlme library) in R. In particular, the comparison output from the lm() command with that from a call to lme(). Now let’s take a look at the difference of two models.
data(Oats)
## Classes 'nfnGroupedData', 'nfGroupedData', 'groupedData' and 'data.frame': 72 obs. of 4 variables:
## $ Block : Ord.factor w/ 6 levels "VI"<"V"<"III"<..: 6 6 6 6 6 6 6 6 6 6 ...
## $ Variety: Factor w/ 3 levels "Golden Rain",..: 3 3 3 3 1 1 1 1 2 2 ...
## $ nitro : num 0 0.2 0.4 0.6 0 0.2 0.4 0.6 0 0.2 ...
## $ yield : num 111 130 157 174 117 114 161 141 105 140 ...
## - attr(*, "formula")=Class 'formula' language yield ~ nitro | Block
## .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
## - attr(*, "labels")=List of 2
## ..$ y: chr "Yield"
## ..$ x: chr "Nitrogen concentration"
## - attr(*, "units")=List of 2
## ..$ y: chr "(bushels/acre)"
## ..$ x: chr "(cwt/acre)"
## - attr(*, "inner")=Class 'formula' language ~Variety
## .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
plot(Oats)
Let’s Model this data
Model1=lm(yield~Variety*nitro, data=Oats)
summary(Model1)
##
## Call:
## lm(formula = yield ~ Variety * nitro, data = Oats)
##
## Residuals:
## Min 1Q Median 3Q Max
## -35.950 -14.967 -1.258 12.675 52.050
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 81.900 7.342 11.155 < 2e-16 ***
## VarietyMarvellous 8.517 10.383 0.820 0.415033
## VarietyVictory -8.600 10.383 -0.828 0.410506
## nitro 75.333 19.622 3.839 0.000279 ***
## VarietyMarvellous:nitro -10.750 27.750 -0.387 0.699718
## VarietyVictory:nitro 5.750 27.750 0.207 0.836487
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 21.5 on 66 degrees of freedom
## Multiple R-squared: 0.4134, Adjusted R-squared: 0.369
## F-statistic: 9.303 on 5 and 66 DF, p-value: 9.66e-07
Model2=lme(yield~Variety*nitro, data=Oats,random=~1|Block/Variety)
summary(Model2)
## Linear mixed-effects model fit by REML
## Data: Oats
## AIC BIC logLik
## 581.2372 600.9441 -281.6186
##
## Random effects:
## Formula: ~1 | Block
## (Intercept)
## StdDev: 14.64487
##
## Formula: ~1 | Variety %in% Block
## (Intercept) Residual
## StdDev: 10.39931 12.99039
##
## Fixed effects: yield ~ Variety * nitro
## Value Std.Error DF t-value p-value
## (Intercept) 81.90000 8.570715 51 9.555796 0.0000
## VarietyMarvellous 8.51667 8.684676 10 0.980655 0.3499
## VarietyVictory -8.60000 8.684676 10 -0.990250 0.3454
## nitro 75.33333 11.858547 51 6.352661 0.0000
## VarietyMarvellous:nitro -10.75000 16.770518 51 -0.641006 0.5244
## VarietyVictory:nitro 5.75000 16.770518 51 0.342864 0.7331
## Correlation:
## (Intr) VrtyMr VrtyVc nitro VrtyM:
## VarietyMarvellous -0.507
## VarietyVictory -0.507 0.500
## nitro -0.415 0.410 0.410
## VarietyMarvellous:nitro 0.294 -0.579 -0.290 -0.707
## VarietyVictory:nitro 0.294 -0.290 -0.579 -0.707 0.500
##
## Standardized Within-Group Residuals:
## Min Q1 Med Q3 Max
## -1.78878622 -0.64954421 -0.06301218 0.57818029 1.63463799
##
## Number of Observations: 72
## Number of Groups:
## Block Variety %in% Block
## 6 18
coef(Model1)
## (Intercept) VarietyMarvellous VarietyVictory
## 81.900000 8.516667 -8.600000
## nitro VarietyMarvellous:nitro VarietyVictory:nitro
## 75.333333 -10.750000 5.750000
coef(Model2)
## (Intercept) VarietyMarvellous VarietyVictory nitro
## VI/Golden Rain 69.89230 8.516667 -8.6 75.33333
## VI/Marvellous 79.57387 8.516667 -8.6 75.33333
## VI/Victory 74.29846 8.516667 -8.6 75.33333
## V/Golden Rain 72.45580 8.516667 -8.6 75.33333
## V/Marvellous 61.27554 8.516667 -8.6 75.33333
## V/Victory 74.88368 8.516667 -8.6 75.33333
## III/Golden Rain 67.29867 8.516667 -8.6 75.33333
## III/Marvellous 86.33209 8.516667 -8.6 75.33333
## III/Victory 69.18703 8.516667 -8.6 75.33333
## IV/Golden Rain 83.09717 8.516667 -8.6 75.33333
## IV/Marvellous 69.93864 8.516667 -8.6 75.33333
## IV/Victory 76.17321 8.516667 -8.6 75.33333
## II/Golden Rain 88.94013 8.516667 -8.6 75.33333
## II/Marvellous 90.88844 8.516667 -8.6 75.33333
## II/Victory 75.18212 8.516667 -8.6 75.33333
## I/Golden Rain 109.71591 8.516667 -8.6 75.33333
## I/Marvellous 103.39143 8.516667 -8.6 75.33333
## I/Victory 121.67549 8.516667 -8.6 75.33333
## VarietyMarvellous:nitro VarietyVictory:nitro
## VI/Golden Rain -10.75 5.75
## VI/Marvellous -10.75 5.75
## VI/Victory -10.75 5.75
## V/Golden Rain -10.75 5.75
## V/Marvellous -10.75 5.75
## V/Victory -10.75 5.75
## III/Golden Rain -10.75 5.75
## III/Marvellous -10.75 5.75
## III/Victory -10.75 5.75
## IV/Golden Rain -10.75 5.75
## IV/Marvellous -10.75 5.75
## IV/Victory -10.75 5.75
## II/Golden Rain -10.75 5.75
## II/Marvellous -10.75 5.75
## II/Victory -10.75 5.75
## I/Golden Rain -10.75 5.75
## I/Marvellous -10.75 5.75
## I/Victory -10.75 5.75
Looking at the parameters we can see that they don’t change when we use lme function. Standard errors are effected by random effects in the model.Comparing two models we see different intercepts for each block in Model2, while linear regression shows constant intercept of 81.9.
plot(ranef(Model2))
This plot shows simmetrical spread of random effects around 0. There is no particular pattern.
plot(Model2)
Looking at the Linear Model and Mixed Effect Model we can see that including random effects in the model is off necessary.
As has been demonstrated a mixed effects model has both random and fixed effects while a standard linear regression model has only fixed effects. Mixed effects models are useful when we have data with more than one source of random variability.These models are useful in a wide variety of disciplines in the physical, biological and social sciences.