Represents an arbitrary partitioning of a set of trajectories. As such, this model has no predictive capabilities. The cluster trajectories are represented by the specified center function (mean by default).

lcModelPartition(
  data,
  response,
  trajectoryAssignments,
  nClusters = NA,
  clusterNames = character(),
  time = getOption("latrend.time"),
  id = getOption("latrend.id"),
  name = "part",
  center = meanNA,
  method = NULL,
  converged = TRUE,
  model = NULL,
  envir = parent.frame()
)

Arguments

data

A data.frame representing the trajectory data.

response

The name of the response variable.

trajectoryAssignments

A vector of cluster membership per trajectory, a data.frame with an id column and "Cluster" column, or the name of the cluster membership column in the data argument.. For vector input, the type must be factor, character, or integer (1 to nClusters). The order of the trajectory, and thus the respective assignments, is determined by the id column of the data. Provide a factor id column for the input data to ensure that the ordering is as you aspect.

nClusters

The number of clusters. Should be NA for trajectory assignments of type factor.

clusterNames

The names of the clusters, or a function with input n outputting a character vector of names. If unspecified, the names are determined from the trajectoryAssignments argument.

time

The name of the time variable.

id

The name of the trajectory identification variable.

name

The name of the method.

center

The function for computing the longitudinal cluster centers, used for representing the cluster trajectories.

method

Optional lcMethod object that was used for fitting this model to the data.

converged

Set the converged state.

model

An optional object to attach to the lcModelPartition object, representing the internal model that was used for obtaining the partition.

envir

The environment associated with the model. Used for evaluating the assigned data object by model.data.lcModel.

Examples

# comparing a model to the ground truth using the adjusted Rand index
data(latrendData)
method <- lcMethodLMKM(Y ~ Time, id = "Id", time = "Time")
model <- latrend(method, latrendData, nClusters = 3)

# extract the reference class from the Class column
trajLabels <- aggregate(Class ~ Id, head, 1, data = latrendData)
trajLabels$Cluster <- trajLabels$Class
refModel <- lcModelPartition(latrendData, response = "Y", trajectoryAssignments = trajLabels)

if (require("mclustcomp")) {
  externalMetric(model, refModel, "adjustedRand")
}
#> adjustedRand 
#>    0.9669189