fect_mspe: Mean Squared Prediction Error Evaluation for fect Objects

View source: R/fect_mspe.R

fect_mspeR Documentation

Mean Squared Prediction Error Evaluation for fect Objects

Description

Evaluates the prediction accuracy of one or more fect model fits by hiding a subset of control observations and comparing counterfactual predictions against actual values.

Usage

fect_mspe(
  out.fect,
  seed = NULL,
  cv.method = "rolling",
  cv.nobs = 3,
  cv.donut = 1,
  cv.buffer = 1,
  cv.prop = 0.1,
  min.T0 = 5,
  k = 20,
  criterion = "mspe",
  W = NULL,
  norm.para = NULL,
  proportion = 0
)

Arguments

out.fect

A fitted fect object or a named list of fitted fect objects to compare.

seed

Optional integer; random seed for reproducibility.

cv.method

Character; cross-validation masking strategy. One of "rolling" (default), "block" (random scattered anchors with contiguous-block masking), or "loo". Legacy aliases "all_units" (= "block") and "treated_units" are still accepted but emit a deprecation message.

cv.nobs

Integer; number of observations to mask per unit per fold. Default is 3.

cv.donut

Integer; number of periods around treatment onset to exclude from masking. Used by block CV. Default is 1.

cv.buffer

Integer; number of past-side cells masked from training (but not scored) before each rolling-window holdout. Used only by cv.method = "rolling". Default is 1.

cv.prop

Numeric; for block CV, proportion of observations to mask per round; for rolling CV, fraction of eligible units sampled per fold. Default is 0.2.

min.T0

Integer; minimum number of pre-treatment periods required. Default is 5.

k

Integer; number of cross-validation folds. Default is 5.

criterion

Character; scoring criterion. One of "mspe", "wmspe", "gmspe", "wgmspe", "mad", "moment", "gmoment". Default is "mspe".

W

Optional TT x N observation weight matrix. Default is NULL.

norm.para

Optional normalization vector. Default is NULL.

proportion

Numeric; proportion cutoff for count.T.cv (same as fect_cv). Default is 0.

Value

A list containing:

summary

A data frame with mean scores across replications for each model, including MSPE, WMSPE, GMSPE, WGMSPE, MAD, Moment, GMoment, RMSE, and Bias.

records

A data frame with per-replication results including Rep, Model, Hidden_N, and all score columns.

fits

The refitted fect objects from the last replication.

criterion

The scoring criterion used.

scores

The scores from the last replication.

Examples

## Not run: 
out <- fect(Y ~ D, data = df, index = c("unit", "time"), method = "ife", r = 2)
mspe <- fect_mspe(out.fect = out, hide_n = 10, seed = 42, n_rep = 5)
mspe$summary

## End(Not run)

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