Target library Documentation

Introduction

This library provides C++ classes for targeted inference and semi-parametric efficient estimators as well as bindings for python and R. The library also contains implementation of parametric models (including different discrete choice models) and model diagnostics tools.

Relevant models includes binary regression models with binary exposure and with nuisance models defined by additional covariates. Models for the relative risk and risk differences where examined by (Richardson et al 2017). Various missing data estimators and causal inference models (Bang & Robins 2005, Tsiatis 2006) also fits into this framework.

Documentation

The main documentation can be found here: https://targetlib.org/ (PDF version)

Examples

R

https://kkholst.github.io/targeted

1 library('targeted')
2 
3 # Simulation
4 m <- lvm(y[-2] ~ 1*x,
5  lp.target[1] ~ 1,
6  lp.nuisance[-1] ~ 2*x)
7 distribution(m, ~a) <- binomial.lvm('logit')
8 m <- binomial.rr(m, 'y', 'a', 'lp.target', 'lp.nuisance')
9 dd <- sim(m, 5e2, seed=1)
10 
11 # Double-robust estimator
12 summary(fit <- targeted::riskreg(y ~ a | 1 | x | x, data=dd, type="rr"))
13 #
14 # Relative risk model
15 # Response: y
16 # Exposure: a
17 #
18 # Estimate Std.Err 2.5% 97.5% P-value
19 # log(RR):
20 # (Intercept) 0.86136 0.11574 0.6345 1.08820 9.895e-14
21 # log(OP):
22 # (Intercept) -0.88518 0.22802 -1.3321 -0.43827 1.036e-04
23 # x 2.35193 0.28399 1.7953 2.90854 1.213e-16
24 # logit(Pr):
25 # (Intercept) -0.07873 0.08857 -0.2523 0.09485 3.740e-01
26 # x 0.02894 0.08291 -0.1336 0.19145 7.270e-01

Python

https://pypi.org/project/targeted/

1 import targeted as tg
2 from targeted.formula import riskreg
3 
4 d = tg.getdata()
5 val = riskreg(d, 'y~a', interaction='x', nuisance='x+z')
6 
7 print(val)
8 ## Riskreg. Estimate: [ 1.17486406 -0.23623467]

C++

https://www.targetlib.org/cppapi/

#include <target/target.h>
using namespace arma;
void main() {
...
targeted::RR<double> model(y, a, x1, x2, x3, p, w);
mat pp0 = model.TargetedBinary::pa();
mat U = model.score(false);
mat res = model.est(alpha);
}

Installation

This program may be compiled as a shared library or as stand-alone python and R libraries.

To compile and run the unit tests:

1 make test

Syntax checks (requires cppcheck and cclint), code coverage, and check for memory leaks

1 make check coverage
2 make valgrind

R

The R package can be built and installed with

1 make r

Python

The python package can be installed directly from PyPi (wheels available for Mac OS X and Linux):

1 pip install targeted

or installed from source

1 make py

Dependencies

The following dependencies are included as submodules:

  1. Armadillo http://arma.sourceforge.net/docs.html
  2. Catch2 (unit tests only) https://github.com/catchorg/Catch2/blob/master/docs/Readme.md#top
  3. pybind11++ (python bindings only) https://pybind11.readthedocs.io
  4. spdlog (logging) https://github.com/gabime/spdlog