estimate_treatment_effect: Main treatment effect estimation function

Description Usage Arguments Details Value Examples

View source: R/treatment.R

Description

Main treatment effect estimation function

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
estimate_treatment_effect(
  data = NULL,
  aps = NULL,
  Y = NULL,
  Z = NULL,
  D = NULL,
  degen = c(0, 1),
  apslab = "APS",
  ylab = "Y",
  zlab = "Z",
  dlab = "D",
  estimator = "2SLS",
  verbose = T
)

Arguments

data

Dataset containing APS, Y, Z, and D data.

aps

Vector of APS values.

Y

Vector of outcome values.

Z

Vector of ML recommendation values.

D

Vector of treatment assignment values.

degen

Vector of values for which APS is degenerate. Defaults to c(0,1).

apslab

Column name of APS variable. Defaults to "APS".

ylab

Column name of Y variable. Defaults to "Y".

zlab

Column name of Z variable. Defaults to "Z".

dlab

Column name of D variable. Defaults to "D".

estimator

String method of IV estimation. Defaults to "2SLS".

verbose

Boolean indicator for whether to print summary output of estimation. Defaults to True.

Details

If the primary data vectors (aps, Y, Z, D) are not passed, then the fallback is to search for the _lab variables in the data object.

Treatment effect is estimated using IV estimation The default is to use the 2SLS method of estimation, with the equations illustrated below.

D_i = γ_0(1-I) + γ_1 Z_i + γ_2 p^s(X_i;δ) + v_i

Y_i = β_0(1-I) + β_1 D_i + β_2 p^s(X_i;δ) + ε_i

β_1 is our causal estimation of the treatment effect. I is an indicator for if the ML funtion takes only a single nondegenerate value in the sample.

Value

Fitted ivreg model object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Iris data
data("iris")
assign_cutoff <- function(X, cutoff){
  ret <- as.integer(X > cutoff)
  return(ret)
}
model <- lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width, data=iris)
aps <- estimate_aps(iris, model, xc = names(iris)[2:4],
          infer=FALSE, s=400, delta=0.8, fcn=assign_cutoff, cutoff=6)

# Can send treatment effect inputs in two different ways
Y_val <- iris$Sepal.Length
Z_val <- assign_cutoff(iris$Sepal.Length, 6)
D_val <- predict(model, iris)
iris[, Y := Y_val]
iris[, Z := Z_val]
iris[, D := D_val]
iris[, APS := aps]
estimate_treatment_effect(aps = aps, Y = Y_val, Z = Z_val, D = D_val)
estimate_treatment_effect(iris, apslab = "APS", ylab = "Sepal.Length", zlab = "Z",
                          dlab = "D")

factoryofthesun/r-IVaps documentation built on Dec. 20, 2021, 7:41 a.m.