Skip to contents

This function uses a block diagonal covariance matrix for the underlying multivariate normal data to create the design matrix in blocks of 10, see the details.

Usage

simul_covariates(n, p_catvar = 10, add_contvars = FALSE, arm_factor = FALSE)

Arguments

n

(count)
number of rows (observations).

p_catvar

(count)
number of covariates (excluding treatment arm).

add_contvars

(flag)
whether to add continuous covariates.

arm_factor

(flag)
whether to make the arm variable a factor.

Value

The design matrix.

Details

The following pattern is repeated for the covariate blocks:

  • The first 5 covariates are uncorrelated with everything.

  • The covariates 6 to 8 have "moderate" correlation (0.25) between each other.

  • The covariates 9 and 10 have "high" correlation (0.5).

By default, only the resulting categorical covariates obtained by thresholding are included. Optionally also the original continuous covariates are included in the returned design matrix.

Examples

simul_covariates(n = 10, p_catvar = 3, add_contvars = FALSE)
#>    arm x_1 x_2 x_3
#> 1    0   a   b   b
#> 2    1   b   a   a
#> 3    0   a   b   b
#> 4    0   a   b   b
#> 5    1   a   b   b
#> 6    0   a   a   b
#> 7    1   b   b   b
#> 8    0   b   a   b
#> 9    1   b   b   a
#> 10   1   a   b   a
simul_covariates(n = 10, p_catvar = 3, add_contvars = TRUE)
#>    arm x_1 x_2 x_3        z_1         z_2         z_3
#> 1    0   b   a   b  0.9487540 -0.90951843  0.07326746
#> 2    1   a   b   b -1.3480495  0.45837916  1.23817132
#> 3    1   b   b   b  0.3541759 -0.04661845  0.71837134
#> 4    0   b   a   b  0.5302639 -0.68095460  0.53946650
#> 5    1   a   a   a -0.3109749 -1.48882940 -1.06123399
#> 6    0   a   a   b -0.2441555 -0.39251301 -0.54073787
#> 7    0   a   a   b -0.2918782 -1.74968202 -0.71520471
#> 8    1   a   b   b -1.1280862 -0.03866763 -0.17892009
#> 9    0   a   a   b -1.1228816 -0.79715324  0.16497028
#> 10   1   b   a   b  2.0539386 -0.91592054 -0.72740817
simul_covariates(n = 10, p_catvar = 3, add_contvars = TRUE, arm_factor = TRUE)
#>    arm x_1 x_2 x_3         z_1         z_2        z_3
#> 1    1   b   b   b  1.73390029  0.15550390  0.4370337
#> 2    0   b   a   b  0.45642938 -0.86911632  0.3723881
#> 3    0   b   a   a  0.70750349 -1.17448945 -1.6467491
#> 4    0   b   a   a  2.06378922 -1.75967731 -1.9235523
#> 5    1   b   b   b  0.02391059  0.05836159  0.3808330
#> 6    1   b   b   b  0.24594946  1.16451986  1.3757053
#> 7    1   b   b   b  0.27205914  0.33762789  0.8258487
#> 8    0   a   a   b -0.99245858 -1.05451872 -0.4161150
#> 9    0   a   b   b -0.02757795  0.66076911  0.9821496
#> 10   1   b   a   b  2.22284516 -0.82340900  0.2421807