autoplot.lmm {LMMstar}R 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 = NULL,
  facet = NULL,
  facet_nrow = NULL,
  facet_ncol = NULL,
  scales = "fixed",
  labeller = "label_value",
  at = NULL,
  time.var = NULL,
  color = NULL,
  position = NULL,
  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 variable 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.

facet

[formula] split the plot into a matrix of panels defined by the variables in the formula. Internally it calls ggplot2::facet_wrap or ggplot2::facet_grid depending on whether the formula contains a variable on the left hand side.

facet_nrow

[integer] number of rows of panels in the graphical display.

facet_ncol

[integer] number of columns of panels in the graphical display.

scales, labeller

[character] Passed to ggplot2::facet_wrap.

at

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

time.var

[character] x-axis variable for the plot.

color

[character] name of the variable in the dataset used to color the curve. No color is used when set to FALSE.

position

[character] relative position of the points when colored according to a variable.

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

Functions

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)

#### 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)
}

[Package LMMstar version 1.1.0 Index]