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.
gam_sandwich_cluster(b, cluster_id, freq = FALSE)A p x p covariance matrix.
Fitted GAM object (must not have class `"pffr"`).
Integer vector of length `nrow(model.matrix(b))` mapping each vectorized observation to its curve.
If `TRUE`, use frequentist sandwich (`B2 = 0`). If `FALSE` (default), use Bayesian sandwich (`B2 = Vp - Ve`).