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()
)
A data.frame
representing the trajectory data.
The name of the response variable.
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.
The number of clusters. Should be NA
for trajectory assignments of type factor
.
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.
The name of the time variable.
The name of the trajectory identification variable.
The name of the method.
The function
for computing the longitudinal cluster centers, used for representing the cluster trajectories.
Optional lcMethod
object that was used for fitting this model to the data.
Set the converged state.
An optional object to attach to the lcModelPartition
object, representing the internal model that was used for obtaining the partition.
The environment
associated with the model. Used for evaluating the assigned data
object by model.data.lcModel.
# 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