Estimation

class med_bench.estimation.mediation_coefficient_product.CoefficientProduct(regularize: bool, **kwargs)[source]

Coefficient Product estimatation method class

estimate(*args, **kwargs)
fit(t, m, x, y)[source]

Fits nuisance parameters to data

Parameters:
  • array-like (y) – treatment value for each unit, binary

  • (n_samples) (shape) – treatment value for each unit, binary

  • array-like – mediator value for each unit, here m is necessary binary and uni- dimensional

  • (n_samples) – mediator value for each unit, here m is necessary binary and uni- dimensional

  • array-like – covariates (potential confounders) values

  • (n_samples (shape) – covariates (potential confounders) values

  • n_features_covariates) – covariates (potential confounders) values

  • array-like – outcome value for each unit, continuous

  • (n_samples) – outcome value for each unit, continuous

class med_bench.estimation.mediation_g_computation.GComputation(regressor, classifier, **kwargs)[source]

GComputation estimation method class

estimate(*args, **kwargs)
fit(t, m, x, y)[source]

Fits nuisance parameters to data

class med_bench.estimation.mediation_ipw.InversePropensityWeighting(classifier, clip: float, trim: float, **kwargs)[source]

Inverse propensity weighting estimation method class

estimate(*args, **kwargs)
fit(t, m, x, y)[source]

Fits nuisance parameters to data

class med_bench.estimation.mediation_mr.MultiplyRobust(regressor, classifier, ratio: str, normalized, **kwargs)[source]

Iniitializes Multiply Robust estimatation method class

estimate(*args, **kwargs)
fit(t, m, x, y)[source]

Fits nuisance parameters to data

class med_bench.estimation.mediation_dml.DoubleMachineLearning(regressor, classifier, normalized: bool, **kwargs)[source]

Double Machine Learning estimation method class

estimate(t, m, x, y)[source]

Estimates causal effect on data

fit(t, m, x, y)[source]

Fits nuisance parameters to data

class med_bench.estimation.mediation_tmle.TMLE(regressor, classifier, ratio, **kwargs)[source]

Implementation of targeted maximum likelihood estimation method class

estimate(*args, **kwargs)
fit(t, m, x, y)[source]

Fits nuisance parameters to data

get_simulated_data

med_bench.get_simulated_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 1

  • dim_m (int, optional,) – Number of mediatiors to generate. Defaults to 1

  • seed (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 None

  • type_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 effect

  • theta_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