zepid.causal.ipw.IPTW.StochasticIPTW

class zepid.causal.ipw.IPTW.StochasticIPTW(df, treatment, outcome, weights=None)

Calculates the IPTW estimate for stochastic treatment plans. StochasticIPTW will returns the estimated marginal outcome for that treatment plan. This is distinct from IPTW, which returns an array of weights. For confidence intervals, a bootstrapping procedure needs to be used.

The formula for IPTW for a stochastic treatment is

\[\pi_i = \frac{\overline{\Pr}(A=a|L)}{\Pr(A=a|L)}\]

where \(\bar{\Pr}\) is the new probability of treatment under the proposed stochastic treatment. This probability can be unconditional (everyone treated at some constant percent) or it can be conditional on observed covariates. The denominator is the same estimated probability of treatment in the standard IPTW formula. Basically, we are manipulating how many the treated individuals represent in a new pseudo-population

Note

StochasticIPTW estimates the marginal outcome at a specified treatment distribution. Unlike IPTW, it does not immediately result in a comparison between two treatment levels (i.e. we are not estimating a marginal structural model in this case). For a comparison, two different version would need to be specified.

StochasticIPTW does not contain the diagnostics that are contained within IPTW. This IPTW estimation approach makes weaker assumptions regarding positivity and causal consistency.

Parameters:
  • df (DataFrame) – Pandas dataframe object containing all variables of interest
  • treatment (str) – Variable name of treatment variable of interest. Must be coded as binary. 1 should indicate treatment, while 0 indicates no treatment
  • outcome (str) – Variable name of outcome variable of interest. May be binary or continuous.
  • weights (str, optional) – Optional column for weights. If specified, a weighted regression model is instead used to estimate the inverse probability of treatment weights. This optional is useful in the following scenario; some confounder information is missing and IPMW was used to correct for missing data. IPTW should be estimated with the IPMW to standardize to the correct pseudo-population.

Examples

Loading data

>>> from zepid import load_sample_data, spline
>>> from zepid.causal.ipw import StochasticIPTW
>>> df = load_sample_data(timevary=False).drop(columns=['cd4_wk45'])
>>> df[['cd4_rs1','cd4_rs2']] = spline(df,'cd40',n_knots=3,term=2,restricted=True)
>>> df[['age_rs1','age_rs2']] = spline(df,'age0',n_knots=3,term=2,restricted=True)

Estimating marginal outcome under treatment plan where 80% are randomly treated

>>> ipw = StochasticIPTW(df, treatment='art', outcome='dead')
>>> ipw.treatment_model('male + age0 + age_rs1 + age_rs2 + cd40 + cd4_rs1 + cd4_rs2 + dvl0')
>>> ipw.fit(p=0.8)
>>> ipw.summary()

Estimating marginal outcome under treatment plan where 10% are randomly treated

>>> ipw.fit(p=0.1)
>>> ipw.summary()

Estimating marginal outcome under treatment plan where 75% of men are treated and 90% of women

>>> ipw.fit(p=[0.75, 0.90], conditional=["df['male']==1", "df['male']==0"])
>>> ipw.summary()

References

Muñoz ID & van der Laan M. (2012). Population intervention causal effects based on stochastic interventions. Biometrics, 68(2), 541-549.

__init__(df, treatment, outcome, weights=None)

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(df, treatment, outcome[, weights]) Initialize self.
fit(p[, conditional]) Estimates the mean outcome under the specified stochastic treatment plan.As currently implemented, p percent of the population is randomly treated.
summary([decimal]) Prints the summary information for the marginal outcome under the treatment plan of interest.
treatment_model(model[, print_results]) Specify the parametric regression model for the observed treatment conditional on the sufficient adjustment set.