README.md

PE

Helper functions to compute conditional probability and expectation from a data set. This can be used to calculate estimators in causal inference.

Limitation

The current version has only been tested on data containing binary variables.

Examples

The following two examples demonstrate the useage of this package. Note that the argument for the main functions, P() and E(), are designed so that the code will look identical to the mathematical expression. The package can be similarly applied to other estimators, such as natural indirect and direct effect, controlled direct effect, instramental variables, etc.

Standardization

Suppose we have a dataset containing binary variables Y, the treatment outcome; A, the treatment group; and C, a sufficient confounder. We can estimate the average treatment effect by,

Using the P() and E() functions from this package, this expression can be calculated with the following code:

E(Y | A == 1) - sum(E(Y | A == 0, C) * P(Y == 1| A == 0, C)))

Difference-in-difference

Suppose we have binary variables F, the pre-exposure outcome; D, the post-exposure outcome; and E an indicator for exposure. Assuming that additive equi-confounding holds with the pre-exposure outcome, that is,

then we can estimate the average effect of exposure in the exposed by,

Using the P() and E() functions from this package, this expression can be calculated with the following code:

(E(D | E == 1) - E(D | E == 0)) - (E(F | E == 1) - E(F | E == 0))

Installation

This package can be installed from GitHub using the devtools package:

# install.packages('devtools')
devtools::install_github('tgrimes/PE')


tgrimes/PE documentation built on Sept. 2, 2020, 2:49 p.m.