Last chance! 50% off unlimited learning
Sale ends in
Last chance! 50% off unlimited learning
Sale ends in
This differs from what simulate_tvem_example does, in that each participant (subject) is only measured at a single measurement time, but the measurement time of each subject is random. This might simulate a sample of people of many different ages, where age is treated as a continuous number.
simulate_cross_sectional_tvem_example(
n_subjects = 300,
min_time = 7,
max_time = 7,
simulate_binary = FALSE,
sigma_x1 = 2,
sigma_x2 = 2,
truncate_for_realism = TRUE,
round_digits = 3,
sigma_y = 1.5,
mu_x1_function = function(t) {
6 - 2 * sqrt(pmax(0, ((t - min(t))/7) - 0.2))
},
mu_x2_function = function(t) {
3 + sqrt(pmax(0, ((t - min(t))/7) - 0.5))
},
beta0_y_function = function(t) {
1 - 0.3 * sqrt((t - min(t))/7)
},
beta1_y_function = function(t) {
0.5 * ((t - min(t))/7)^2
},
beta2_y_function = function(t) {
rep(0.2, length(t))
}
)
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
The time point at the end of the simulated time interval
Whether the simulated data should be binary
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
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
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.
set.seed(16802)
the_data <- simulate_tvem_example(simulate_binary=TRUE)
Run the code above in your browser using DataLab