lcMethodCustom: Specify a custom method based on a model function

Description Usage Arguments See Also Examples

View source: R/methodCustom.R

Description

Specify a custom method based on a model function

Usage

1
2
3
4
5
6
7
8
lcMethodCustom(
  response,
  fun,
  center = meanNA,
  time = getOption("latrend.time"),
  id = getOption("latrend.id"),
  name = "custom"
)

Arguments

response

The name of the response variable.

fun

The cluster function with signature (method, data).

center

Optional function for computing the longitudinal cluster centers, with signature (x).

time

The name of the time variable.

id

The name of the trajectory identification variable.

name

The name of the method.

See Also

Other lcMethod implementations: lcMethod-class, lcMethodAkmedoids, lcMethodCrimCV, lcMethodDtwclust, lcMethodFeature, lcMethodFunFEM, lcMethodGCKM, lcMethodKML, lcMethodLMKM, lcMethodLcmmGBTM, lcMethodLcmmGMM, lcMethodLongclust, lcMethodMclustLLPA, lcMethodMixAK_GLMM, lcMethodMixtoolsGMM, lcMethodMixtoolsNPRM, lcMethodRandom, lcMethodStratify

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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
   lcModelCustom(data = data,
     trajectoryAssignments = factor(clusters, levels = c(FALSE, TRUE), labels = c("Low", "High")),
     response = response,
     time = time,
     id = id)
}
method <- lcMethodCustom(response = "Y", fun = clusfun, id = "Id", time = "Time")
model <- latrend(method, data = latrendData)

latrend documentation built on April 14, 2021, 5:08 p.m.