Quickstart

Installation

Install with pip:

pip install targeted

Note

Presently binary wheels are available for Linux systems and Mac OS X running Python>=3.6. Windows installations must be built from source.

Risk regression

As an illustration data is loaded from the package

In [1]: import targeted as tg

In [2]: d = tg.getdata() # returns a Pandas DataFrame

In [3]: print(d.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

Here y is the binary response variable, a binary the exposure, and x, z covariates.

Next we estimate the risk difference of the exposed vs the non-exposed

In [4]: import numpy as np

In [5]: from patsy import dmatrices

In [6]: y, X = dmatrices('y ~ x+z', d)

In [7]: a = d['a']

In [8]: ones = np.ones((y.size,1))

In [9]: tg.riskreg(y=y, a=a, x1=ones, x2=X)
Out[9]: Riskreg. Estimate: [1.02819001]

Or using the formula syntax:

In [10]: from targeted.formula import riskreg

In [11]: riskreg(d, 'y~a')
Out[11]: Riskreg. Estimate: [1.49101228]