simulate_data: Simulate 3 levels data

Description Usage Arguments Details Value Examples

View source: R/simulate_data.R

Description

Generate univariate (for now) linear 3 level data with n3 groups, n2 subgroups per group and n1 individuals per subgroups.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
simulate_data(
  n1,
  n2,
  n3,
  fixed_slope,
  fixed_intercept,
  lvl2_corr_mat,
  lvl3_corr_mat,
  sigma2,
  separable_in_x = TRUE,
  distance_factor = 2
)

Arguments

n1

number of individuals at level 1. Must be strictly positive.

n2

number of subgroups at level 2. Must be strictly positive.

n3

number of groups at level 3. Must be strictly positive.

fixed_slope

Fixed effect slope. Must be finite.

fixed_intercept

Fixed effect intercept. Must be finite.

lvl2_corr_mat

Level 2 random effect correlation matrix. Must be of type matrix with size of 2x2

lvl3_corr_mat

Level 3 random effect correlation matrix. Must be of type matrix with size of 2x2

sigma2

variance of the residuals. Must be strictly positive.

separable_in_x

logical; if TRUE, the data will be separable in x axis.

distance_factor

numeric; When separable_in_x == TRUE, indicates the distances in x between level 3 groups. Must be strictly positive.

Details

The generated data follows the 3 levels lmm equations given below :

Y_{ijk} = β_{0jk} + β_{1jk} X_{ijk} + ε_{ijk}

Level 2 :

β_{0jk} = γ_{00k} + u_{0jk}

β_{1jk} = γ_{10k} + u_{1jk}

Level 3 :

γ_{00k} = δ_{000} + u_{00k}

γ_{10k} = δ_{100} + u_{10k}

With :

Value

data frame containing the generated data containing the following list of columns :

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## 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)

## to 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
                     )

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