View source: R/methodFeature.R
| lcMethodFeature | R Documentation |
Feature-based clustering.
lcMethodFeature(
response,
representationStep,
clusterStep,
standardize = scale,
center = meanNA,
time = getOption("latrend.time"),
id = getOption("latrend.id"),
...
)
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. |
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) )
Other lcMethod implementations:
getArgumentDefaults(),
getArgumentExclusions(),
lcMethod-class,
lcMethodAkmedoids,
lcMethodCrimCV,
lcMethodDtwclust,
lcMethodFunFEM,
lcMethodFunction,
lcMethodGCKM,
lcMethodKML,
lcMethodLMKM,
lcMethodLcmmGBTM,
lcMethodLcmmGMM,
lcMethodMclustLLPA,
lcMethodMixAK_GLMM,
lcMethodMixtoolsGMM,
lcMethodMixtoolsNPRM,
lcMethodRandom,
lcMethodStratify
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.