| predictForCluster | R Documentation |
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 signature 'lcModel'
predictForCluster(object, newdata = NULL, cluster, ..., what = "mu")
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 |
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.
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
})
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.