Specify a custom method based on a function
The name of the response variable.
The cluster function with signature (method, data) that returns a lcModel object.
Optional function for computing the longitudinal cluster centers, with signature (x).
The name of the time variable.
The name of the trajectory identification variable.
The name of the method.
Other lcMethod implementations:
getArgumentDefaults(),
getArgumentExclusions(),
lcMethod-class,
lcMethodAkmedoids,
lcMethodCrimCV,
lcMethodDtwclust,
lcMethodFeature,
lcMethodFunFEM,
lcMethodGCKM,
lcMethodKML,
lcMethodLMKM,
lcMethodLcmmGBTM,
lcMethodLcmmGMM,
lcMethodMclustLLPA,
lcMethodMixAK_GLMM,
lcMethodMixtoolsGMM,
lcMethodMixtoolsNPRM,
lcMethodRandom,
lcMethodStratify
data(latrendData)
# Stratification based on the mean response level
clusfun <- function(data, response, id, time, ...) {
clusters <- data.table::as.data.table(data)[, mean(Y) > 0, by = Id]$V1
lcModelPartition(
data = data,
trajectoryAssignments = factor(
clusters,
levels = c(FALSE, TRUE),
labels = c("Low", "High")
),
response = response,
time = time,
id = id
)
}
method <- lcMethodFunction(response = "Y", fun = clusfun, id = "Id", time = "Time")
model <- latrend(method, data = latrendData)