sim_mediation_data: Simulate data for analysis.

View source: R/sim_mediation_data.R

sim_mediation_dataR Documentation

Simulate data for analysis.

Description

Simulate data for analysis.

Usage

sim_mediation_data(exp, sample_size, SC, bn = T)

Arguments

exp

For binary exposure, enter the exposure prevalence. For continuous exposure, enter the mean and sd of a normal distribution.

sample_size

Number of samples.

SC

A vector of parameters, in order of: b0, bw, bq, bs, a0, aw, aq, d0, dw, sigma_q, sigma_s, where Q=rnorm(sample_size,d0+dwW,sigma_q), S=rnorm(sample_size,a0+awW+aqQ,sigma_s), Y=ifelse(rnorm(sample_size,b0+bwW+bqQ+bsS,1)<0,0,1)

confounders

Confounder values.

Examples

para=c(rep(-0.5,9),1,1)
dat1=sim_mediation_data(0.5,1000,para) #binary exposure
apply(dat1,2,mean) #the proportion of Y should not be too skew (nearly 0 or 1)
dat2=sim_mediation_data(c(0,1),1000,para) #continous exposure

roqe/BY2M documentation built on March 24, 2024, 2:48 a.m.