This vignette explains the
methodology behind the HC covariance estimators implemented in
hcinfer. It is written for users who want to understand
what the estimators correct, why leverage matters, and how HCbeta is
constructed.
The focus is methodological rather than procedural. For a usage
oriented introduction, see
vignette("introduction", package = "hcinfer"). For code
that compares estimators on one fitted model, see
vignette("hcinfer-comparison", package = "hcinfer").
Consider the linear regression model
\[ y = X \beta + e, \]
where \(y\) is an \(n \times 1\) response vector, \(X\) is an \(n \times p\) design matrix with full column rank and \(p < n\), \(\beta\) is a \(p \times 1\) parameter vector, and the errors satisfy \(E(e_t) = 0\) and \(\operatorname{Var}(e_t) = \sigma_t^2\). The error covariance matrix is
\[ \Omega = \operatorname{diag}(\sigma_1^2, \ldots, \sigma_n^2). \]
The ordinary least squares estimator is
\[ \hat\beta = (X'X)^{-1} X'y. \]
The covariance matrix that drives tests and confidence intervals is
\[ \Psi = \operatorname{Var}(\hat\beta) = (X'X)^{-1} X' \Omega X (X'X)^{-1}. \]
Under homoskedasticity, \(\Omega = \sigma^2 I_n\) and the target reduces to the usual scalar variance estimator times \((X'X)^{-1}\). Under heteroskedasticity, the diagonal entries of \(\Omega\) can differ across observations. The classical homoskedastic formula is then no longer appropriate for inference.
The difficulty is that \(\Omega\) contains \(n\) unknown variances but there is only one observation at each index. HC estimators avoid modeling the variance function directly. They estimate the aggregate quantity \(X' \Omega X\) through a weighted residual outer product.
The HC covariance estimators in hcinfer share the same
sandwich structure:
\[ \widehat\Psi_{HC} = (X'X)^{-1} X' \widehat\Omega X (X'X)^{-1}, \qquad \widehat\Omega = \operatorname{diag}(\hat e_t^2 g_t), \]
where \(\hat e_t = y_t - x_t'\hat\beta\) is the OLS residual and \(g_t\) is an adjustment factor. The methods differ in the definition of \(g_t\), except HC0R, described below, which keeps \(g_t = 1\) and replaces \(\hat e_t\) by robust residuals.
The role of \(g_t\) is to correct the fact that squared OLS residuals tend to be too small as estimates of local error variances. That shrinkage is tied to leverage.
The hat matrix is
\[ H = X(X'X)^{-1}X', \qquad \hat y = Hy, \qquad \hat e = (I_n - H)y. \]
Only the diagonal of \(H\) enters the HC adjustment factors. The leverage of observation \(t\) is
\[ h_t = H_{tt} = x_t'(X'X)^{-1}x_t, \qquad 0 \leq h_t \leq 1. \]
The average leverage is
\[ \bar h = p / n. \]
Leverage is a property of the design matrix. It measures how unusual the regressor vector \(x_t\) is relative to the fitted design. It is computed before looking at the response values.
This is distinct from influence. An observation is influential when its removal substantially changes the fitted coefficients. Influence depends on both leverage and the response value. HC covariance estimators focus on leverage because the residual shrinkage they correct is a geometric property of the OLS projection.
The OLS residual vector is obtained by projecting \(y\) with \(I_n - H\). For the diagonal terms, a useful approximation is
\[ E(\hat e_t^2) \approx (1 - h_t)\sigma_t^2. \]
Thus \(\hat e_t^2\) tends to capture only a fraction \(1 - h_t\) of the local error variance. When leverage is large, the fitted value is pulled toward the observed response at that design point, and the residual is compressed.
The figure below shows the approximation as a function of \(h_t\).
compression <- data.frame(
leverage = seq(0, 0.9, length.out = 100)
)
compression$fraction <- 1 - compression$leverage
high_leverage_point <- data.frame(
leverage = 0.65,
fraction = 0.35
)
ggplot2::ggplot(compression, ggplot2::aes(x = leverage, y = fraction)) +
ggplot2::geom_line(color = "#2c5f8a", linewidth = 1) +
ggplot2::geom_point(
data = high_leverage_point,
color = "#c0392b",
size = 2.6
) +
ggplot2::annotate(
"text",
x = 0.65,
y = 0.42,
label = "h[t] == 0.65",
parse = TRUE,
hjust = 0.5,
color = "#7f1d1d"
) +
ggplot2::scale_x_continuous(limits = c(0, 0.9)) +
ggplot2::scale_y_continuous(limits = c(0, 1)) +
ggplot2::labs(
x = expression(h[t]),
y = expression("Approximate fraction captured, " * 1 - h[t])
) +
ggplot2::theme_minimal(base_size = 12)This is why HC estimators use leverage even when the analyst is not doing an influence analysis. The adjustment concerns the expected size of the squared residual, not the decision to keep or remove an observation.
The supported classical estimators can be described by their adjustment factors \(g_t\). Let \(u_t = 1 - h_t\) and \(h_{max} = \max(h_1, \ldots, h_n)\).
The main formulas are:
\[ \begin{aligned} HC0: \quad & g_t = 1, \\ HC1: \quad & g_t = \frac{n}{n - p}, \\ HC2: \quad & g_t = \frac{1}{1 - h_t}, \\ HC3: \quad & g_t = \frac{1}{(1 - h_t)^2}, \\ HC4: \quad & g_t = (1 - h_t)^{-\delta_t}, \quad \delta_t = \min\left(4, \frac{h_t}{\bar h}\right), \\ HC4m: \quad & g_t = (1 - h_t)^{-\delta_t}, \quad \delta_t = \min\left(1, \frac{h_t}{\bar h}\right) + \min\left(1.5, \frac{h_t}{\bar h}\right). \end{aligned} \]
HC0 uses the squared residuals without a leverage correction. HC1 adds a degrees of freedom scale factor. HC2 corrects the leading leverage term. HC3 uses a stronger correction related to leave one out reasoning. HC4 and HC4m adapt the exponent to the leverage relative to its average.
HC5 and HC5m target high leverage designs more directly. In
hcinfer, the HC5 adjustment follows the corrected
expression given in the erratum to Cribari-Neto, Souza and Vasconcellos
(2007),
\[ g_t = (1 - h_t)^{-\delta_t / 2}, \qquad \delta_t = \min\left( \frac{h_t}{\bar h}, \max\left(4, k \frac{h_{max}}{\bar h}\right) \right), \qquad k = 0.7. \]
The HC5m adjustment combines the HC4m structure with the HC5 term and applies the resulting exponent without the factor \(1/2\):
\[ \begin{aligned} g_t &= (1 - h_t)^{-\delta_t}, \\ \delta_t &= k_1 \min\left(\gamma_1, \frac{h_t}{\bar h}\right) + k_2 \min\left(\gamma_2, \frac{h_t}{\bar h}\right) \\ &\quad + k_3 \min\left( \frac{h_t}{\bar h}, \max\left(4, k \frac{h_{max}}{\bar h}\right) \right), \end{aligned} \]
with defaults \(k = 0.7\), \(k_1 = 1\), \(k_2 = 0\), \(k_3 = 1\), \(\gamma_1 = 1\), and \(\gamma_2 = 1.5\).
These constants are exposed through ... in
vcov_hc() and hcinfer(). They should usually
be left at their defaults unless the analysis is explicitly a
sensitivity check or a methodological comparison.
HC0R addresses residual compression by changing the residuals rather
than the adjustment factor. Lima, Souza, Cribari-Neto and Fernandes
(2010) proposed computing HC0 with residuals from a high-breakdown fit.
A few atypical observations can pull the OLS fit toward themselves and
shrink their own residuals; a high-breakdown fit is less sensitive to
those observations. HC0R uses least median of squares (LMS) regression
(Rousseeuw 1984). The name HC0R is the label used by
hcinfer for the estimator that Lima et al. (2010) report as
HC0 with LMS residuals; in their paper, the symbol \(HC0_R\) denotes a different, weighted least
squares version of HC0.
For a candidate coefficient vector \(b\), order the squared residuals \((y_t - x_t'b)^2\) from smallest to
largest. Denote the \(m\)-th value by
\(r^2_{(m)}(b)\). The LMS estimator
minimizes \(r^2_{(m)}(b)\), with \(m\) chosen as in
MASS::lqs():
\[ \hat\beta_{LMS} = \arg\min_b r^2_{(m)}(b), \qquad m = \left\lfloor\frac{n + 1}{2}\right\rfloor. \]
For odd \(n\), the objective is the median squared residual; for even \(n\), it is the lower of the two middle squared residuals. HC0R uses the resulting residuals \(\tilde e_t = y_t - x_t'\hat\beta_{LMS}\) in place of the OLS residuals. Setting \(g_t = 1\) gives the covariance estimator
\[ \widehat\Psi_{HC0R} = (X'X)^{-1} X' \operatorname{diag}(\tilde e_t^2) X (X'X)^{-1}. \]
Both copies of \((X'X)^{-1}\) still come from the OLS fit. Tests also retain the OLS coefficient estimates; the LMS fit enters only through the residuals in the diagonal matrix. Because HC0R does not divide by \(1 - h_t\), its covariance formula remains defined at \(h_t = 1\). The LMS fit itself, however, needs nonsingular elemental subsets, which become rare when the model contains several observation-specific dummy regressors.
MASS::lqs(method = "lms") approximates the LMS minimizer
by evaluating the criterion at the exact fits to elemental subsets of
\(p\) observations and, when the model
has an intercept, by re-optimizing the intercept for each subset. It
examines every subset when \(\binom{n}{p} <
5000\); otherwise it samples \(\min(500p, 3000)\) subsets at random. The
default seed = 1 fixes this sample, which
hcinfer draws with R’s default random number generators
whatever RNGkind() the session uses, and the caller’s
random number stream is restored after the fit. Choosing another
seed shows how much the standard errors depend on which
subsets were sampled.
Large leverage can make powers of \(1 - h_t\) very small. Since the HC factors divide by these powers, the adjustment can become much larger than the residual compression it was meant to correct. This can inflate standard errors and move the inference too far in the opposite direction from HC0.
The pattern is visible in the public schools example used throughout the package.
library(hcinfer)
schools <- PublicSchools
schools$income_scaled <- schools$income / 10000
schools$income_scaled_sq <- schools$income_scaled^2
fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools)
methods <- c("hc3", "hc4", "hc4m", "hcbeta")
weight_data <- lapply(methods, function(method) {
cov <- vcov_hc(fit, type = method)
data.frame(
method = cov$label,
leverage = unname(cov$leverage),
weight = unname(cov$weights)
)
})
weight_data <- do.call(rbind, weight_data)
weight_data$method <- factor(
weight_data$method,
levels = c("HC3", "HC4", "HC4m", "HCbeta")
)
ggplot2::ggplot(weight_data, ggplot2::aes(x = leverage, y = weight)) +
ggplot2::geom_point(color = "#2c5f8a", alpha = 0.85, size = 1.8) +
ggplot2::facet_wrap(~method, scales = "free_y", ncol = 2) +
ggplot2::labs(
x = expression(h[t]),
y = expression(g[t])
) +
ggplot2::theme_minimal(base_size = 12) +
ggplot2::theme(
panel.grid.minor = ggplot2::element_blank(),
strip.text = ggplot2::element_text(face = "bold")
)The vertical scales differ by panel because the methods can produce adjustment factors of very different sizes.
HCbeta, proposed by Cunha, Cribari-Neto and Marinho (2026), starts from the identity
\[ 1 - h_t = F_U(1 - h_t), \]
where \(F_U\) is the cumulative distribution function of a Uniform\((0, 1)\) random variable. This observation recasts the classical leverage complement as a cdf value on \([0, 1]\).
The HCbeta estimator replaces the uniform cdf with the Beta cdf,
\[ F_B(x; a, b) = I_x(a, b), \]
where \(I_x(a, b)\) is the
regularized incomplete beta function. In R this is
pbeta(x, a, b).
This does not assume that the leverage complements follow a Beta distribution. The Beta distribution is used as a parametric cdf for constructing the adjustment factor. Its support matches the support of \(1 - h_t\), and its shape parameters allow the adjustment curve to depart from the uniform baseline.
The leverage complement \(1 - h_t\) is first truncated to \(w_t = \max\{\text{lower}, \min(1 - h_t, \text{upper})\}\), where the default truncation interval is \([0.01, 0.99]\). Beta shape parameters \(\tilde a\) and \(\tilde b\) are then calibrated from the truncated complements by the method of moments, shrunk toward the uniform case \(a = b = 1\), and clamped to a compact interval. With these ingredients in place, the HCbeta adjustment factor is
\[ g_t = \frac{n}{n - p} \left\{\frac{1}{F_B(w_t; \tilde a, \tilde b)}\right\}^{c_1/n^{c_2}}, \qquad c_1 = 7, \qquad c_2 = 0.75. \]
The exponent \(c_1/n^{c_2}\) decays
with \(n\), so the correction is most
active in moderate samples and vanishes asymptotically. The full
construction, including the moment equations, shrinkage, fixed floor,
and caps, is given in
vignette("hcinfer-hcbeta-algorithm", package = "hcinfer").
hcinfer() uses the selected HC covariance estimator to
form coefficient level normal Wald tests. For
\[ H_0: \beta_j = \beta_j^{(0)}, \]
the statistic is
\[ z_j = \frac{\hat\beta_j - \beta_j^{(0)}} {\sqrt{[\widehat\Psi_{HC}]_{jj}}}. \]
The reference distribution is the standard normal distribution. A two sided test rejects at level \(\alpha\) when
\[ |z_j| > z_{1 - \alpha / 2}. \]
The corresponding confidence interval is
\[ \hat\beta_j \pm z_{1 - \alpha / 2} \sqrt{[\widehat\Psi_{HC}]_{jj}}. \]
Student t quantiles and bootstrap intervals are not used by
hcinfer().
The individual Wald tests address one coefficient at a time. The
summaries for hcinfer() and gls_mult() also
test whether all coefficients in the mean model except the intercept are
jointly zero. Without an intercept, this test includes every
coefficient; for an intercept-only model, it is omitted. The joint null
always tests against zero, regardless of the null values
used for the individual tests.
Let \(\hat\beta_2\) contain the
estimates of the \(q\) coefficients
under test, and let \(\widehat\Psi_{22}\) be the corresponding
block of the estimated covariance matrix. For hcinfer(),
this is a block of the selected HC estimator. For
gls_mult(), it comes from the model-based covariance \((X'\widehat W X)^{-1}\), where \(\widehat W\) is diagonal with entries equal
to the reciprocals of the fitted conditional variances. When the
covariance block is numerically positive definite, the Wald statistic
\(W\) and the reported quasi-F
statistic \(F\) are
\[ W = \hat\beta_2' \widehat\Psi_{22}^{-1} \hat\beta_2, \qquad F = W/q. \]
Under the joint null, asymptotic normality of the coefficient
estimates and consistency of the covariance estimator give \(W\) a limiting \(\chi^2_q\) distribution; for
gls_mult(), the model-based covariance is consistent only
when the variance model is correctly specified. The reference for \(F\) is therefore \(\chi^2_q/q\), and the reported p-value is
\(P(\chi^2_q \geq W)\), consistent with
the asymptotic normal reference for the individual tests. In simulations
with 27, 54, and 108 observations, Godfrey (2006) found that asymptotic
critical values did not reliably control the null rejection
probabilities of Wald tests based on HC covariance estimators; the HC0
version rejected about twice as often as the nominal 5% level even with
108 observations. The p-value is thus an approximation that warrants
caution in small and moderate samples.
HCbeta is the default estimator in hcinfer(). It is
designed to keep the leverage correction active without letting the
largest adjustment factors grow too quickly in high leverage designs.
For a step-by-step usage workflow, see
vignette("introduction", package = "hcinfer").
Large leverage is not, by itself, a reason to remove an observation. It indicates that squared residuals at that design point are compressed by the OLS projection. Influence diagnostics answer a different question about how much the fitted coefficients change when an observation is removed.
The package does not need to form the full hat matrix to compute leverage. The leverages can be obtained from a QR decomposition of the model matrix by summing the squared entries in each row of the orthonormal factor.
For details on the numerical implementation of the Beta cdf
evaluation and exponent capping, see the numerical section of
vignette("hcinfer-hcbeta-algorithm", package = "hcinfer").
Method-specific constants are passed through ... in
vcov_hc() and hcinfer(). HC0R accepts
seed through .... The HCbeta caps can be
supplied independently through ..., and unknown names are
rejected. This keeps the interface compact while making the documented
constants available for sensitivity analyses.
White, H. (1980). A heteroskedasticity-consistent covariance matrix estimator and a direct test for heteroskedasticity. Econometrica, 48(4), 817-838. doi:10.2307/1912934.
Hinkley, D. V. (1977). Jackknifing in unbalanced situations. Technometrics, 19(3), 285-292. doi:10.1080/00401706.1977.10489550.
MacKinnon, J. G. and White, H. (1985). Some heteroskedasticity-consistent covariance matrix estimators with improved finite sample properties. Journal of Econometrics, 29(3), 305-325. doi:10.1016/0304-4076(85)90158-7.
Davidson, R. and MacKinnon, J. G. (1993). Estimation and Inference in Econometrics. Oxford University Press.
Cribari-Neto, F. (2004). Asymptotic inference under heteroskedasticity of unknown form. Computational Statistics and Data Analysis, 45(2), 215-233. doi:10.1016/S0167-9473(02)00366-3.
Cribari-Neto, F. and da Silva, W. B. (2011). A new heteroskedasticity-consistent covariance matrix estimator for the linear regression model. AStA Advances in Statistical Analysis, 95(2), 129-146. doi:10.1007/s10182-010-0141-2.
Cribari-Neto, F., Souza, T. C., and Vasconcellos, K. L. P. (2007). Inference under heteroskedasticity and leveraged data. Communications in Statistics - Theory and Methods, 36(10), 1877-1888. doi:10.1080/03610920601126589.
Cribari-Neto, F., Souza, T. C., and Vasconcellos, K. L. P. (2008). Errata: Inference under heteroskedasticity and leveraged data, Communications in Statistics, Theory and Methods, 36, 1877-1888, 2007. Communications in Statistics - Theory and Methods, 37(20), 3329-3330. doi:10.1080/03610920802109210.
Li, S., Zhang, N., Zhang, X., and Wang, G. (2016). A new heteroskedasticity-consistent covariance matrix estimator and inference under heteroskedasticity. Journal of Statistical Computation and Simulation, 87(1), 198-210. doi:10.1080/00949655.2016.1198906.
Rousseeuw, P. J. (1984). Least median of squares regression. Journal of the American Statistical Association, 79(388), 871-880. doi:10.1080/01621459.1984.10477105.
Godfrey, L. G. (2006). Tests for regression models with heteroskedasticity of unknown form. Computational Statistics and Data Analysis, 50(10), 2715-2733. doi:10.1016/j.csda.2005.04.004.
Lima, V. M. C., Souza, T. C., Cribari-Neto, F., and Fernandes, G. B. (2010). Heteroskedasticity-robust inference in linear regressions. Communications in Statistics - Simulation and Computation, 39(1), 194-206. doi:10.1080/03610910903402572.
Cunha, M. O., Cribari-Neto, F., and Marinho, P. R. D. (2026). A beta-based heteroskedasticity-consistent covariance matrix estimator. Journal of Statistical Computation and Simulation. doi:10.1080/00949655.2026.2757763.