Specify a stratification method
The name of the response variable.
An expression returning a number or factor value per trajectory, representing the cluster assignment. Alternatively, a function can be provided that takes separate trajectory data.frame as input.
The function for computing the longitudinal cluster centers, used for representing the cluster trajectories.
The number of clusters. This is optional, as this can be derived from the largest assignment number by default, or the number of factor levels.
The names of the clusters. If a factor assignment is returned, the levels are used as the cluster names.
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,
lcMethodFunction,
lcMethodGCKM,
lcMethodKML,
lcMethodLMKM,
lcMethodLcmmGBTM,
lcMethodLcmmGMM,
lcMethodMclustLLPA,
lcMethodMixAK_GLMM,
lcMethodMixtoolsGMM,
lcMethodMixtoolsNPRM,
lcMethodRandom
data(latrendData)
# Stratification based on the mean response level
method <- lcMethodStratify(
"Y",
mean(Y) > 0,
clusterNames = c("Low", "High"),
id = "Id",
time = "Time"
)
model <- latrend(method, latrendData)
summary(model)
#> Longitudinal cluster model using stratify
#> lcMethodStratify specifying "stratify"
#> center: function (x) { mean(x, na.rm = TRUE)}
#> nClusters: NaN
#> clusterNames: "Low", "High"
#> time: "Time"
#> id: "Id"
#> name: "stratify"
#> response: "Y"
#> stratify: mean(Y) > 0
#>
#> Cluster sizes (K=2):
#> Low High
#> 119 (59.5%) 81 (40.5%)
#>
#> Number of obs: 2000, strata (Id): 200
#>
#> Scaled residuals:
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> -3.85807 -0.57074 0.08278 0.00000 0.65266 2.90961
#>
# Stratification function
stratfun <- function(trajdata) {
trajmean <- mean(trajdata$Y)
factor(
trajmean > 1.7,
levels = c(FALSE, TRUE),
labels = c("Low", "High")
)
}
method <- lcMethodStratify("Y", stratfun, id = "Id", time = "Time")
# Multiple clusters
stratfun3 <- function(trajdata) {
trajmean <- mean(trajdata$Y)
cut(
trajmean,
c(-Inf, .5, 2, Inf),
labels = c("Low", "Medium", "High")
)
}
method <- lcMethodStratify("Y", stratfun3, id = "Id", time = "Time")