lcMethodFeature {latrend} | R Documentation |
Feature-based clustering
Description
Feature-based clustering.
Usage
lcMethodFeature(
response,
representationStep,
clusterStep,
standardize = scale,
center = meanNA,
time = getOption("latrend.time"),
id = getOption("latrend.id"),
...
)
Arguments
response |
The name of the response variable. |
representationStep |
A |
clusterStep |
A |
standardize |
A |
center |
The |
time |
The name of the time variable. |
id |
The name of the trajectory identification variable. |
... |
Additional arguments. |
Linear regresion & k-means example
In this example we define a feature-based approach where each trajectory is represented using a linear regression model. The coefficients of the trajectories are then clustered using k-means.
Note that this method is already implemented as lcMethodLMKM()
.
Representation step:
repStep <- function(method, data, verbose) { library(data.table) library(magrittr) xdata = as.data.table(data) coefdata <- xdata[, lm(method$formula, .SD) keyby = c(method$id) ] # exclude the id column coefmat <- subset(coefdata, select = -1) rownames(coefmat) <- coefdata[[method$id]] return(coefmat) }
Cluster step:
clusStep <- function(method, data, repMat, envir, verbose) { km <- kmeans(repMat, centers = method$nClusters) lcModelPartition( response = method$response, data = data, trajectoryAssignments = km$cluster ) }
Now specify the method and fit the model:
data(latrendData) method <- lcMethodFeature( formula = Y ~ Time, response = "Y", id = "Id", time = "Time", representationStep = repStep, clusterStep = clusStep model <- latrend(method, data = latrendData) )
See Also
Other lcMethod implementations:
getArgumentDefaults()
,
getArgumentExclusions()
,
lcMethod-class
,
lcMethodAkmedoids
,
lcMethodCrimCV
,
lcMethodDtwclust
,
lcMethodFunFEM
,
lcMethodFunction
,
lcMethodGCKM
,
lcMethodKML
,
lcMethodLMKM
,
lcMethodLcmmGBTM
,
lcMethodLcmmGMM
,
lcMethodMclustLLPA
,
lcMethodMixAK_GLMM
,
lcMethodMixtoolsGMM
,
lcMethodMixtoolsNPRM
,
lcMethodRandom
,
lcMethodStratify