R/sleep/LME.R

# Title     : LME.R
# Objective : Linear Mixed Effects
# Created by: greyhypotheses
# Created on: 11/03/2022


# the data
data(sleepstudy)

# summary
summary(object = sleepstudy)



#' Random Intercept, Fixed Effects Model

# ... Reaction > fixed,   Subject > random
model <- lme(fixed = Reaction ~ Days, data = sleepstudy, random = ~1 | Subject)
estimates <- summary(model)

# ... the fixed effects regression coefficients \beta_{0} & \beta_{1}
estimates$coefficients$fixed

# ... variances
estimates$sigma

# ... ln-likelihood & AIC
estimates$logLik
estimates$AIC

# ... method
estimates$method

# ... alternative
alternative <- lme(fixed = Reaction ~ Days, data = sleepstudy, random = ~1 | Subject, method = 'ML')
summary(object = alternative)



# Residuals

# ... are the points randomly distributed about y = 0
plot(model, frame.plot = FALSE)
plot(x = model$fitted, y = model$residuals, frame.plot = FALSE)

# ... are the standardised residuals normally distributed?
# ... if the points lie along line y = x ... yes
qqnorm(model, frame.plot = FALSE)
premodelling/mixed documentation built on April 25, 2022, 6:27 a.m.