autoplot.lmm: Graphical Display For Linear Mixed Models

View source: R/autoplot.R

autoplot.lmmR Documentation

Graphical Display For Linear Mixed Models

Description

Display fitted values or residual plot for the mean, variance, and correlation structure. Can also display quantile-quantile plot relative to the normal distribution.

Usage

## S3 method for class 'lmm'
autoplot(
  object,
  type = "fit",
  type.residual = NULL,
  obs.alpha = 0,
  obs.size = c(2, 0.5),
  at = NULL,
  time.var = NULL,
  color = TRUE,
  ci = TRUE,
  ci.alpha = NULL,
  ylim = NULL,
  mean.size = c(3, 1),
  size.text = 16,
  position.errorbar = "identity",
  ...
)

## S3 method for class 'lmm'
plot(x, ...)

Arguments

object, x

a lmm object.

type

[character] the type of plot

  • "fit": fitted values over repetitions.

  • "qqplot": quantile quantile plot of the normalized residuals

  • "correlation": residual correlation over repetitions

  • "scatterplot": normalized residuals vs. fitted values (diagnostic for missing non-linear effects),

  • "scatterplot2": square root of the normalized residuals vs. fitted values (diagnostic for heteroschedasticity),

  • "partial": partial residual plot.

type.residual

[character] the type of residual to be used. Not relevant for type="fit". By default, normalized residuals are used except when requesting a partial residual plot where this argument specify the variable relative to which the partial residuals are computed (argument var in residuals.lmm).

obs.alpha

[numeric, 0-1] When not NA, transparency parameter used to display the original data by cluster.

obs.size

[numeric vector of length 2] size of the point and line for the original data.

at

[data.frame] values for the covariates at which to evaluate the fitted values.

time.var

[character] x-axis variable for the plot.

color

[character] name of the variable in the dataset used to color the curve.

ci

[logical] should confidence intervals be displayed?

ci.alpha

[numeric, 0-1] When not NA, transparency parameter used to display the confidence intervals.

ylim

[numeric vector of length 2] the lower and higher value of the vertical axis.

mean.size

[numeric vector of length 2] size of the point and line for the mean trajectory.

size.text

[numeric, >0] size of the font used to display text.

position.errorbar

[character] relative position of the errorbars.

...

arguments passed to the predict.lmm or autoplot.residual_lmm functions.

Value

A list with two elements

  • data: data used to create the graphical display.

  • plot: ggplot object.

Functions

  • plot(lmm): Graphical Display For Linear Mixed Models

See Also

plot.lmm for other graphical display (residual plots, partial residual plots).

Examples

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)

plot(eCS.lmm, type = "fit")
autoplot(eCS.lmm, type = "fit")$plot + facet_wrap(~X1)
plot(eCS.lmm, type = "qqplot") ## engine.qqplot = "qqtest"
plot(eCS.lmm, type = "qqplot", engine.qqplot = "qqtest")
plot(eCS.lmm, type = "correlation") 
plot(eCS.lmm, type = "scatterplot") 
plot(eCS.lmm, type = "scatterplot2") 
plot(eCS.lmm, type = "partial", type.residual = "visit") 
plot(eCS.lmm, type = "partial", type.residual = "X1") 
plot(eCS.lmm, type = "partial", type.residual = "X6") 
}

LMMstar documentation built on Nov. 9, 2023, 1:06 a.m.