Predicts the expected trajectory observations at the given time under the assumption that the trajectory belongs to the specified cluster.
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.
# S4 method for lcModel
predictForCluster(object, newdata = NULL, cluster, ..., what = "mu")
The lcModel
object.
Optional data.frame
for which to compute the model predictions. If omitted, the model training data is used.
Cluster trajectory predictions are made when ids are not specified.
The cluster name (as character
) to predict for.
Additional arguments.
The distributional parameter to predict. By default, the mean response 'mu' is predicted. The cluster membership predictions can be obtained by specifying what = 'mb'
.
A vector
with the predictions per newdata
observation, or a data.frame
with the predictions and newdata alongside.
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()
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.
Other model-specific methods:
clusterTrajectories()
,
coef.lcModel()
,
converged()
,
deviance.lcModel()
,
df.residual.lcModel()
,
fitted.lcModel()
,
fittedTrajectories()
,
lcModel-class
,
logLik.lcModel()
,
model.frame.lcModel()
,
nobs.lcModel()
,
postprob()
,
predict.lcModel()
,
predictAssignments()
,
predictPostprob()
,
residuals.lcModel()
,
sigma.lcModel()
,
time.lcModel()
# NOT RUN {
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