The latrend
package provides a framework for clustering longitudinal datasets in a standardized way. The name is short for latent-class trend (analysis), referring to the discovery of hidden trends in the data. The package provides interfaces to various R packages for conducting this type of analysis.
The package is described in detail in the pre-print available at https://arxiv.org/abs/2402.14621
- Unified cluster analysis, independent of the underlying algorithms used. Enabling users to compare the performance of various longitudinal cluster methods on the case study at hand.
- Supports many different methods for longitudinal clustering out of the box (see the list of supported packages below).
- The framework consists of extensible
S4
methods based on an abstract model class, enabling rapid prototyping of new cluster methods or model specifications. - Standard plotting tools for model evaluation across methods (e.g., trajectories, cluster trajectories, model fit, metrics)
- Support for many cluster metrics through the packages clusterCrit, mclustcomp, and igraph.
- The structured and unified analysis approach enables simulation studies for comparing methods.
- Standardized model validation for all methods through bootstrapping or k-fold cross-validation.
See the release notes page for the latest updates.
The latest release of latrend can be installed from CRAN by running:
install.packages("latrend")
It can also be installed from Github directly using:
remotes::install_github('philips-software/latrend', ref = remotes::github_release())
# include vignettes
remotes::install_github('philips-software/latrend', ref = remotes::github_release(), build_vignettes = TRUE)
library(latrend)
Load and view example data.
data(latrendData)
head(latrendData)
options(latrend.id = "Id", latrend.time = "Time")
plotTrajectories(latrendData, response = "Y")
Cluster the trajectories and plot the results.
kmlMethod <- lcMethodKML("Y", nClusters = 3)
model <- latrend(kmlMethod, data = latrendData)
summary(model)
plot(model)
Identify solutions for 1 to 5 clusters.
kmlMethods <- lcMethods(kmlMethod, nClusters = 1:5)
models <- latrendBatch(kmlMethods, data = latrendData)
Determine the number of clusters through one or more internal cluser metrics.
metric(models, c("WMAE", "BIC"))
plotMetric(models, c("Dunn", "ASW", "WMAE", "WRSS", "BIC", "estimationTime"))
The latrend
package provides interfaces to the relevant methods for longitudinal clustering for the following packages:
We appreciate any contributions in the form of ideas, feature requests, bug reports, bug fixes, documentation improvements, code reformatting, and code submissions. Please see the Contributing guide.