Predicts the expected trajectory observations at the given time under the assumption that the trajectory belongs to the specified cluster.
For lcModel
objects, the same result can be obtained by calling predict()
with the newdata
data.frame
having a "Cluster"
assignment column.
The main purpose of this function is to make it easier to implement the prediction computations for custom lcModel
classes.
predictForCluster(object, newdata = NULL, cluster, ...)# S4 method for lcModel
predictForCluster(object, newdata = NULL, cluster, ..., what = "mu")
A vector
with the predictions per newdata
observation, or a data.frame
with the predictions and newdata alongside.
The model.
A data.frame
of trajectory data for which to compute trajectory assignments.
The cluster name (as character
) to predict for.
Arguments passed on to predict.lcModel
useCluster
Whether to use the "Cluster" column in the newdata argument for computing predictions conditional on the respective cluster.
For useCluster = NA
(the default), the feature is enabled if newdata contains the "Cluster" column.
The distributional parameter to predict. By default, the mean response 'mu' is predicted. The cluster membership predictions can be obtained by specifying what = 'mb'
.
Classes extending lcModel
should override this method, unless predict.lcModel()
is preferred.
setMethod("predictForCluster", "lcModelExt",
function(object, newdata = NULL, cluster, ..., what = "mu") {
# return model predictions for the given data under the
# assumption of the data belonging to the given cluster
})
The default predictForCluster(lcModel)
method makes use of predict.lcModel()
, and vice versa. For this to work, any extending lcModel
classes, e.g., lcModelExample
, should implement either predictForCluster(lcModelExample)
or predict.lcModelExample()
. When implementing new models, it is advisable to implement predictForCluster
as the cluster-specific computation generally results in shorter and simpler code.
predict.lcModel
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()
,
predictPostprob()
,
qqPlot()
,
residuals.lcModel()
,
sigma.lcModel()
,
strip()
,
time.lcModel()
,
trajectoryAssignments()
data(latrendData)
method <- lcMethodLMKM(Y ~ Time, id = "Id", time = "Time")
model <- latrend(method, latrendData)
predictForCluster(
model,
newdata = data.frame(Time = c(0, 1)),
cluster = "B"
)
# all fitted values under cluster B
predictForCluster(model, cluster = "B")
Run the code above in your browser using DataLab