R/generics.R
, R/model.R
, R/metricsInternal.R
, and 1 more
metric.Rd
Compute one or more internal metrics for the given lcModel
object.
Note that there are many metrics available, and there exists no metric that works best in all scenarios. It is recommended to carefully consider which metric is most appropriate for your use case.
Recommended overview papers:
arbelaitz2013extensive;textuallatrend provide an extensive overview validity indices for cluster algorithms.
vandernest2020overview;textuallatrend provide an overview of metrics for mixture models (GBTM, GMM); primarily likelihood-based or posterior probability-based metrics.
henson2007detecting;textuallatrend provide an overview of likelihood-based metrics for mixture models.
Call getInternalMetricNames()
to retrieve the names of the defined internal metrics.
See the Details section below for a list of supported metrics.
metric(object, name = getOption("latrend.metric", c("WRSS", "APPA.mean")), ...)
# S4 method for class 'lcModel'
metric(object, name = getOption("latrend.metric", c("WRSS", "APPA.mean")), ...)
# S4 method for class 'list'
metric(object, name, drop = TRUE)
# S4 method for class 'lcModels'
metric(object, name, drop = TRUE)
The lcModel
, lcModels
, or list
of lcModel
objects to compute the metrics for.
The name(s) of the metric(s) to compute. If no names are given, the names specified in the latrend.metric
option (WRSS, APPA, AIC, BIC) are used.
Additional arguments.
Whether to return a numeric vector
instead of a data.frame
in case of a single metric.
For metric(lcModel)
: A named numeric
vector with the computed model metrics.
For metric(list)
: A data.frame
with a metric per column.
For metric(lcModels)
: A data.frame
with a metric per column.
Metric name | Description | Function / Reference |
AIC | Akaike information criterion. A goodness-of-fit estimator that adjusts for model complexity (i.e., the number of parameters). Only available for models that support the computation of the model log-likelihood through logLik. | stats::AIC() , akaike1974newlatrend |
APPA.mean | Mean of the average posterior probability of assignment (APPA) across clusters. A measure of the precision of the trajectory classifications. A score of 1 indicates perfect classification. | APPA() , nagin2005grouplatrend |
APPA.min | Lowest APPA among the clusters | APPA() , nagin2005grouplatrend |
ASW | Average silhouette width based on the Euclidean distance | rousseeuw1987silhouetteslatrend |
BIC | Bayesian information criterion. A goodness-of-fit estimator that corrects for the degrees of freedom (i.e., the number of parameters) and sample size. Only available for models that support the computation of the model log-likelihood through logLik. | stats::BIC() , schwarz1978estimatinglatrend |
CAIC | Consistent Akaike information criterion | bozdogan1987modellatrend |
CLC | Classification likelihood criterion | mclachlan2000finitelatrend |
converged | Whether the model converged during estimation | converged() |
deviance | The model deviance | stats::deviance() |
Dunn | The Dunn index | dunn1974welllatrend |
entropy | Entropy of the posterior probabilities | |
estimationTime | The time needed for fitting the model | estimationTime() |
ED | Euclidean distance between the cluster trajectories and the assigned observed trajectories | |
ED.fit | Euclidean distance between the cluster trajectories and the assigned fitted trajectories | |
ICL.BIC | Integrated classification likelihood (ICL) approximated using the BIC | biernacki2000assessinglatrend |
logLik | Model log-likelihood | stats::logLik() |
MAE | Mean absolute error of the fitted trajectories (assigned to the most likely respective cluster) to the observed trajectories | |
Mahalanobis | Mahalanobis distance between the cluster trajectories and the assigned observed trajectories | mahalanobis1936generalizedlatrend |
MSE | Mean squared error of the fitted trajectories (assigned to the most likely respective cluster) to the observed trajectories | |
relativeEntropy , RE | A measure of the precision of the trajectory classification. A value of 1 indicates perfect classification, whereas a value of 0 indicates a non-informative uniform classification. It is the normalized version of entropy , scaled between [0, 1]. | ramaswamy1993empiricallatrend, muthen2004latentlatrend |
RMSE | Root mean squared error of the fitted trajectories (assigned to the most likely respective cluster) to the observed trajectories | |
RSS | Residual sum of squares under most likely cluster allocation | |
scaledEntropy | See relativeEntropy | |
sigma | The residual standard deviation | stats::sigma() |
ssBIC | Sample-size adjusted BIC | sclove1987applicationlatrend |
SED | Standardized Euclidean distance between the cluster trajectories and the assigned observed trajectories | |
SED.fit | The cluster-weighted standardized Euclidean distance between the cluster trajectories and the assigned fitted trajectories | |
WMAE | MAE weighted by cluster-assignment probability | |
WMSE | MSE weighted by cluster-assignment probability | |
WRMSE | RMSE weighted by cluster-assignment probability | |
WRSS | RSS weighted by cluster-assignment probability |
See the documentation of the defineInternalMetric()
function for details on how to define your own metrics.
externalMetric min.lcModels max.lcModels
Other metric functions:
defineExternalMetric()
,
defineInternalMetric()
,
externalMetric()
,
getExternalMetricDefinition()
,
getExternalMetricNames()
,
getInternalMetricDefinition()
,
getInternalMetricNames()
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
,
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()
,
trajectoryAssignments()
data(latrendData)
method <- lcMethodLMKM(Y ~ Time, id = "Id", time = "Time")
model <- latrend(method, latrendData)
metric(model, "WMAE")
#> WMAE
#> 0.2158127
if (require("clusterCrit")) {
metric(model, c("WMAE", "Dunn"))
}
#> WMAE Dunn
#> 0.2158127 0.2204919