Fitting LME Models

The fitted model is an object of class lme representing the linear mixed-effects model fit. Generic functions such as print, plot and summary have methods to show the results of the fit.

Orthodont

Set Up

library(nlme)
data(Orthodont)
tail(Orthodont)
## Grouped Data: distance ~ age | Subject
##     distance age Subject    Sex
## 103     19.0  12     F10 Female
## 104     19.5  14     F10 Female
## 105     24.5   8     F11 Female
## 106     25.0  10     F11 Female
## 107     28.0  12     F11 Female
## 108     28.0  14     F11 Female

Baseline LM Model

lm1 <- lm(distance ~ age, data = Orthodont)
summary(lm1)
## 
## Call:
## lm(formula = distance ~ age, data = Orthodont)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.5037 -1.5778 -0.1833  1.3519  6.3167 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  16.7611     1.2256  13.676  < 2e-16 ***
## age           0.6602     0.1092   6.047 2.25e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.537 on 106 degrees of freedom
## Multiple R-squared:  0.2565, Adjusted R-squared:  0.2495 
## F-statistic: 36.56 on 1 and 106 DF,  p-value: 2.248e-08
AIC(lm1)
## [1] 511.577

Simple LME Model

fm1 <- lme(distance ~ age, data = Orthodont,method="ML") # random is ~ age
summary(fm1)
## Linear mixed-effects model fit by maximum likelihood
##   Data: Orthodont 
##        AIC      BIC    logLik
##   451.2116 467.3044 -219.6058
## 
## Random effects:
##  Formula: ~age | Subject
##  Structure: General positive-definite
##             StdDev    Corr  
## (Intercept) 2.1941125 (Intr)
## age         0.2149252 -0.581
## Residual    1.3100391       
## 
## Fixed effects:  distance ~ age 
##                 Value Std.Error DF  t-value p-value
## (Intercept) 16.761111 0.7678985 80 21.82725       0
## age          0.660185 0.0705779 80  9.35399       0
##  Correlation: 
##     (Intr)
## age -0.848
## 
## Standardized Within-Group Residuals:
##          Min           Q1          Med           Q3          Max 
## -3.305962769 -0.487430154  0.007597924  0.482236304  3.922791903 
## 
## Number of Observations: 108
## Number of Groups: 27
AIC(fm1)
## [1] 451.2116

More Complex LME Model

fm2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1)
summary(fm2)
## Linear mixed-effects model fit by REML
##   Data: Orthodont 
##        AIC      BIC    logLik
##   447.5125 460.7823 -218.7563
## 
## Random effects:
##  Formula: ~1 | Subject
##         (Intercept) Residual
## StdDev:    1.807425 1.431592
## 
## Fixed effects:  distance ~ age + Sex 
##                 Value Std.Error DF   t-value p-value
## (Intercept) 17.706713 0.8339225 80 21.233044  0.0000
## age          0.660185 0.0616059 80 10.716263  0.0000
## SexFemale   -2.321023 0.7614168 25 -3.048294  0.0054
##  Correlation: 
##           (Intr) age   
## age       -0.813       
## SexFemale -0.372  0.000
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -3.74889609 -0.55034466 -0.02516628  0.45341781  3.65746539 
## 
## Number of Observations: 108
## Number of Groups: 27
par(mfrow=c(2,2))
plot(fm2,pch=18)

par(mfrow=c(1,1))