/SuperRiesz

R package for ensemble estimation of Riesz representers

Primary LanguageRGNU Affero General Public License v3.0AGPL-3.0

SuperRiesz

R package for ensemble estimation of Riesz Representers for a family of statistical functionals.

Installation

To install SuperRiesz directly from Github:

remotes::install_github("herbps10/SuperRiesz")

Mathematical Background

Suppose we observe data $O = (Y, X)$ where $Y$ is an outcome and $X$ a vector. Define the target parameter of interest as $\theta = \mathbb{E}[m(O, \bar{Q})]$ where $m$ is an arbitrary function and $\bar{Q}(X) = \mathbb{E}[Y \mid X]$.

If $\theta$ is a continuous linear functional of $\bar{Q}$, then by the Riesz Representation Theorem there exists a random variable $\alpha(X)$ such that, for all $f$ with $\mathbb{E}[f(X)^2] < \infty$,

$$ \mathbb{E}[m(O, f)] = \mathbb{E}[\alpha(X) f(X)]. $$

The random variable $\alpha(X)$ is called the Riesz Representer of $\theta$. This package estimates the Riesz Representer $\alpha$ by solving the minimization problem

$$ \hat{\alpha} = \arg\min_{\alpha \in \mathcal{A}} \frac{1}{n} \sum_{i=1}^n \alpha(X_i)^2-2 m(O_i, \alpha). $$

For more details, RieszNet and ForestRiesz: Automatic Debiased Machine Learning with Neural Nets and Random Forests by Chernozhukov et al. (2022) has a nice overview of the theory. See also Automatic Debiased Machine Learning via Riesz Regression by Chernozhukov et al. (2021).

Usage

The primary function is super_riesz.

Arguments:

  • data: data frame containing all observations.
  • alternatives: named list containing any alternative versions of the dataset.
  • library: vector or list of candidate learners.
  • m: function defining the parameter mapping.
  • folds: number of cross-validation folds (default = 5)

Example

Estimate the Riesz Representer for the Average Treatment Effect: $\theta = \mathbb{E}[\mathbb{E}[Y \mid A = 1, W]] - \mathbb{E}[Y \mid A = 0, W]]$. Define $\bar{Q}(A, W) = \mathbb{E}[Y \mid A, W]$. Then $m(O, \bar{Q}) = \bar{Q}(1, W) - \bar{Q}(0, W)$.

# Simulate data
library(tidyverse)
N <- 1e3

set.seed(152)
data <- tibble(
  W = runif(N, -1, 1),
  A = rbinom(N, 1, plogis(W)),
  Y = rnorm(N, mean = W + A, sd = 0.5)
)

vars <- c("W", "A")
m <- \(alpha, data) alpha(data("treatment")) - alpha(data("control"))
fit <- super_riesz(
  data[, vars], 
  list(
    "control" = mutate(data[, vars], A = 0),
    "treatment" = mutate(data[, vars], A = 1)
  ),
  library = c("linear", "nn"), 
  m = m
)

predict(fit, data[, vars])

Learners

constant

Learner that always returns a constant

Parameters:

  • constant: constant to return

glm

Linear learner based on optim.

Parameters:

  • constrain_positive: whether to constrain predictions to be positive (true or false)

torch

General neural network learner based on torch

Parameters:

  • architecture: function which has a single parameter, the input dimension, and returns a torch neural network architecture.
  • learning_rate: learning rate (positive float)
  • epochs: number of training epochs (integer)
  • verbose: logical
  • seed: torch random seed (optional)

nn

Simple neural network learner based on torch.

Parameters:

  • hidden: number of neurons in each hidden layer (integer)
  • layers: number of layers (integer)
  • learning_rate: training learning rate (positive float)
  • epochs: number of training epochs (integer)
  • dropout: dropout in hidden layer during training (float between 0 and 1)
  • constrain_positive: whether to constrain predictions to be positive (true or false)
  • verbose: logical
  • seed: torch random seed (optional)

linear

Linear model learner based on torch

Parameters:

  • learning_rate: training learning rate (positive float)
  • epochs: number of training epochs (integer)