Computes the sandwich meat in row blocks, optionally accumulating scores by cluster. Cluster storage is proportional to the number of distinct clusters times the number of coefficients. Streaming fits reread the source.

fastglm_vcov(
  object,
  type = c("HC3", "HC2", "HC1", "HC0"),
  cluster = NULL,
  cadjust = TRUE,
  block.size = 8192L,
  full = FALSE
)

Arguments

object

a fitted fastglm GLM, count, two-part, or ordinal model.

type

HC0, HC1, HC2, or HC3 correction. Cluster covariance, count, two-part, and ordinal models support HC0 and HC1. The default is HC3 for GLMs and HC0 for count, two-part, and ordinal models.

cluster

optional cluster identifiers; for streaming fits, a function of chunk index returning identifiers in the source row order. For dense ordinal fits, supply one identifier per retained row, or per row before missing-value omission after any formula subset. Each represented individual in a grouped frequency row belongs to that row's cluster; split the row if its members belong to different clusters. For ordinal sources, the callback is called once for each block and must return one identifier per original block row. The same identifier in different blocks denotes the same cluster. Numeric identifiers retain their full precision. Factors use their labels; other identifier types must remain consistent across positive-frequency blocks (integers and ordinary numeric vectors may be combined). Missing labels are allowed only for rows with zero effective frequency.

cadjust

multiply clustered covariance by G/(G-1).

block.size

maximum number of design rows processed at once.

full

include the estimated negative-binomial size parameter when applicable. Its covariance with the regression coefficients is included.

Value

A coefficient covariance matrix.

Details

For count and two-part models, the sandwich covariance uses joint estimating scores and the observed derivative of their sum. Cluster scores include both model components, so within-cluster dependence can produce nonzero covariance between them. The Gamma mean equation does not depend on dispersion; removing its common dispersion multiplier preserves the fitted mean parameters and their sandwich covariance. These approximations require independent observations, or independent clusters when supplied, and identifiable interior parameters. For GLM, count, and two-part models, sandwich covariance for bias-adjusted scores is not implemented.

Ordinal robust covariance supports dense, prepared, and repeatable source fits, with common and threshold-specific slopes jointly. Source fits reread the observations once without retaining the full design or response. The source determines the size of the loaded block; block.size limits the temporary calculations within that block. Cluster calculations retain one score vector and identifier per positive-frequency cluster. For ordinal fits, the covariance uses the inverse observed negative Jacobian of the ordinary likelihood score, rather than inverse expected Fisher information. Independent-observation meat sums individual score outer products linearly in the effective category frequencies. Cluster meat instead sums individual scores within each cluster before taking outer products. Thus a frequency row represents repeated independent individuals unless a cluster identifier groups them together. With total frequency \(N\), parameter count \(d\), and positive-frequency cluster count \(G\), HC1 multiplies independent covariance by \(N/(N-d)\) and cluster covariance by \((N-1)/(N-d)\); cadjust = TRUE additionally applies \(G/(G-1)\) to cluster covariance. Every declared category must have positive frequency, and the fit must have converged.

For mean-bias-reduced ordinal fits, this is explicitly a first-order ordinary-score sandwich evaluated at the bias-reduced estimate, not the covariance of the exact adjusted equations. Its asymptotic interpretation requires an interior regular limit, fixed parameter dimension, nonsingular limiting score derivative, an appropriate independent-observation or independent-cluster central limit theorem, and a score adjustment negligible relative to the square root of the sample size. Finite estimates under separation do not establish those conditions. This convention does not promise finite-sample calibration or bias reduction under misspecification. See fastglm_bootstrap() for refit-based uncertainty from retained-data fits; ordinal source bootstrapping remains unavailable.