R/generics.R
, R/matrix.R
, R/model.R
trajectoryAssignments.Rd
Get the cluster membership of each trajectory associated with the given model.
For lcModel
: 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.
trajectoryAssignments(object, ...)
# S4 method for class 'matrix'
trajectoryAssignments(
object,
strategy = which.max,
clusterNames = colnames(object),
...
)
# S4 method for class 'lcModel'
trajectoryAssignments(object, strategy = which.max, ...)
The model.
Any additional arguments passed to the strategy function.
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.
Optional character vector
with the cluster names.
If clusterNames = NULL
, make.clusterNames()
is used.
A factor vector
indicating the cluster membership for each trajectory.
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\).
postprob clusterSizes predictAssignments
Other lcModel functions:
clusterNames()
,
clusterProportions()
,
clusterSizes()
,
clusterTrajectories()
,
coef.lcModel()
,
converged()
,
deviance.lcModel()
,
df.residual.lcModel()
,
estimationTime()
,
externalMetric()
,
fitted.lcModel()
,
fittedTrajectories()
,
getCall.lcModel()
,
getLcMethod()
,
ids()
,
lcModel-class
,
metric()
,
model.frame.lcModel()
,
nClusters()
,
nIds()
,
nobs.lcModel()
,
plot-lcModel-method
,
plotClusterTrajectories()
,
plotFittedTrajectories()
,
postprob()
,
predict.lcModel()
,
predictAssignments()
,
predictForCluster()
,
predictPostprob()
,
qqPlot()
,
residuals.lcModel()
,
sigma.lcModel()
,
strip()
,
time.lcModel()
data(latrendData)
method <- lcMethodLMKM(Y ~ Time, id = "Id", time = "Time")
model <- latrend(method, latrendData)
trajectoryAssignments(model)
#> [1] B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
#> [38] B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
#> [75] B B B B B B A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
#> [112] A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
#> [149] A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
#> [186] A A A A A A A A A A A A A A A
#> Levels: A B
# assign trajectories at random using weighted sampling
trajectoryAssignments(model, strategy = which.weight)
#> [1] B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
#> [38] B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
#> [75] B B B B B B A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
#> [112] A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
#> [149] A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
#> [186] A A A A A A A A A A A A A A A
#> Levels: A B