API Reference: targeted

Submodules

targeted.riskreg module

class targeted.riskreg.riskreg(y, a, **kwargs)

Bases: object

Documentation for Riskreg

estimate = None
mle = None
mle_coef = None
model = None
modeltype = None
propensity = None
propensity_coef = None
targeted.riskreg.riskreg_mle(y, a, x2, *args, **kwargs)

Maximum Likelihood estimation of risk-regression model

The parameter of interest is either a risk difference or relative risk parameter with the effect of confounders decsribed on a log odds-product scale.

Parameters
  • y (list or numpy.array) – Response vector (0,1)

  • a (list or numpy.array) – Exposure vector (0,1)

  • x2 (numpy.array) – Design matrix for nuisance parameter regression (odds-product)

  • x1 (numpy.array, optional) – Design matrix for linear interactions with exposure ‘a’

  • w (list or numpy.array, optional) – Weights vector

  • type (str) – Relative risk: rr, Risk difference: rd

Returns

Riskreg object

Return type

Riskreg

References

Details behind the method can be found in 1.

1

Richardson, T. S., Robins, J. M., & Wang, L. (2017). On modeling and estimation for the relative risk and risk difference. Journal of the American Statistical Association, 112(519), 1121–1130. http://dx.doi.org/10.1080/01621459.2016.1192546

targeted module

targeted.data module

targeted.data.getdata(dataset: str = 'd', list: bool = False)

Load example data from the ‘targeted’ package

Parameters
  • filename (str) – Name of the filename of the data

  • list (bool) –

Examples

>>> # Surgical unit data
>>> targeted.getdata('surgunit').head()
   bloodclot  prognostic  enzyme  liver function  survival
0        6.7          62      81            2.59       200
1        5.1          59      66            1.70       101
2        7.4          57      83            2.16       204
3        6.5          73      41            2.01       101
4        7.8          65     115            4.30       509
>>> # Example data for risk-regression model
>>> targeted.getdata().head()
   y  a         x         z
0  0  0 -0.626454  1.134965
1  0  0  0.183643  1.111932
2  0  0 -0.835629 -0.870778
3  1  0  1.595281  0.210732
4  1  1  0.329508  0.069396
targeted.data.sim_bin(n=100.0, exposure=1, binary=True, p=1, rho=0.5, gamma=1.0, outcome_intercept=- 1.0, exposure_intercept=- 1.0)

Simulate data from linear model or logistic regression model with binary exposure

Parameters
  • n (int) – number of samples

  • exposure (float) – direct exposure effect (linear predictor scale)

  • p (int) – number of covariates/auxiliary variables

  • rho (float) – correlation between covariates

  • gamma (float) – effect of covariates on exposure (linear predictor scale)

  • outcome_intercept (float) – intercept of outcome model

  • exposure_intercept (float) – intercept of exposure model

Returns

DataFrame with: response y, exposure a, and covariates x1, x2, …

Return type

pandas.DataFrame

Examples

>>> import targeted
>>> from numpy import mean
>>> d = targeted.sim_bin(n=1e4, gamma=0)
>>> ey = lambda x: mean(d[d['a']==x]['y'])
>>> ey(1)-ey(0)  # Causal effect
-0.1973030984022366  # random

Notes

The model for the outcome is given by

\[g(\mathbb{E}[Y\mid A, X]) = \mu_Y + \theta A + \beta^T X\]

where \(g\) is either the identify function (binary=False) or the logit function (binary=True). The exposure effect \(\theta\) is controlled by the argument exposure.

The covariates are \(X\sim\mathcal{N}_p(0, \Sigma)\) where the covariance matrix \(\Sigma\) is a compound symmetry matrix with correlation \(\rho\) controlled by the argument rho.

For the exposure the model is given by

\[\operatorname{logit}(\mathbb{E}[A\mid X]) = \mu_A + \gamma^T X\]

The intercept terms \(\mu_Y\) and \(\mu_A\) are controlled by the arguments outcome_intercept and exposure_intercept.