Package 'localIV'

Title: Estimation of Marginal Treatment Effects using Local Instrumental Variables
Description: In the generalized Roy model, the marginal treatment effect (MTE) can be used as a building block for constructing conventional causal parameters such as the average treatment effect (ATE) and the average treatment effect on the treated (ATT). Given a treatment selection equation and an outcome equation, the function mte() estimates the MTE via the semiparametric local instrumental variables method or the normal selection model. The function mte_at() evaluates MTE at different values of the latent resistance u with a given X = x, and the function mte_tilde_at() evaluates MTE projected onto the estimated propensity score. The function ace() estimates population-level average causal effects such as ATE, ATT, or the marginal policy relevant treatment effect.
Authors: Xiang Zhou [aut, cre]
Maintainer: Xiang Zhou <[email protected]>
License: GPL (>= 3)
Version: 0.3.1
Built: 2025-02-18 04:41:45 UTC
Source: https://github.com/xiangzhou09/localiv

Help Index


Estimating Average Causal Effects from a Fitted MTE Model.

Description

ace estimates Average Causal Effects (ACE) from a fitted MTE model. The estimand can be average treatment effect (ATE), average treatment effect on the treated (ATT), average treatment effect on the untreated (ATU), or the Marginal Policy Relevant Treatment Effect (MPRTE) defined in Zhou and Xie (2019).

Usage

ace(model, estimand = c("ate", "att", "atu", "mprte"), policy = 1)

Arguments

model

A fitted mte model returned by mte.

estimand

Type of estimand: "ate", "att", "atu", or "mprte".

policy

An expression written as a function of p. This is used only when estimand="mprte".

Value

Estimate of ATE, ATT, ATU, or MPRTE

References

Heckman, James J., Sergio Urzua, and Edward Vytlacil. 2006. "Understanding Instrumental Variables in Models with Essential Heterogeneity." The Review of Economics and Statistics 88:389-432.

Zhou, Xiang and Yu Xie. 2019. "Marginal Treatment Effects from A Propensity Score Perspective." Journal of Political Economy, 127(6): 3070-3084.

Zhou, Xiang and Yu Xie. 2020. "Heterogeneous Treatment Effects in the Presence of Self-selection: a Propensity Score Perspective." Sociological Methodology.

Examples

mod <- mte(selection = d ~ x + z, outcome = y ~ x,
  data = toydata)

ate <- ace(mod, "ate")
att <- ace(mod, "att")
atu <- ace(mod, "atu")
mprte1 <- ace(mod, "mprte")
mprte2 <- ace(mod, "mprte", policy = p)
mprte3 <- ace(mod, "mprte", policy = 1-p)
mprte4 <- ace(mod, "mprte", policy = I(p<0.25))
c(ate, att, atu, mprte1, mprte2, mprte3, mprte4)

Fitting a Marginal Treatment Effects (MTE) Model.

Description

mte fits a MTE model using either the semiparametric local instrumental variables (local IV) method or the normal selection model (Heckman, Urzua, Vytlacil 2006). The user supplies a formula for the treatment selection equation, a formula for the outcome equations, and a data frame containing all variables. The function returns an object of class mte. Observations that contain NA (either in selection or in outcome) are removed.

Usage

mte(
  selection,
  outcome,
  data = NULL,
  method = c("localIV", "normal"),
  bw = NULL
)

mte_localIV(mf_s, mf_o, bw = NULL)

mte_normal(mf_s, mf_o)

Arguments

selection

A formula representing the treatment selection equation.

outcome

A formula representing the outcome equations where the left hand side is the observed outcome and the right hand side includes predictors of both potential outcomes.

data

A data frame, list, or environment containing the variables in the model.

method

How to estimate the model: either "localIV" for the semiparametric local IV method or "normal" for the normal selection model.

bw

Bandwidth used for the local polynomial regression in the local IV approach. Default is 0.25.

mf_s

A model frame for the treatment selection equations returned by model.frame

mf_o

A model frame for the outcome equations returned by model.frame

Details

mte_localIV estimates MTE(x,u)\textup{MTE}(x, u) using the semiparametric local IV method, and mte_normal estimates MTE(x,u)\textup{MTE}(x, u) using the normal selection model.

Value

An object of class mte.

coefs

A list of coefficient estimates: gamma for the treatment selection equation, beta10 (intercept) and beta1 (slopes) for the baseline outcome equation, beta20 (intercept) and beta2 (slopes) for the treated outcome equation, and theta1 and theta2 for the error covariances when method = "normal".

ufun

A function representing the unobserved component of MTE(x,u)\textup{MTE}(x, u).

ps

Estimated propensity scores.

ps_model

The propensity score model, an object of class glm if method = "localIV", or an object of class selection if method = "normal".

mf_s

The model frame for the treatment selection equation.

mf_o

The model frame for the outcome equations.

complete_row

A logical vector indicating whether a row is complete (no missing variables) in the original data

call

The matched call.

References

Heckman, James J., Sergio Urzua, and Edward Vytlacil. 2006. "Understanding Instrumental Variables in Models with Essential Heterogeneity." The Review of Economics and Statistics 88:389-432.

See Also

mte_at for evaluating MTE at different values of the latent resistance uu; mte_tilde_at for evaluating MTE projected onto the propensity score; ace for estimating average causal effects from a fitted mte object.

Examples

mod <- mte(selection = d ~ x + z, outcome = y ~ x, data = toydata, bw = 0.25)

summary(mod$ps_model)
hist(mod$ps)

