plotClusterTrajectories: Plot cluster trajectories

plotClusterTrajectoriesR Documentation

Plot cluster trajectories

Description

Plot cluster trajectories

Plot the cluster trajectories of a lcModel

Usage

## S4 method for signature 'data.frame'
plotClusterTrajectories(
  object,
  response,
  cluster = "Cluster",
  time = getOption("latrend.time"),
  center = meanNA,
  trajectories = c(FALSE, "sd", "se", "80pct", "90pct", "95pct", "range"),
  facet = !isFALSE(as.logical(trajectories[1])),
  id = getOption("latrend.id"),
  ...
)

## S4 method for signature 'lcModel'
plotClusterTrajectories(
  object,
  what = "mu",
  at = time(object),
  clusterLabels = NULL,
  trajectories = FALSE,
  facet = !isFALSE(as.logical(trajectories[1])),
  trajAssignments = trajectoryAssignments(object),
  ...
)

Arguments

object

The (cluster) trajectory data.

response

The response variable name.

cluster

The cluster assignment column

time

The time variable name.

center

A function for aggregating multiple points at the same point in time

trajectories

Whether to additionally plot the original trajectories (TRUE), or to show the expected interval (standard deviation, standard error, range, or percentile range) of the observations at the respective moment in time.

Note that visualizing the expected intervals is currently only supported for time-aligned trajectories, as the interval is computed at each unique moment in time. By default (FALSE), no information on the underlying trajectories is shown.

facet

Whether to facet by cluster. This is done by default when trajectories is enabled.

id

Id column. Only needed when trajectories = TRUE.

...

Arguments passed to clusterTrajectories(), or ggplot2::geom_line() for plotting the cluster trajectory lines.

what

The distributional parameter to predict. By default, the mean response 'mu' is predicted. The cluster membership predictions can be obtained by specifying what = 'mb'.

at

An optional vector of the times at which to compute the cluster trajectory predictions.

clusterLabels

Cluster display names. By default it's the cluster name with its proportion enclosed in parentheses.

trajAssignments

The cluster assignments for the fitted trajectories. Only used when trajectories = TRUE and facet = TRUE. See trajectoryAssignments.

Value

A ggplot object.

See Also

clusterTrajectories plotFittedTrajectories plotTrajectories plot

Other lcModel functions: clusterNames(), clusterProportions(), clusterSizes(), clusterTrajectories(), coef.lcModel(), converged(), deviance.lcModel(), df.residual.lcModel(), estimationTime(), externalMetric,lcModel,lcModel-method, fitted.lcModel(), fittedTrajectories(), getCall.lcModel(), getLcMethod(), ids(), lcModel-class, metric(), model.frame.lcModel(), nClusters(), nIds(), nobs.lcModel(), plot-lcModel-method, plotFittedTrajectories(), postprob(), predict.lcModel(), predictAssignments(), predictForCluster(), predictPostprob(), qqPlot(), residuals.lcModel(), sigma.lcModel(), strip(), time.lcModel(), trajectoryAssignments()

Examples

data(latrendData)
method <- lcMethodLMKM(Y ~ Time, id = "Id", time = "Time")
model <- latrend(method, latrendData, nClusters = 3)

if (require("ggplot2")) {
  plotClusterTrajectories(model)

  # show assigned trajectories
  plotClusterTrajectories(model, trajectories = TRUE)

  # show 95th percentile observation interval
  plotClusterTrajectories(model, trajectories = "95pct")

  # show observation standard deviation
  plotClusterTrajectories(model, trajectories = "sd")

  # show observation standard error
  plotClusterTrajectories(model, trajectories = "se")

  # show observation range
  plotClusterTrajectories(model, trajectories = "range")
}

latrend documentation built on March 31, 2023, 5:45 p.m.