propensity_score: Calculate propensity scores.

Description Usage Arguments Value References Examples

View source: R/propensity.R

Description

Function that calculates propensity scores with an option to check calibration and overlap assumptions

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
propensity_score(
  data,
  x,
  y,
  w,
  subset = FALSE,
  model = "logistic",
  trim = FALSE,
  plot = TRUE,
  ...
)

Arguments

data

a dataframe object containing the variables and values.

x

a list of character vectors specifying variables to be included in the model (columns in the data). If unspecified, then it is assumed to be all columns in the data besides y and w.

y

a character vector specifying the response variable.

w

a character vector specifying the treatment variable. Treatment must be specified as 0 and 1 or TRUE and FALSE.

subset

an optional vector specifying a subset of observations to be used in the fitting process.

model

a character string naming the model used (one of "logistic", "lasso", or "causal forest").

trim

a list of two numeric elements describing cutoffs at which to trim propensity scores.

plot

logical; if TRUE then produces histogram of propensity scores to check that the overlap assumption is satisfied and a Q-Q plot to check the calibration.

...

additional arguments to be passed to the model fitting functions.

Value

a vector of propensity scores where the indices of the vector correspond to the indices in data.

References

Imbens, Guido, and Donald Rubin. Causal Inference for Statistics, Social, and Biomedical Sciences: An Introduction. Cambridge University Press, 2015.

Examples

1
2
3
4
data(lalonde)
logit_propensities <- propensity_score(lalonde, y = "re78", w = "treat", model = "logistic")
lasso_propensities <- propensity_score(lalonde, y = "re78", w = "treat", model = "lasso")
cf_propensities <- propensity_score(lalonde, y = "re78", w = "treat", model = "causal forest")

jackcollison/causality documentation built on Dec. 20, 2021, 8:05 p.m.