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
S4
methods based on an abstract model class, enabling rapid prototyping of new cluster methods or model specifications.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.