Package 'MDEI'

Title: Implementing the Method of Direct Estimation and Inference
Description: Causal and statistical inference on an arbitrary treatment effect curve requires care in both estimation and inference. This package, implements the Method of Direct Estimation and Inference as introduced in "Estimation and Inference on Nonlinear and Heterogeneous Effects" by Ratkovic and Tingley (2023) <doi:10.1086/723811>. The method takes an outcome, variable of theoretical interest (treatment), and set of variables and then returns a partial derivative (marginal effect) of the treatment variable at each point along with uncertainty intervals. The approach offers two advances. First, a split-sample approach is used as a guard against over-fitting. Second, the method uses a data-driven interval derived from conformal inference, rather than relying on a normality assumption on the error terms.
Authors: Marc Ratkovic [aut, cre], Dustin Tingley [ctb], Nithin Kavi [aut]
Maintainer: Marc Ratkovic <[email protected]>
License: GPL (>= 2)
Version: 1.0
Built: 2024-11-17 06:42:31 UTC
Source: CRAN

Help Index


MDEI

Description

MDEI estimates effects.

Author(s)

Maintainer: Marc Ratkovic [email protected]

Authors:

Other contributors:


Coverage Plot for MDEI Object

Description

Coverage Plot for MDEI Object

Usage

coverPlot(
  object,
  xvar = "treat",
  sigval = 0,
  target = "tau",
  colors = c(gray(0.7), gray(0)),
  cex.point = 0.5,
  xlabel = "",
  ylabel = "",
  ...
)

Arguments

object

An object of class MDEI.

xvar

The variable to plot along the x-axis. May be 'treat' for the treatment variable, the name of a column in the covariate matrix in the obj, or a numeric vector, the length of the data. Default is "treat".

sigval

The value to see if it is covered by the conformal interval. Either a single value or a vector. Default is 0.

target

Either tau' or 'theta'. The first, 'tau', is the marginal effect at each point, while the second 'theta', is the portion of the conditional mean of the outcome that is a function of the treatment and the outcome.

colors

A vector with two elements. The first is the color of the confidence interval at points where the conformal interval does not contain sigval, the second the color where it does. Default is c(gray(.7), gray(0)).

cex.point

The size of the points in the figure. Default is 0.5.

xlabel

Label for x-axis of figure. Default is "".

ylabel

Label for y-axis of figure. Default is "".

...

Additional arguments to be passed to plot.

Value

No return value.


MDEI function

Description

Implements the Method of Direct Estimation and Inference

Usage

MDEI(
  y,
  treat,
  X,
  splits = 10,
  alpha = 0.9,
  samplesplit = TRUE,
  conformal = TRUE,
  nthreads.ranger = NULL,
  verbose = TRUE
)

Arguments

y

The outcome variable, a vector.

treat

The treatment variable, a vector.

X

A matrix of covariates.

splits

Number of repeated cross-fitting steps to implement.

alpha

The desired level of the confidence band.

samplesplit

Whether to use a sample splitting approach. Default is TRUE.

conformal

Whether to generate a conformal bands or use a critical value from the normal approximation. Default is TRUE..

nthreads.ranger

Number of threads used internally by the ranger function for random forests. Default is NULL.

verbose

An optional logical value. If TRUE information on the number of split samples completed is printed. Default is TRUE.

Value

tau.est

The estimated marginal effect.

CIs.tau

Upper and lower values of conformal confidence band.

critical.values

Conformal critical values.

Ey.x

Mean of outcome given only covariates.

coefficients

The list of all nonparametric bases and the proportion of sample splits that they were selected.

internal

Internal objects used for development and diagnostics.

References

Ratkovic, Marc and Dustin Tingley. 2023. "Estimation and Inference on Nonlinear and Heterogeneous Effects." The Journal of Politics.

Examples

n <- 100

X <- matrix(rnorm(n*1), nrow = n)
treat <- rnorm(n)
y <- treat^2 + X[,1] + rnorm(n)

# Be sure to run with more splits than this.  We recommend
# at least 10-50 initially, for exploratory analyses, with several hundred for 
# publication quality. For large sample sizes, these numbers may be adjusted down.
# These are only recommendations.
# Threads are set to 1 to pass CRAN checks, but we suggest leaving it at the default
# which ranger takse as the total number available.
set.seed(1)
m1 <- MDEI(y, treat, X, splits=1, alpha=.9, nthreads.ranger = 1)

# Accuracy
cor(m1$tau.est, treat*2)
cor(m1$theta.est, treat^2)

# Coverage
mean(apply(m1$CIs.tau-2*treat,1,prod)<0)

Summary of an MDEI Object

Description

Summary of an object of class MDEI.

Usage

## S3 method for class 'MDEI'
summary(object, features = 10, ...)

Arguments

object

An object of class MDEI.

features

Number of spline bases to include.

...

Additional arguments to be passed to plot.

Value

coeftable

A table with three columns: the names of selected spline interactions, the average coefficient, and proportion of time it was included in the model. Averages over taken over subsamples in the split sample strategy.Note that the coefficients are interactions between spline interactions that can be accessed through obj$internal$Xmat.spline.