mte_vals <- mte_at(u = seq(0.05, 0.95, 0.1), model = mod)
if(require("ggplot2")){
  ggplot(mte_vals, aes(x = u, y = value)) +
  geom_line(size = 1) +
  xlab("Latent Resistance U") +
  ylab("Estimates of MTE at Mean Values of X") +
  theme_minimal(base_size = 14)
}

Evaluate Marginal Treatment Effects from a Fitted MTE Model.

Description

mte_at evaluates marginal treatment effects at different values of the latent resistance u with a given X=xX=x.

Usage

mte_at(x = NULL, u, model)

Arguments

x

Values of the pretreatment covariates at which MTE(x,u)\textup{MTE}(x, u) is evaluated. It should be a numeric vector whose length is one less than the number of columns of the design matrix XX in the outcome model. Default is the sample means.

u

A numeric vector. Values of the latent resistance uu at which MTE(x,u)\textup{MTE}(x, u) is evaluated. Note that the estimation involves extrapolation when the specified u values lie outside of the support of the propensity score.

model

A fitted MTE model returned by mte.

Value

mte_at returns a data frame.

u

input values of u.

x_comp

the x-component of the estimated MTE(x,u)\textup{MTE}(x, u)

u_comp

the u-component of the estimated MTE(x,u)\textup{MTE}(x, u)

value

estimated values of MTE(x,u)\textup{MTE}(x, u)

Examples

mod <- mte(selection = d ~ x + z, outcome = y ~ x, data = toydata)

mte_vals <- mte_at(u = seq(0.05, 0.95, 0.1), model = mod)
if(require("ggplot2")){
  ggplot(mte_vals, aes(x = u, y = value)) +
  geom_line(size = 1) +
  xlab("Latent Resistance U") +
  ylab("Estimates of MTE at Mean Values of X") +
  theme_minimal(base_size = 14)
}

Evaluate Marginal Treatment Effects Projected onto the Propensity Score

Description

mte_tilde_at evaluates marginal treatment effects projected onto the estimated propensity score. The projection is done via the function gam.

Usage

mte_tilde_at(p, u, model, ...)

Arguments

p

A numeric vector. Values of the propensity score at which MTE~(p,u)\widetilde{\textup{MTE}}(p, u) is evaluated.

u

A numeric vector. Values of the latent resistance at which MTE~(p,u)\widetilde{\textup{MTE}}(p, u) is evaluated.

model

A fitted MTE model returned by mte.

...

Additional parameters passed to gam.

Value

mte_tilde_at returns a list of two elements:

df

A data frame containing five columns:

  • p input values of p.

  • u input values of u.

  • p_comp the p-component of the estimated MTE~(p,u)\widetilde{\textup{MTE}}(p, u)

  • u_comp the u-component of the estimated MTE~(p,u)\widetilde{\textup{MTE}}(p, u)

  • value estimated values of MTE~(p,u)\widetilde{\textup{MTE}}(p, u)

proj

Fitted gam model for E[μ1(X)μ0(X)P(Z)=p]E[\mu_1(X)-\mu_0(X)|P(Z)=p]

References

Zhou, Xiang and Yu Xie. 2019. "Marginal Treatment Effects from A Propensity Score Perspective." Journal of Political Economy, 127(6): 3070-3084.

Zhou, Xiang and Yu Xie. 2020. "Heterogeneous Treatment Effects in the Presence of Self-selection: a Propensity Score Perspective." Sociological Methodology.

Examples

mod <- mte(selection = d ~ x + z, outcome = y ~ x, data = toydata)

u <- p <- seq(0.05, 0.95, 0.1)
mte_tilde <- mte_tilde_at(p, u, model = mod)

# heatmap showing MTE_tilde(p, u)
if(require("ggplot2")){
ggplot(mte_tilde$df, aes(x = u, y = p, fill = value)) +
  geom_tile() +
  scale_fill_gradient(name = expression(widetilde(MTE)(p, u)), low = "yellow", high = "blue") +
  xlab("Latent Resistance U") +
  ylab("Propensity Score p(Z)") +
  theme_minimal(base_size = 14)
}

mprte_tilde_df <- subset(mte_tilde$df, p == u)

# heatmap showing MPRTE_tilde(p)
if(require("ggplot2")){
ggplot(mprte_tilde_df, aes(x = u, y = p, fill = value)) +
  geom_tile() +
  scale_fill_gradient(name = expression(widetilde(MPRTE)(p)), low = "yellow", high = "blue") +
  xlab("Latent Resistance U") +
  ylab("Propensity Score p(Z)") +
  theme_minimal(base_size = 14)
}

# MPRTE_tilde(p) decomposed into the p-component and the u-component
if(require(tidyr) && require(dplyr) && require(ggplot2)){
mprte_tilde_df %>%
  pivot_longer(cols = c(u_comp, p_comp, value)) %>%
  mutate(name = recode_factor(name,
         `value` = "MPRTE(p)",
         `p_comp` = "p(Z) component",
         `u_comp` = "U component")) %>%
  ggplot(aes(x = p, y = value)) +
  geom_line(aes(linetype = name), size = 1) +
  scale_linetype(name = "") +
  xlab("Propensity Score p(Z)") +
  ylab("Treatment Effect") +
  theme_minimal(base_size = 14) +
  theme(legend.position = "bottom")
}

A Hypothetical Dataset for Illustrative Purpose

Description

A dataset containing 4 columns: y for a continuous outcome, d for a binary treatment, x for a pretreatment covariate, and z for an excluded instrument.

Usage

toydata

Format

An object of class data.frame with 10000 rows and 4 columns.