simDat: Function to simulate multivariate longitudinal data

Description Usage Arguments Value Examples

View source: R/simDat.R

Description

A function that simulates correlated multivariate data based on a set of fixed and random effects.

Usage

1
2
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 "normal" for multivariate normal or "50:50 normal" for a mixture of two normal distributions

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
}

Example output

Loading required package: gee
Loading required package: lme4
Loading required package: Matrix
Loading required package: MASS

MargCond documentation built on May 1, 2019, 8:46 p.m.

Related to simDat in MargCond...