clusterwiselmm: Geometrical clusterwise method for linear multi level models

Description Usage Arguments Value Examples

View source: R/clusterwiselmm.R

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
clusterwiselmm(
  data,
  target,
  K,
  formula,
  nb_trials = 50,
  nb_iterations = 100,
  batch = TRUE,
  verbose = TRUE,
  initialization = NULL
)

Arguments

data

data frame containing the variables named in formula.

target

vector containing the target variable.

K

number of clusters.

formula

formula a two sided linear formula object corresponding to formula parameter in lmer from lme4 package.

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.

Value

list containing models as a class of clmm, the final clustering and the final cost.

Examples

 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.

Redha-ALLICHE/clusterwiselmm documentation built on Aug. 3, 2020, 1:10 a.m.