if(require(ggplot2)){
#### simulate data in the long format ####
set.seed(10)
dL <- sampleRem(100, n.times = 3, format = "long")
dL$X1 <- as.factor(dL$X1)
#### fit Linear Mixed Model ####
eCS.lmm <- lmm(Y ~ visit + X1 + X6,
repetition = ~visit|id, structure = "CS", data = dL, df = FALSE)
#### model fit ####
plot(eCS.lmm, type = "fit", facet =~X1)
## customize display
gg <- autoplot(eCS.lmm, type = "fit", facet =~X1)$plot
gg + coord_cartesian(ylim = c(0,6))
## restrict to specific covariate value
plot(eCS.lmm, type = "fit", at = data.frame(X6=1), color = "X1")
#### qqplot ####
plot(eCS.lmm, type = "qqplot")
plot(eCS.lmm, type = "qqplot", engine.qqplot = "qqtest")
#### residual correlation ####
plot(eCS.lmm, type = "correlation")
#### residual trend ####
plot(eCS.lmm, type = "scatterplot")
#### residual heteroschedasticity ####
plot(eCS.lmm, type = "scatterplot2")
#### partial residuals ####
plot(eCS.lmm, type = "partial", type.residual = "visit")
plot(eCS.lmm, type = "partial", type.residual = c("(Intercept)","X1","visit"))
plot(eCS.lmm, type = "partial", type.residual = c("(Intercept)","X1","visit"),
facet = ~X1)
}
Run the code above in your browser using DataLab