By default, the data-generating model has a time-varying intercept, and two time-varying covariates named x1 and x2. x1 has a time-varying effect and x2 has a time-invariant effect.
simulate_tvem_example(
n_subjects = 300,
max_time = 7,
simulate_binary = FALSE,
n_obs_possible = 141,
prop_obs_observed = 0.3,
sigma_x1 = 2,
sigma_x2 = 2,
truncate_for_realism = TRUE,
round_digits = 3,
x1_short_term_rho = 0.7,
x2_short_term_rho = 0.7,
sigma_y = 1.5,
mu_x1_function = function(t) {
6 - 2 * sqrt(pmax(0, (t/7) - 0.2))
},
mu_x2_function = function(t) {
3 + sqrt(pmax(0, (t/7) - 0.5))
},
beta0_y_function = function(t) {
1 - 0.3 * sqrt(t/7)
},
beta1_y_function = function(t) {
0.5 * (t/7)^2
},
beta2_y_function = function(t) {
rep(0.2, length(t))
},
y_short_term_rho = 0.8
)
A simulated dataset with the following variables:
Subject ID
Observation time
First covariate
Second covariate
Outcome variable
Number of subjects in dataset
The time point at the end of the simulated time interval
Whether the simulated data should be binary
Total number of possible measurement times per subject
Proportion of these that are actually observed
Standard deviation of covariate 1, assumed homoskedastic over time
Standard deviation of covariate 2, assumed homoskedastic over time
Whether to prevent simulated values from going below 0 or above 10, in order to imitate survey data; used only for normally distributed outcomes. Set this to FALSE if you are running a simulation, in order to avoid losing coverage due to departing from the parametric model.
Number of digits at which to round the generated data; used only for normally distributed outcomes
Correlation between adjacent measurements of covariate 1
Correlation between adjacent measurements of covariate 2
Error standard deviation of y, only used if the outcomes are to be normal rather than binary
Mean of covariate 1 as function of time
Mean of covariate 2 as function of time
TVEM intercept as function of time
TVEM coefficient of covariate 1 as function of time
TVEM coefficient of covariate 2 as function of time
Correlation between adjacent measurements of y, only used if it is normal and not binary
set.seed(123)
the_data <- simulate_tvem_example(simulate_binary=TRUE)
Run the code above in your browser using DataLab