simDat {MargCond} | R Documentation |
Function to simulate multivariate longitudinal data
Description
A function that simulates correlated multivariate data based on a set of fixed and random effects.
Usage
simDat(n, fixed_effects, rand_effects, error_var = c(2, 2),
error_structure = "normal", rho = 0, times = 1:5, X = NULL, Z = NULL)
Arguments
n |
total sample size (number of clusters) |
fixed_effects |
list of fixed effect vectors for each outcome |
rand_effects |
list of random effect vectors for each outcome |
error_var |
vector of error variances for each outcome |
error_structure |
structure for the random error term, either |
rho |
correlation between outcomes |
times |
times for each repeated measure |
X |
fixed effect design matrix |
Z |
random effect design matrix |
Value
A dataframe included simulated outcomes and the design matrices
Examples
set.seed(2112)
NN = 80
n_times = 1:3
## Simulating some data
simdat <- simDat(n = NN,
fixed_effects = list(c(1, 1, 2), c(1.5, 1, 3)),
rand_effects = list(1, 1),
error_var = c(4, 4),
error_structure = 'normal',
rho = .35,
times = n_times,
X = cbind(rep(1, NN * length(n_times)),
rnorm(NN * length(n_times), 0, 2),
rbinom(NN * length(n_times), 1, .5)),
Z = cbind(rep(1, NN * length(n_times))))
## Adding random missing values
aa <- sample(1:nrow(simdat), 10, replace = TRUE)
bb <- sample(1:7, 10, replace = TRUE)
for (i in 1:length(aa)) {
simdat[aa[i], bb[i]] <- NA
}
[Package MargCond version 1.0.0 Index]