Description Usage Arguments Value Examples
View source: R/clusterwiselmm.R
This function fits a clusterwise multi level model with k clusters to a given data frame using a geometrical approach. It runs the optimizer for many trials to get rid of the initialization bias and reach a global minima. You can choose between a batch or sequential approach and also fix the initial clustering.
1 2 3 4 5 6 7 8 9 10 11 |
data |
data frame containing the variables named in |
target |
vector containing the target variable. |
K |
number of clusters. |
formula |
formula a two sided linear formula object corresponding to |
nb_trials |
number of trials. |
nb_iterations |
maximum number of iterations. |
batch |
factor; if TRUE, runs a batch approach, otherwise runs a sequential one. |
verbose |
factor; if TRUE, prints the final cost at each trial. |
initialization |
if vector of the same length of data, use this vector as clustering initialization. Otherwise, do a random initialization. |
list containing models as a class of clmm, the final clustering and the final cost.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | require(stats)
## define correlation matrices for random effects slopes and intercepts
lvl2_corr_mat = matrix(c(1, 0,
0, 1), 2, 2)
lvl3_corr_mat = matrix(c(10, 0,
0, 10), 2, 2)
## generate 3 levels data with 3 groups that contains each 10 subgroups,
## and each subgroup contains 30 individuals
data = simulate_data(n1 = 30,
n2 = 10,
n3 = 3,
fixed_slope = -2,
fixed_intercept = 2,
lvl2_corr_mat = lvl2_corr_mat,
lvl3_corr_mat = lvl3_corr_mat,
sigma2 = 1
)
## fit a clusterwise lmm with 3 classes that tries to find level 3 clustering.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.