predictForCluster {latrend} | R Documentation |
Predict trajectories conditional on cluster membership
Description
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.
Usage
predictForCluster(object, newdata = NULL, cluster, ...)
## S4 method for signature 'lcModel'
predictForCluster(object, newdata = NULL, cluster, ..., what = "mu")
Arguments
object |
The model. |
newdata |
A |
cluster |
The cluster name (as |
... |
Arguments passed on to
|
what |
The distributional parameter to predict. By default, the mean response 'mu' is predicted. The cluster membership predictions can be obtained by specifying |
Details
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.
Value
A vector
with the predictions per newdata
observation, or a data.frame
with the predictions and newdata alongside.
Implementation
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 })
See Also
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()
Examples
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")