Learn R Programming

latrend (version 1.3.0)

trajectoryAssignments: Get the cluster membership of each trajectory

Description

Classify the fitted trajectories based on the posterior probabilities computed by postprob(), according to a given classification strategy.

By default, trajectories are assigned based on the highest posterior probability using which.max(). In cases where identical probabilities are expected between clusters, it is preferable to use which.is.max instead, as this function breaks ties at random. Another strategy to consider is the function which.weight(), which enables weighted sampling of cluster assignments based on the trajectory-specific probabilities.

Usage

# S4 method for matrix
trajectoryAssignments(
  object,
  strategy = which.max,
  clusterNames = colnames(object),
  ...
)

# S4 method for lcModel trajectoryAssignments(object, strategy = which.max, ...)

Arguments

object

The object to obtain the cluster assignments from.

strategy

A function returning the cluster index based on the given vector of membership probabilities. By default, ids are assigned to the cluster with the highest probability.

clusterNames

Optional character vector with the cluster names. If clusterNames = NULL, make.clusterNames() is used.

...

Any additional arguments passed to the strategy function.

Value

A factor indicating the cluster membership for each trajectory.

Details

In case object is a matrix: the posterior probability matrix, with the \(k\)th column containing the observation- or trajectory-specific probability for cluster \(k\).

See Also

postprob clusterSizes predictAssignments

Examples

Run this code
# NOT RUN {
data(latrendData)
method <- lcMethodLMKM(Y ~ Time, id = "Id", time = "Time")
model <- latrend(method, latrendData)
trajectoryAssignments(model)

# assign trajectories at random using weighted sampling
trajectoryAssignments(model, strategy = which.weight)
# }

Run the code above in your browser using DataLab