Learn R Programming

refund (version 0.1-40)

gam_sandwich_cluster: Cluster-robust sandwich covariance estimator

Description

Computes a cluster-robust (CR1) sandwich covariance matrix for a fitted GAM, clustering by curve. Handles both heteroskedasticity and within-curve autocorrelation, requiring only that curves are independent.

Usage

gam_sandwich_cluster(b, cluster_id, freq = FALSE)

Value

A p x p covariance matrix.

Arguments

b

Fitted GAM object (must not have class `"pffr"`).

cluster_id

Integer vector of length `nrow(model.matrix(b))` mapping each vectorized observation to its curve.

freq

If `TRUE`, use frequentist sandwich (`B2 = 0`). If `FALSE` (default), use Bayesian sandwich (`B2 = Vp - Ve`).