imputed_outcomes: Imputed Potential Outcomes Accessor

View source: R/po-estimands.R

imputed_outcomesR Documentation

Imputed Potential Outcomes Accessor

Description

Returns the cell-level imputed potential-outcome surface from a fitted fect object as a long-form data frame. This is the rock-bottom accessor for any post-hoc estimand: read off the columns and aggregate however you like. Used internally by estimand for the shipped estimand types; exposed publicly so users can compose custom estimands the package does not ship.

Usage

imputed_outcomes(
  fit,
  cells = NULL,
  replicates = FALSE,
  direction = c("on", "off")
)

Arguments

fit

A fect object (output of fect).

cells

Optional filter on which treated cells to return. Accepts NULL (default; all treated cells), a logical vector aligned with the unfiltered row order, or a one-sided formula evaluated against the long-form data (e.g., ~ event.time %in% 1:5 & !id %in% bad_ids).

replicates

Logical. FALSE (default) returns one row per treated cell with the point-estimate Y0_hat. TRUE expands by bootstrap/jackknife replicate; requires the fit to have been built with keep.sims = TRUE.

direction

Either "on" (default; event time relative to treatment onset) or "off" (relative to treatment exit; only meaningful on reversal panels).

Value

A data frame with one row per treated cell or per (treated cell, replicate). Columns:

id

Unit identifier from fit$id.

time

Calendar time from fit$rawtime.

event.time

Event time at this cell (relative to onset or exit per direction).

cohort

First-treatment calendar time for the unit (direction = "on") or first-exit calendar time (direction = "off").

treated

Logical; always TRUE in returned rows.

Y_obs

Observed outcome at this cell.

Y0_hat

Imputed counterfactual outcome (Y_obs - eff).

eff

Cell-level score: contribution to the ATT estimator. For imputation estimators this equals Y_obs - Y0_hat; for doubly-robust estimators it equals (Y_obs - Y0_hat) + eff_debias.

eff_debias

Debias correction; 0 for plain imputation estimators, populated for DR estimators.

W.agg

Aggregation weight at this cell; 1 if the fit was built without W or W.agg.

replicate

(only when replicates = TRUE) 1..nboots for bootstrap, or the dropped-unit index for jackknife.

Memory cost

With replicates = TRUE the returned data frame has n_treated_cells * nboots rows. For typical panels this is manageable; for large panels (TT \times N \ge 50{,}000 and nboots \ge 500) consider filtering via cells before expansion.

Slot contract

This function reads from fit$Y.dat, fit$D.dat, fit$T.on (or T.off), fit$eff, fit$eff.boot (when replicates = TRUE), fit$eff_debias (when populated), fit$W.agg, fit$id, fit$rawtime. These slots have a documented stable shape; see the package design notes.

See Also

estimand for the typed dispatcher built on top of this accessor; fect for the fitting interface.

Examples

## Not run: 
library(fect)
fit <- fect(Y ~ D, data = simdata, index = c("id", "time"),
            method = "fe", force = "two-way",
            se = TRUE, nboots = 200, parallel = FALSE,
            keep.sims = TRUE)

## Point-estimate long form: one row per treated cell.
po <- imputed_outcomes(fit)
head(po)

## Filter to first 5 event times.
po5 <- imputed_outcomes(fit, cells = ~ event.time %in% 1:5)

## Bootstrap replicate expansion (requires keep.sims = TRUE).
po_b <- imputed_outcomes(fit, replicates = TRUE)
nrow(po_b) == nrow(po) * 200    # one row per (cell, replicate)

## End(Not run)

fect documentation built on April 30, 2026, 9:06 a.m.