Description Usage Arguments Value Examples
Function to create simulated dataset given user-defined parameters and data structure for growth curve model with optional random effect for L2 variance
1 2 3 |
sample_size |
List of named vectors specifying sample size at level 2 (named |
var_names |
List of named character vectors indicating names for intercept ( |
x1_range |
Vector with min and max values for time variable (in that order: e.g. |
design_matrices |
List of five named lists, with each of the latter relating to a design matrix. These five lists are |
beta |
Vector containing coefficients of fixed effects for model for mean of y, in order of x0, x1. |
alpha |
Vector containing coefficients of fixed effects for level 1 variance function, in order of x0, x1. |
gamma |
Vector containing coefficients of fixed effects for model of distal outcome, in order of x0, x1, x2, x3. Defaults to |
distal_type |
Character vector specifying type for distal outcome: either |
sigma2e_distal |
Residual variance of distal outcome (applies when |
sigma2u |
Level 2 covariance matrix. E.g. |
log_sigma2e |
Logical vector indicating whether log link used for level 1 variance function ( |
linear_sigma2e_attempts |
Numerical vector (one element) corresponding to maximum number of attempts made to generate non-negative sigma2e (only applicable when |
random_seed |
Numerical vector indicating value of random seed to be set at outset. |
List containing simulated dataset (as simu_dataframe
), plus other relevant generated objects and user-defined parameters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | ## Not run:
library(windsimu)
## Level 2 random effect in level 1 variance function
## with this term also allowed to covary with random
## intercept & random slope in level 2 covariance matrix:
simu_u2j_covary <- windsimu(
sample_size = list(n2 = 1000, n1 = 9),
var_names = list(x0 = "cons", x1 = "age"),
x1_range = c(-1, 1),
design_matrices = list(
x_A = list(x0 = TRUE, x1 = TRUE),
z_A = list(x0 = TRUE, x1 = TRUE),
x_B = list(x0 = TRUE, x1 = TRUE),
z_B = list(x0 = TRUE, x1 = FALSE)
),
beta = c(150, 6.5),
alpha = c(-.95, 0.48),
sigma2u =
matrix(
c(93, 12, 2.5,
12, 3.8, 0.8,
2.5, 0.8, 0.4),
nrow = 3,
ncol = 3,
byrow = TRUE
),
log_sigma2e = TRUE,
linear_sigma2e_attempts = 10,
random_seed = 1
)
## inspect structure of returned object:
str(simu_u2j_covary)
## export simulated dataset (to current working directory) as .dta:
library(haven)
write_dta(simu_u2j_covary$simu_dataframe, "simu_u2j_covary.dta", version = 14)
## Level 2 random effect in level 1 variance function
## but covariance of this term set to 0 in level 2 covariance matrix:
simu_u2j_no_covary <- windsimu(
sample_size = list(n2 = 1000, n1 = 9),
var_names = list(x0 = "cons", x1 = "age"),
x1_range = c(-1, 1),
design_matrices = list(
x_A = list(x0 = TRUE, x1 = TRUE),
z_A = list(x0 = TRUE, x1 = TRUE),
x_B = list(x0 = TRUE, x1 = TRUE),
z_B = list(x0 = TRUE, x1 = FALSE)
),
beta = c(150, 6.5),
alpha = c(-.95, 0.48),
sigma2u =
matrix(
c(93, 12, 0,
12, 3.8, 0,
0, 0, 0.4),
nrow = 3,
ncol = 3,
byrow = TRUE
),
log_sigma2e = TRUE,
linear_sigma2e_attempts = 10,
random_seed = 1
)
## No additional level 2 random effect:
simu_no_u2j <- windsimu(
sample_size = list(n2 = 1000, n1 = 9),
var_names = list(x0 = "cons", x1 = "age"),
x1_range = c(-1, 1),
design_matrices = list(
x_A = list(x0 = TRUE, x1 = TRUE),
z_A = list(x0 = TRUE, x1 = TRUE),
x_B = list(x0 = TRUE, x1 = TRUE),
z_B = list(x0 = FALSE, x1 = FALSE)
),
beta = c(150, 6.5),
alpha = c(-.95, 0.48),
sigma2u =
matrix(
c(93, 12,
12, 3.8),
nrow = 2,
ncol = 2,
byrow = TRUE
),
log_sigma2e = TRUE,
linear_sigma2e_attempts = 10,
random_seed = 1
)
## No log link for level 1 variance function.
## Note age uncentred (level 1 variance function more likely
## to stay positive); also note linear_sigma2e_attempts:
simu_u2j_covary_linearL1varfun <- windsimu(
sample_size = list(n2 = 1000, n1 = 9),
var_names = list(x0 = "cons", x1 = "age"),
x1_range = c(11.25, 13.25),
design_matrices = list(
x_A = list(x0 = TRUE, x1 = TRUE),
z_A = list(x0 = TRUE, x1 = TRUE),
x_B = list(x0 = TRUE, x1 = TRUE),
z_B = list(x0 = TRUE, x1 = FALSE)
),
beta = c(150, 6.5),
alpha = c(-.95, 0.48),
sigma2u =
matrix(
c(93, 12, 2.5,
12, 3.8, 0.8,
2.5, 0.8, 0.4),
nrow = 3,
ncol = 3,
byrow = TRUE
),
log_sigma2e = FALSE,
linear_sigma2e_attempts = 100,
random_seed = 1
)
## As simu_u2j_covary (above), but with distal outcome;
## note x_C in design_matrices, and gamma:
simu_u2j_covary_distal <- windsimu(
sample_size = list(n2 = 1000, n1 = 9),
var_names = list(x0 = "cons", x1 = "age"),
x1_range = c(-1, 1),
design_matrices = list(
x_A = list(x0 = TRUE, x1 = TRUE),
z_A = list(x0 = TRUE, x1 = TRUE),
x_B = list(x0 = TRUE, x1 = TRUE),
z_B = list(x0 = TRUE, x1 = FALSE),
x_C = list(x0 = TRUE, x1 = TRUE, x2 = TRUE, x3 = TRUE)
),
beta = c(150, 6.5),
alpha = c(-.95, 0.48),
gamma = c(0.5, 0.2, 0.7, 1.4),
distal_type = "Continuous",
sigma2e_distal = 1,
sigma2u =
matrix(
c(93, 12, 2.5,
12, 3.8, 0.8,
2.5, 0.8, 0.4),
nrow = 3,
ncol = 3,
byrow = TRUE
),
log_sigma2e = TRUE,
linear_sigma2e_attempts = 10,
random_seed = 1
)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.