# load lme4 package and example dataset
library(lme4)
data(Orthodont, package = "nlme")
# fit the two models under H1 and H0
m1 <- lmer(distance ~ 1 + Sex + age + age*Sex +
(0 + age | Subject), data = Orthodont, REML = FALSE)
m0 <- lm(distance ~ 1 + Sex + age + age*Sex, data = Orthodont)
# compare them (order is important: m1 comes first)
varCompTest(m1,m0,pval.comp="bounds")
# using nlme
library(nlme)
m1 <- lme(distance ~ 1 + Sex + age + age*Sex,
random = pdSymm(Subject ~ 1 + age), data = Orthodont, method = "ML")
m0 <- lme(distance ~ 1 + Sex, random = ~ 1 | Subject, data = Orthodont, method = "ML")
varCompTest(m1,m0)
Run the code above in your browser using DataLab