med_bench.get_simulated_data
.simulate_data#
- simulate_data(n, rg, mis_spec_m=False, mis_spec_y=False, dim_x=1, dim_m=1, seed=None, type_m='binary', sigma_y=0.5, sigma_m=0.5, beta_t_factor=1, beta_m_factor=1)[source]#
Simulate data for mediation analysis
- Parameters:
n (
int
,) – Number of samples to generate.rg (RandomState instance,) – Controls the pseudo random number generator used to generate the data at fit time.
mis_spec_m (obj:bool,) – Whether the mediator generation is misspecified or not defaults to False
mis_spec_y (obj:bool,) – Whether the output model is misspecified or not defaults to False
dim_x (
int
, optional,) – Number of covariates in the input. Defaults to 1dim_m (
int
, optional,) – Number of mediatiors to generate. Defaults to 1seed (
int
or None, optional,) – Controls the pseudo random number generator used to generate the coefficients of the model. Pass an int for reproducible output across multiple function calls. Defaults to Nonetype_m (
str
,) – Whether the mediator is binary or continuous Defaults to ‘binary’,sigma_y (
float
,) – noise variance on outcome Defaults to 0.5,
- :param sigma_m
float
: noise variance on mediator Defaults to 0.5,
- :paramnoise variance on mediator
Defaults to 0.5,
- Parameters:
beta_t_factor (
float
,) – scaling factor on treatment effect, Defaults to 1,beta_m_factor (
float
,) – scaling factor on mediator, Defaults to 1,
- Returns:
x (ndarray of shape (n, dim_x)) – the simulated covariates
t (ndarray of shape (n, 1)) – the simulated treatment
m (ndarray of shape (n, dim_m)) – the simulated mediators
y (ndarray of shape (n, 1)) – the simulated outcome
total (
float
,) – the total simulated effecttheta_1 (
float
,) – the natural direct effect on the treated,theta_0 (
float
,) – the natural direct effect on the untreated,delta_1 (
float
,) – the natural indirect effect on the treated,delta_0 (
float
,) – the natural indirect effect on the untreated,p_t (ndarray of shape (n, 1),) – Propensity score
th_p_t_mx (ndarray of shape (n, 1),) – overlap