soft_impute_fe_cpp: Matrix Completion with Optional Two-Way Fixed Effects

View source: R/RcppExports.R

soft_impute_fe_cppR Documentation

Matrix Completion with Optional Two-Way Fixed Effects

Description

Solves ⁠min over L, a, b of (1/2) * squaredFrobenius(O o (Y - L - a1' - 1b')) + lambda * nuclearNorm(L)⁠ by alternating a back-fitting update of the fixed effects with one soft-thresholded SVD step for L (Mazumder, Hastie & Tibshirani 2010).

Usage

soft_impute_fe_cpp(
  Y,
  O,
  lambda,
  estimate_fe = TRUE,
  max_iter = 1000L,
  tol = 1e-05,
  fe_sweeps = 5L
)

Arguments

Y

Observed outcome matrix (T x N). Unobserved entries should be 0.

O

Binary mask matrix (T x N): 1 = observed, 0 = missing (treated post).

lambda

Nuclear norm penalty (soft-threshold on singular values).

estimate_fe

Estimate unpenalised row and column effects.

max_iter

Maximum iterations.

tol

Convergence tolerance (relative Frobenius norm change).

fe_sweeps

Back-fitting sweeps per iteration. The mask makes the two effects non-orthogonal, so one closed-form pass does not solve for both.

Details

The row and column effects are the unpenalised fixed effects of Athey et al. (2021, S.8.1): "we regularize the estimates of L*, but do not wish to regularize the estimates of the fixed effects". Leaving them inside L shrinks the panel's level towards zero along with its factor structure, which biases the imputed counterfactual whenever the level is far from zero. estimate_fe = false reproduces the S.4 baseline model Y = L + e.

Both effects absorb an additive constant, so a and b are identified only up to a shift between them; their sum, which is what enters the completed matrix, is unaffected.

Value

A list with L (the penalised low-rank part), a (row effects), b (column effects), and M, the completed matrix ⁠L + a 1' + 1 b'⁠.


coresynth documentation built on Oct. 11, 2026, 5:07 p.m.