| Title: | Heteroskedasticity-Consistent Inference for Linear Models |
|---|---|
| Description: | Performs heteroskedasticity-consistent inferences in linear regressions under heteroskedasticity. The published HC0 through HC5m estimators implemented in the package follow White (1980) <doi:10.2307/1912934>, Hinkley (1977) <doi:10.1080/00401706.1977.10489550>, MacKinnon and White (1985) <doi:10.1016/0304-4076(85)90158-7>, Cribari-Neto (2004) <doi:10.1016/S0167-9473(02)00366-3>, Cribari-Neto and da Silva (2011) <doi:10.1007/s10182-010-0141-2>, Cribari-Neto et al. (2007) <doi:10.1080/03610920601126589> with its erratum <doi:10.1080/03610920802109210>, and Li et al. (2016) <doi:10.1080/00949655.2016.1198906>. The package also includes HCbeta, a new estimator proposed by the package authors. It additionally provides feasible generalized least squares estimation under multiplicative heteroskedasticity following Harvey (1976) <doi:10.2307/1913974> and Cribari-Neto and Pereira (2019) <doi:10.1080/00949655.2019.1586902>, with two-step and maximum likelihood fitting and information criteria for the likelihood fit. It provides normal Wald tests, confidence intervals, diagnostics, and S3 output for applied inference. |
| Authors: | Pedro Rafael D. Marinho [aut, cre] (ORCID: <https://orcid.org/0000-0003-1591-8300>), Francisco Cribari-Neto [aut] (ORCID: <https://orcid.org/0000-0002-5909-6698>), Marina Oliveira Cunha [aut] (ORCID: <https://orcid.org/0009-0007-4938-3881>) |
| Maintainer: | Pedro Rafael D. Marinho <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.0 |
| Built: | 2026-09-26 11:41:31 UTC |
| Source: | https://github.com/prdm0/hcinfer |
Computes pairs (case) bootstrap standard errors and confidence intervals for
the coefficients of an ordinary least squares model fitted with
stats::lm(). The pairs bootstrap resamples the observations
with replacement, refits OLS on each resample, and
summarizes the resulting sampling distribution of . It makes no
assumption about the form of the error variance, so it is a useful empirical
reference for the analytic heteroskedasticity-consistent standard errors
produced by hcinfer() and vcov_hc().
boot_pairs( object, B = 1000L, level = 0.95, ci_type = c("percentile", "basic", "normal"), cores = 1L, seed = NULL ) ## S3 method for class 'hcinfer_boot' print(x, ...)boot_pairs( object, B = 1000L, level = 0.95, ci_type = c("percentile", "basic", "normal"), cores = 1L, seed = NULL ) ## S3 method for class 'hcinfer_boot' print(x, ...)
object |
An ordinary least squares model fitted by |
B |
Number of bootstrap replicates. A positive integer; defaults to
|
level |
Confidence level for the intervals, strictly between 0 and 1.
Defaults to |
ci_type |
Interval type: |
cores |
Number of worker processes. A single number greater than or
equal to 1; non-integer values are rounded to the nearest integer. The
default |
seed |
Optional single number used to seed the resampling for
reproducibility. When supplied, the result is deterministic and independent
of the number of |
x |
An object returned by |
... |
Unused. |
For each of B bootstrap replicates, a sample of n row indices is drawn
with replacement from 1, ..., n, and OLS is refitted on the resampled rows
. Writing for the estimate on
replicate r, the bootstrap standard error of coefficient j is the sample
standard deviation of .
Three interval types are available through ci_type. Let
denote the empirical quantile of the bootstrap
replicates for a coefficient, the original estimate,
the bootstrap standard error, and
.
The "percentile" interval is
. The "basic" (reverse percentile)
interval is
. The
"normal" interval is
, with the standard
normal quantile.
Reproducibility. When seed is supplied, all resampling indices are drawn
once, sequentially, in the main process under that seed, and the per-replicate
fit is deterministic. The results are therefore identical whether the run is
sequential or parallel and regardless of the number of cores. The caller's
random number generator state is saved and restored, so calling boot_pairs()
does not disturb a surrounding random stream. When seed is NULL, the
current RNG state is used and results are not reproducible.
Parallelism. The default cores = 1 fits the replicates sequentially.
When cores rounds to 2 or more, the deterministic per-replicate fits are
distributed with purrr::in_parallel(), which uses the mirai package
as its backend. boot_pairs() starts cores daemons for the duration of the
call and shuts them down on exit; do not call it while relying on externally
configured mirai daemons. Parallelism only speeds up the computation: it
never changes the numeric result. It is worthwhile mainly for large B or
large n; for small problems the setup overhead can dominate.
Rank-deficient resamples. A resample can be rank deficient (for example when a resample omits the observations that identify a coefficient). Such replicates are dropped, a warning reports how many were dropped, and the summaries use the remaining replicates. The call errors if fewer than two valid replicates remain.
An object of class hcinfer_boot: a list with the original OLS
coefficients, bootstrap std_error, bias, interval endpoints conf_low
and conf_high, the settings (level, ci_type, B, B_effective,
n_failed, cores, seed), the full replicates matrix
(B rows by p columns), and a tidy table tibble with columns term,
estimate, bias, std_error, conf_low, and conf_high. Use
coef(), vcov(), and confint() to extract components.
Davison, A. C. and Hinkley, D. V. (1997). Bootstrap Methods and their Application. Cambridge University Press. doi:10.1017/CBO9780511802843
Efron, B. and Tibshirani, R. J. (1993). An Introduction to the Bootstrap. Chapman and Hall. doi:10.1201/9780429246593
schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) # 1. Fit, inspect, and visualize a reproducible pairs bootstrap. boot <- boot_pairs(fit, B = 1000, seed = 123) boot confint(boot) plot(boot) # 2. Use the bootstrap as an empirical reference for the analytic HC standard # errors, side by side in one table. data.frame( term = boot$table$term, ols = sqrt(diag(vcov(fit))), bootstrap = boot$table$std_error, hcbeta = sqrt(diag(vcov(hcinfer(fit, type = "hcbeta")))), hc3 = sqrt(diag(vcov(hcinfer(fit, type = "hc3")))) ) # 3. Recompute intervals at a new level and type from the same replicates, # without rerunning the bootstrap. confint(boot, level = 0.99, type = "basic") confint(boot, parm = "income_scaled_sq", level = 0.90) # 4. Larger, parallel run on two cores. Requires the mirai and carrier # packages; the numeric result matches a sequential run with the same seed. if (requireNamespace("mirai", quietly = TRUE) && requireNamespace("carrier", quietly = TRUE)) { boot_par <- boot_pairs(fit, B = 4000, ci_type = "basic", cores = 2, seed = 42) boot_par$table }schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) # 1. Fit, inspect, and visualize a reproducible pairs bootstrap. boot <- boot_pairs(fit, B = 1000, seed = 123) boot confint(boot) plot(boot) # 2. Use the bootstrap as an empirical reference for the analytic HC standard # errors, side by side in one table. data.frame( term = boot$table$term, ols = sqrt(diag(vcov(fit))), bootstrap = boot$table$std_error, hcbeta = sqrt(diag(vcov(hcinfer(fit, type = "hcbeta")))), hc3 = sqrt(diag(vcov(hcinfer(fit, type = "hc3")))) ) # 3. Recompute intervals at a new level and type from the same replicates, # without rerunning the bootstrap. confint(boot, level = 0.99, type = "basic") confint(boot, parm = "income_scaled_sq", level = 0.90) # 4. Larger, parallel run on two cores. Requires the mirai and carrier # packages; the numeric result matches a sequential run with the same seed. if (requireNamespace("mirai", quietly = TRUE) && requireNamespace("carrier", quietly = TRUE)) { boot_par <- boot_pairs(fit, B = 4000, ci_type = "basic", cores = 2, seed = 42) boot_par$table }
Extracts the OLS coefficients stored in an hcinfer() result.
## S3 method for class 'hcinfer' coef(object, ...)## S3 method for class 'hcinfer' coef(object, ...)
object |
An object returned by |
... |
Unused. |
A named numeric vector of OLS coefficients.
Extracts normal Wald confidence intervals from an hcinfer() result. If the
requested level differs from the level used to create the object, only the
normal critical value and interval endpoints are recomputed.
## S3 method for class 'hcinfer' confint(object, parm, level = object$confidence_level, ...)## S3 method for class 'hcinfer' confint(object, parm, level = object$confidence_level, ...)
object |
An object returned by |
parm |
Optional coefficient names or positions. |
level |
Confidence level. |
... |
Unused. |
A tibble with columns term, conf_low, conf_high, and level.
Violent-crime and murder rates together with socioeconomic indicators for the 50 U.S. states and the District of Columbia in 2009. The data are useful for illustrating heteroskedasticity-consistent inference in a cross-sectional design with influential observations.
Crime2009Crime2009
A tibble with 51 rows and 8 variables:
Name of one of the 50 U.S. states or the District of Columbia.
Violent-crime rate per 100,000 population.
Murder rate per 100,000 population.
Percentage of the population that graduated from high school or higher.
Percentage of the population living below the poverty line.
Percentage of households headed by a single parent.
Percentage of the population that is white.
Percentage of the population living in urban areas.
French, J. P. (2023). api2lm: Functions and Data Sets for the Book 'A
Progressive Introduction to Linear Models'. R package version 0.2.
doi:10.32614/CRAN.package.api2lm. The same data are distributed as the
statecrime dataset in the Python statsmodels package (Seabold and
Perktold, 2010, https://www.statsmodels.org/); the underlying figures come
from the Statistical Abstract of the United States (2009) and are in the
public domain.
data(Crime2009) Crime2009[Crime2009$state == "Alabama", ] fit <- lm(murder ~ hs_grad + poverty + single, data = Crime2009) hcinfer(fit, type = "hcbeta")data(Crime2009) Crime2009[Crime2009$state == "Alabama", ] fit <- lm(murder ~ hs_grad + poverty + single, data = Crime2009) hcinfer(fit, type = "hcbeta")
Fits a linear mean model by feasible generalized least squares when the conditional variance is modelled as an exponential function of observed dispersion regressors. Both Harvey's two-step estimator and full Gaussian maximum likelihood are available. The method complements HC covariance inference by making an explicit, testable variance-model assumption.
gls_mult( object, variance = NULL, estimator = c("ml", "two_step"), method = c("BFGS", "Nelder-Mead", "CG", "L-BFGS-B"), alpha = 0.05, null = 0, control = list(), ... )gls_mult( object, variance = NULL, estimator = c("ml", "two_step"), method = c("BFGS", "Nelder-Mead", "CG", "L-BFGS-B"), alpha = 0.05, null = 0, control = list(), ... )
object |
An unweighted, univariate ordinary least squares model fitted
by |
variance |
|
estimator |
Estimator. |
method |
Optimization algorithm passed to |
alpha |
Significance level for normal Wald tests. The confidence level
is |
null |
Null values for mean-coefficient tests. Use one value for all coefficients or one finite value per mean coefficient. |
control |
A list passed to |
... |
Reserved and required to be empty. It is not forwarded to
|
Let the mean model be
where is an full-rank matrix with .
The multiplicative variance model is
where is an full-rank matrix with ,
is the dispersion coefficient vector, and is the
fitted log-variance. Thus has squared response units,
whereas is the conditional standard deviation in
response units. The mean and dispersion coefficients remain distinct
parameter blocks even when variance = NULL makes .
The dispersion model must contain exactly one all-ones intercept column.
This requirement makes the two-step intercept correction unambiguous.
A custom one-sided variance formula may use variables outside the mean
formula. Such variables are recovered from the original lm data and
aligned by the exact rows used to estimate the mean model.
With estimator = "two_step", the function first regresses
on , where are the OLS
residuals. If denotes this raw auxiliary estimate,
the intercept is corrected as
where is the unit vector that selects the dispersion intercept.
The constant is approximately 1.270362845 because
for a standard normal error. The resulting weights are
, collected in the
diagonal weight matrix
,
and the feasible GLS estimate is obtained from the weighted normal
equations. Multiplying every inverse-variance weight by the same positive
constant leaves the GLS coefficient estimate unchanged. The raw and
corrected auxiliary estimates are stored in variance_coefficients_raw and
variance_coefficients_corrected.
The asymptotic normal-theory covariance approximation for the auxiliary
regression is
because under normality. The intercept
correction centers this auxiliary error, but it does not remove
finite-sample effects from using OLS residuals in place of the errors.
The reported mean covariance is the model-based plug-in
, which treats the estimated weights as known
and does not propagate the sampling variability of , the
same convention adopted by Cribari-Neto and Pereira (2019). The Gaussian
log-likelihood at a two-step estimate is not maximized, so two-step objects
do not support logLik(), AIC(), or BIC().
With the default estimator = "ml", the corrected two-step estimate
initializes optimization of the Gaussian log-likelihood by the algorithm
chosen with method (BFGS by default). The joint log-likelihood
of the mean and dispersion blocks is
For every trial value of , is profiled out by
weighted least squares, yielding , and the chosen
optimizer maximizes the resulting profile log-likelihood
through
stats::optim(), using the analytic profile gradient when the algorithm is
gradient based. The asymptotic expected information has
zero cross-information between and , with blocks
Its inverse gives the reported asymptotic dispersion covariance
and the model-based mean plug-in covariance
, which treats the estimated weights as known.
For an accepted maximum likelihood fit, logLik() returns the Gaussian
log-likelihood evaluated at the accepted local solution, so the default
AIC() and BIC() methods work without package-specific
information-criterion methods. Their likelihood degrees of freedom equal
, and comparisons require competing fits to have reached
comparable likelihood solutions. With an intercept-only dispersion model,
variance = ~ 1, the fit reduces to the homoskedastic Gaussian linear model
and reproduces the lm coefficients, log-likelihood, AIC, and BIC.
Mean and dispersion tables use standard-normal Wald reference values. The reported mean covariance is model-based and relies on correct specification of the multiplicative variance model. It is not an HC sandwich covariance, and no robust GLS covariance is computed.
For estimator = "ml", a fit is accepted as a locally optimized stationary
solution only when stats::optim() returns convergence code zero and the
scale-invariant profile-score norm
, where
is the profile score, falls below a fixed tolerance. This
guard rejects a false convergence report at a nonstationary point, such as
one caused by an excessively loose reltol, but it does not prove that the
accepted solution is a global maximum.
Computation uses row-scaled matrices, Cholesky solves, and centered
log-variances; it never constructs an diagonal weight
matrix or explicitly inverts a cross-product. The function fails explicitly
for rank-deficient designs, missing or nonfinite aligned inputs, zero or
nonfinite OLS residuals, an absent dispersion intercept, unrecoverable
dispersion rows, nonrepresentable fitted variances or weights, a singular
weighted design, or maximum likelihood non-convergence. Weighted, offset,
and multivariate lm fits are not silently reinterpreted and are rejected.
An object of class gls_mult and hcinfer_object. Important components are:
coefficients, vcov
Mean coefficients and their model-based covariance matrix.
variance_coefficients, variance_vcov
Dispersion coefficients and their method-specific covariance matrix.
variance_coefficients_raw,
variance_coefficients_corrected
Raw and intercept-corrected two-step auxiliary estimates. For maximum likelihood, the corrected estimate is the optimizer starting value.
fitted, residuals
GLS fitted values and residuals.
fitted_variances, weights, eta
Fitted conditional variances
in squared response units, inverse-variance weights, and fitted
log-variances .
table, variance_table
Normal Wald summaries for the mean and dispersion parameter blocks.
loglik, convergence
The log-likelihood at the accepted local solution and optimizer diagnostics, present only for maximum likelihood fits.
df, nobs
Likelihood parameter count and sample
size.
Harvey, A. C. (1976). Estimating regression models with multiplicative heteroscedasticity. Econometrica, 44(3), 461-465. doi:10.2307/1913974
Cribari-Neto, F. and Pereira, I. F. S. (2019). Testing inference in heteroskedastic linear regressions: a comparison of two alternative approaches. Journal of Statistical Computation and Simulation, 89(8), 1437-1465. doi:10.1080/00949655.2019.1586902
hcinfer() for OLS inference with HC covariance estimators and
vcov_hc() for the implemented HC covariance matrices.
vignette("hcinfer-gls", package = "hcinfer") is a didactic guide to
feasible GLS under multiplicative heteroskedasticity.
schools <- PublicSchools |> dplyr::mutate(income_scaled = income / 10000) fit <- lm(expenditure ~ income_scaled, data = schools) result <- gls_mult(fit) result summary(result) coef(result) coef(result, model = "dispersion") vcov(result) tests(result) confint(result) logLik(result) AIC(result) BIC(result) two_step <- gls_mult(fit, estimator = "two_step") coef(two_step) nelder_mead <- gls_mult(fit, method = "Nelder-Mead") coef(nelder_mead)schools <- PublicSchools |> dplyr::mutate(income_scaled = income / 10000) fit <- lm(expenditure ~ income_scaled, data = schools) result <- gls_mult(fit) result summary(result) coef(result) coef(result, model = "dispersion") vcov(result) tests(result) confint(result) logLik(result) AIC(result) BIC(result) two_step <- gls_mult(fit, estimator = "two_step") coef(two_step) nelder_mead <- gls_mult(fit, method = "Nelder-Mead") coef(nelder_mead)
Extracts, summarizes, and prints components of an object returned by
gls_mult(). Mean-model methods use normal Wald inference. The model
argument selects the mean or dispersion parameter block for coef() and
vcov().
## S3 method for class 'gls_mult' coef(object, model = c("mean", "dispersion"), ...) ## S3 method for class 'gls_mult' vcov(object, model = c("mean", "dispersion"), ...) ## S3 method for class 'gls_mult' confint(object, parm, level = object$confidence_level, ...) ## S3 method for class 'gls_mult' tests(object, parm, alpha = object$alpha, ...) ## S3 method for class 'gls_mult' nobs(object, ...) ## S3 method for class 'gls_mult' fitted(object, ...) ## S3 method for class 'gls_mult' residuals(object, ...) ## S3 method for class 'gls_mult' logLik(object, ...) ## S3 method for class 'gls_mult' print(x, ...) ## S3 method for class 'gls_mult' summary(object, ...) ## S3 method for class 'summary_gls_mult' print(x, ...)## S3 method for class 'gls_mult' coef(object, model = c("mean", "dispersion"), ...) ## S3 method for class 'gls_mult' vcov(object, model = c("mean", "dispersion"), ...) ## S3 method for class 'gls_mult' confint(object, parm, level = object$confidence_level, ...) ## S3 method for class 'gls_mult' tests(object, parm, alpha = object$alpha, ...) ## S3 method for class 'gls_mult' nobs(object, ...) ## S3 method for class 'gls_mult' fitted(object, ...) ## S3 method for class 'gls_mult' residuals(object, ...) ## S3 method for class 'gls_mult' logLik(object, ...) ## S3 method for class 'gls_mult' print(x, ...) ## S3 method for class 'gls_mult' summary(object, ...) ## S3 method for class 'summary_gls_mult' print(x, ...)
object, x
|
An object returned by |
model |
Parameter block to extract: |
... |
Unused. Passing arguments raises an error. |
parm |
Optional mean-coefficient names or integer positions. |
level |
Confidence level for mean-coefficient intervals. |
alpha |
Significance level for mean-coefficient tests. |
coef() returns a named numeric vector; vcov() returns a covariance
matrix; confint() and tests() return tibbles; fitted() and
residuals() return named numeric vectors; nobs() returns the sample size;
and logLik() returns a logLik object for maximum likelihood fits.
summary() returns an object of class summary_gls_mult, including fitted
conditional-variance and standard-deviation summaries in squared response
and response units. Print methods return their input invisibly.
Returns the HC covariance estimators implemented by hcinfer.
hc_methods()hc_methods()
A tibble with columns type, label, description, and
default_arguments.
hc_methods()hc_methods()
Computes normal Wald tests and confidence intervals for an ordinary least squares model using a heteroskedasticity-consistent covariance estimator.
hcinfer(object, type = "hcbeta", alpha = 0.05, null = 0, ...)hcinfer(object, type = "hcbeta", alpha = 0.05, null = 0, ...)
object |
An ordinary least squares model fitted by |
type |
A character string specifying the HC estimator. The default is
|
alpha |
Significance level. The confidence level is |
null |
Null values for the coefficient tests. Use a scalar to test all coefficients against the same value, or a numeric vector with one value per coefficient. |
... |
Method-specific constants passed to |
For each coefficient, hcinfer tests
against a two-sided alternative using the statistic
The reference distribution is the standard normal distribution. Confidence intervals are Wald intervals obtained by direct inversion of the test,
Bootstrap intervals and Student t quantiles are not used.
An object of class hcinfer containing the fitted HC covariance estimator,
coefficient tests, p-values, confidence intervals, diagnostics, and method
parameters.
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
schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) result <- hcinfer(fit, type = "hcbeta") result summary(result) confint(result) # Sensitivity analysis with nondefault HCbeta caps hcinfer(fit, type = "hcbeta", a_max = 20000, b_max = 20000) hcinfer(fit, type = "hc5", k = 0.7) hcinfer(fit, type = "hc5m", k = 0.7, k1 = 1, k2 = 0, k3 = 1)schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) result <- hcinfer(fit, type = "hcbeta") result summary(result) confint(result) # Sensitivity analysis with nondefault HCbeta caps hcinfer(fit, type = "hcbeta", a_max = 20000, b_max = 20000) hcinfer(fit, type = "hc5", k = 0.7) hcinfer(fit, type = "hc5m", k = 0.7, k1 = 1, k2 = 0, k3 = 1)
Extractors for objects returned by boot_pairs(). coef() returns the
original OLS coefficients, vcov() returns the bootstrap covariance matrix
(the sample covariance of the bootstrap replicates), and confint() returns
bootstrap confidence intervals, optionally recomputed at a different level
or type from the stored replicates.
## S3 method for class 'hcinfer_boot' coef(object, ...) ## S3 method for class 'hcinfer_boot' vcov(object, ...) ## S3 method for class 'hcinfer_boot' confint(object, parm, level = object$level, type = object$ci_type, ...)## S3 method for class 'hcinfer_boot' coef(object, ...) ## S3 method for class 'hcinfer_boot' vcov(object, ...) ## S3 method for class 'hcinfer_boot' confint(object, parm, level = object$level, type = object$ci_type, ...)
object |
An object returned by |
... |
Unused. |
parm |
Optional coefficient names or integer positions. |
level |
Confidence level for |
type |
Interval type for |
coef() a named numeric vector; vcov() a numeric covariance matrix;
confint() a tibble with columns term, conf_low, conf_high, and
level.
Sale prices, assessed values, and physical characteristics of 88 homes sold in the Boston, Massachusetts area in 1990. The data are widely used to illustrate regression and heteroskedasticity-consistent inference.
HpriceHprice
A tibble with 88 rows and 10 variables:
House price, in thousands of U.S. dollars.
Assessed value, in thousands of U.S. dollars.
Number of bedrooms.
Size of the lot, in square feet.
Size of the house, in square feet.
Indicator equal to 1 if the home is of colonial style.
Natural logarithm of price.
Natural logarithm of assess.
Natural logarithm of lotsize.
Natural logarithm of sqrft.
Wooldridge, J. M. (2020). Introductory Econometrics: A Modern Approach,
7th ed. Cengage Learning, Boston, MA. The hprice1 data are distributed with
the wooldridge R package and were originally collected from the real estate
pages of the Boston Globe.
data(Hprice) head(Hprice) fit <- lm(price ~ lotsize + bdrms + bdrms:sqrft, data = Hprice) hcinfer(fit, type = "hcbeta")data(Hprice) head(Hprice) fit <- lm(price ~ lotsize + bdrms + bdrms:sqrft, data = Hprice) hcinfer(fit, type = "hcbeta")
Plots the normal Wald confidence intervals for the mean coefficients of a
gls_mult() fit, color-coded by the test decision at the stored significance
level, matching plot.hcinfer(). Only the mean block is shown, consistent
with confint.gls_mult() and tests.gls_mult().
## S3 method for class 'gls_mult' plot(x, parm, ...)## S3 method for class 'gls_mult' plot(x, parm, ...)
x |
An object returned by |
parm |
Optional coefficient names or integer positions. Selection
follows the same rules as |
... |
Unused. Passing named arguments raises an error. |
A ggplot2::ggplot() object.
gls_mult(), confint.gls_mult(), tests.gls_mult()
fit <- lm(expenditure ~ income, data = PublicSchools) result <- gls_mult(fit) plot(result) plot(result, parm = "income")fit <- lm(expenditure ~ income, data = PublicSchools) result <- gls_mult(fit) plot(result) plot(result, parm = "income")
Plots normal Wald confidence intervals for an hcinfer() result. Each
interval is color-coded by the test decision at the stored significance
level: coefficients for which the null hypothesis is rejected are shown in
red, and those for which it is not rejected are shown in blue. Formatted
p-values are printed to the right of each interval for quick reading.
## S3 method for class 'hcinfer' plot(x, parm, ...)## S3 method for class 'hcinfer' plot(x, parm, ...)
x |
An object returned by |
parm |
Optional coefficient names or integer positions. When supplied,
only the selected coefficients are plotted. The selection follows the same
rules as |
... |
Unused. Passing named arguments raises an error. |
A ggplot2::ggplot() object.
hcinfer(), confint.hcinfer(), tests.hcinfer()
schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) result <- hcinfer(fit) plot(result) plot(result, parm = "income_scaled_sq")schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) result <- hcinfer(fit) plot(result) plot(result, parm = "income_scaled_sq")
Plots the pairs bootstrap confidence intervals stored in a boot_pairs()
object. Each coefficient is drawn as its ordinary least squares point estimate
with a horizontal bootstrap interval, color-coded by whether the interval
excludes zero (shown in red) or includes zero (shown in blue). A dashed
vertical reference line is drawn at zero.
## S3 method for class 'hcinfer_boot' plot(x, parm, ...)## S3 method for class 'hcinfer_boot' plot(x, parm, ...)
x |
An object returned by |
parm |
Optional coefficient names or integer positions. When supplied,
only the selected coefficients are plotted, following the same rules as
|
... |
Unused. Passing named arguments raises an error. |
A ggplot2::ggplot() object.
schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) boot <- boot_pairs(fit, B = 1000, seed = 123) plot(boot) plot(boot, parm = "income_scaled_sq")schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) boot <- boot_pairs(fit, B = 1000, seed = 123) plot(boot) plot(boot, parm = "income_scaled_sq")
Plots the HC adjustment factors against the leverage values
stored in a vcov_hc() object. Points with
are highlighted because this threshold is commonly used to
flag high-leverage observations in the empirical examples from the HCbeta
paper.
## S3 method for class 'hcinfer_vcov' plot(x, label_top = 3, ...)## S3 method for class 'hcinfer_vcov' plot(x, label_top = 3, ...)
x |
An object returned by |
label_top |
A nonnegative whole number. The observations with the
largest adjustment factors are labeled. Use |
... |
Unused. Passing named arguments raises an error. |
A ggplot2::ggplot() object.
vcov_hc(), hcinfer(), plot.hcinfer()
schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) cov <- vcov_hc(fit, type = "hcbeta") plot(cov) plot(vcov_hc(fit, type = "hc4"), label_top = 2)schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) cov <- vcov_hc(fit, type = "hcbeta") plot(cov) plot(vcov_hc(fit, type = "hc4"), label_top = 2)
Prints a compact overview of a heteroskedasticity-consistent inference
object. Emoji markers are used when the current locale supports UTF-8 and
getOption("hcinfer.use_emoji", TRUE) is true.
## S3 method for class 'hcinfer' print(x, ...)## S3 method for class 'hcinfer' print(x, ...)
x |
An object returned by |
... |
Unused. |
The input object, invisibly.
Prints a compact overview of a heteroskedasticity-consistent covariance
object. Emoji markers are used when the current locale supports UTF-8 and
getOption("hcinfer.use_emoji", TRUE) is true.
## S3 method for class 'hcinfer_vcov' print(x, ...)## S3 method for class 'hcinfer_vcov' print(x, ...)
x |
An object returned by |
... |
Unused. |
The input object, invisibly.
Public school expenditure and income data for the 50 U.S. states and the District of Columbia in 1979. The expenditure value for Wisconsin is missing in the source data, so the standard regression example uses 50 complete observations. The data are useful for illustrating heteroskedasticity-consistent inference because Alaska is a high-leverage observation in the quadratic public-schools model studied in the HCbeta paper.
PublicSchoolsPublicSchools
A tibble with 51 rows and 3 variables:
Name of one of the 50 U.S. states or the District of Columbia.
Per capita expenditure on public schools in 1979. This variable has one missing value.
Per capita income in 1979.
Greene, W. H. (1993). Econometric Analysis, 2nd ed. Macmillan Publishing
Company, New York. Table 14.1, p. 385. The data were originally sourced from
the U.S. Department of Commerce, Statistical Abstract of the United States
(1979). The dataset is also available in the sandwich R package.
data(PublicSchools) PublicSchools[PublicSchools$state == "Alaska", ] schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) hcinfer(fit, type = "hcbeta")data(PublicSchools) PublicSchools[PublicSchools$state == "Alaska", ] schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) hcinfer(fit, type = "hcbeta")
Public school expenditure and per capita income for the 50 U.S. states and the District of Columbia. Income is measured for 2024, and expenditure is measured for 2025. The regional indicator uses the U.S. Census Bureau classification of the Southern United States.
PublicSchools2PublicSchools2
A tibble with 51 rows and 4 variables:
Character. Name of one of the 50 U.S. states or the District of Columbia.
Integer. Annual per capita personal income for 2024, in nominal U.S. dollars. It is calculated as total personal income for the jurisdiction divided by its population.
Integer. Annual expenditure per student enrolled in K-12 public schools for 2025, in U.S. dollars. It includes instructional salaries and expenses, school support, and administrative services.
Integer. Indicator equal to 1 for Alabama, Arkansas, Delaware, the District of Columbia, Florida, Georgia, Kentucky, Louisiana, Maryland, Mississippi, North Carolina, Oklahoma, South Carolina, Tennessee, Texas, Virginia, and West Virginia, and 0 otherwise.
World Population Review (2026), Per Capita Income by State, https://worldpopulationreview.com/state-rankings/per-capita-income-by-state. Accessed June 11, 2026. The supplied data dictionary also attributes the income measure to the U.S. Bureau of Economic Analysis.
World Population Review (2026), Per Pupil Spending by State, https://worldpopulationreview.com/state-rankings/per-pupil-spending-by-state. Accessed June 11, 2026.
U.S. Census Bureau, Terms and Definitions: Census Regions and Divisions, https://www.census.gov/programs-surveys/popest/guidance-geographies/terms-and-definitions.html.
Wikipedia, Southern United States, https://en.wikipedia.org/wiki/Southern_United_States. This was the geographic source recorded in the supplied data dictionary. Accessed June 11, 2026.
data(PublicSchools2) PublicSchools2[PublicSchools2$state == "District of Columbia", ] table(PublicSchools2$south)data(PublicSchools2) PublicSchools2[PublicSchools2$state == "District of Columbia", ] table(PublicSchools2$south)
Builds a detailed summary for an hcinfer() result. The summary includes
model metadata, HC method information, leverage diagnostics, robust weight
diagnostics, and coefficient-by-coefficient normal Wald tests with p-values
and confidence intervals. The print method adds formal test decisions to
improve interpretation while preserving the numeric components of the object.
## S3 method for class 'hcinfer' summary(object, ...)## S3 method for class 'hcinfer' summary(object, ...)
object |
An object returned by |
... |
Unused. |
An object of class summary_hcinfer.
Builds a detailed summary for an object returned by vcov_hc().
## S3 method for class 'hcinfer_vcov' summary(object, ...)## S3 method for class 'hcinfer_vcov' summary(object, ...)
object |
An object returned by |
... |
Unused. |
An object of class summary_hcinfer_vcov.
Extracts the normal Wald test results from an hcinfer() object. If the
requested significance level differs from the one used to create the object,
only the reject column is recomputed. The test statistics and p-values are
not affected by alpha and are never recomputed.
tests(object, ...) ## S3 method for class 'hcinfer' tests(object, parm, alpha = object$alpha, ...)tests(object, ...) ## S3 method for class 'hcinfer' tests(object, parm, alpha = object$alpha, ...)
object |
An object returned by |
... |
Unused. Passing named arguments raises an error. |
parm |
Optional coefficient names or integer positions to select a subset of coefficients. When omitted, all coefficients are returned. |
alpha |
Significance level used to compute the |
For each coefficient, the stored test is
against a two-sided alternative. The test statistic is
and the p-value is , where is the standard
normal distribution function. The null value is the one
stored in the object, set when hcinfer() was called.
To test against a different null value, rerun hcinfer() with the desired
null argument.
A tibble with one row per selected coefficient and the following columns:
termCoefficient name.
estimateOLS estimate .
null_valueNull hypothesis value .
std_errorRobust standard error
.
z_valueNormal Wald statistic .
p_valueTwo-sided p-value .
alphaSignificance level used for the reject column.
rejectLogical. TRUE when p_value < alpha.
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
schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) result <- hcinfer(fit) tests(result) tests(result, parm = "income_scaled_sq") tests(result, alpha = 0.10)schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) result <- hcinfer(fit) tests(result) tests(result, parm = "income_scaled_sq") tests(result, alpha = 0.10)
Computes a heteroskedasticity-consistent covariance matrix estimator for an
ordinary least squares model fitted with stats::lm(). The function returns
a rich S3 object that stores the covariance matrix, HC weights, leverage
values, method parameters, and model metadata.
vcov_hc(object, type = "hcbeta", ...)vcov_hc(object, type = "hcbeta", ...)
object |
An ordinary least squares model fitted by |
type |
A character string specifying the HC estimator. The default is
|
... |
Method-specific constants. Unknown names are rejected. See Details for the accepted names, defaults, and parameter domains. |
For a linear model with design matrix , OLS residuals ,
and HC weights , the estimator is
where . The supported
estimators are "hc0", "hc1", "hc2", "hc3", "hc4", "hc4m",
"hc5", "hc5m", and "hcbeta".
Additional arguments in ... are method-specific. The defaults are:
"hc0", "hc1", "hc2", "hc3", "hc4", and "hc4m": no
method-specific arguments.
"hc5": k = 0.7.
"hc5m": k = 0.7, k1 = 1, k2 = 0, k3 = 1, gamma1 = 1, and
gamma2 = 1.5.
"hcbeta": c1 = 7, c2 = 0.75, lower = 0.01, upper = 0.99,
a_max = 10000, and b_max = 10000.
The HC5 adjustment factor follows the corrected expression published in the
erratum to Cribari-Neto, Souza and Vasconcellos (2007), that is,
with
, where
and . HC5m follows Li,
Zhang, Zhang and Wang (2016) and applies its own exponent
without the factor .
For "hc5" and "hc5m", k, k1, k2, and k3 must be nonnegative,
while gamma1 and gamma2 must be positive. For "hcbeta", c1 must be
nonnegative, c2 must be positive, and lower and upper must lie in
(0, 1) with lower < upper. The HCbeta leverage-complement truncation is
.
After shrinkage with , the Beta shape parameters
are clamped as
The value is fixed, applied after shrinkage and before
the caps, and is not a method argument. It is distinct from lower, which
truncates ; changing lower does not change .
Both a_max and b_max must be finite and lie in [50, 25000]; they
default to 10000 and can be set independently through ... for sensitivity
analysis. When the variance of the truncated complements is numerically
degenerate, the adjusted shapes are set directly to their respective caps.
HCbeta remains defined when because it truncates
before evaluating the Beta CDF. In contrast, HC2 through HC5m
require a strictly positive leverage complement.
An object of class hcinfer_vcov. The covariance matrix is stored in
object$vcov and is returned directly by vcov().
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
schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) cov <- vcov_hc(fit, type = "hcbeta") cov vcov(cov) plot(cov) # Sensitivity analysis with nondefault HCbeta caps vcov_hc(fit, type = "hcbeta", a_max = 20000, b_max = 20000) vcov_hc(fit, type = "hc5", k = 0.7) vcov_hc(fit, type = "hc5m", k = 0.7, k1 = 1, k2 = 0, k3 = 1)schools <- PublicSchools |> dplyr::mutate( income_scaled = income / 10000, income_scaled_sq = income_scaled^2 ) fit <- lm(expenditure ~ income_scaled + income_scaled_sq, data = schools) cov <- vcov_hc(fit, type = "hcbeta") cov vcov(cov) plot(cov) # Sensitivity analysis with nondefault HCbeta caps vcov_hc(fit, type = "hcbeta", a_max = 20000, b_max = 20000) vcov_hc(fit, type = "hc5", k = 0.7) vcov_hc(fit, type = "hc5m", k = 0.7, k1 = 1, k2 = 0, k3 = 1)
Extracts the heteroskedasticity-consistent covariance matrix stored in an hcinfer object. The matrix is returned directly and is not recomputed.
## S3 method for class 'hcinfer' vcov(object, ...) ## S3 method for class 'hcinfer_vcov' vcov(object, ...)## S3 method for class 'hcinfer' vcov(object, ...) ## S3 method for class 'hcinfer_vcov' vcov(object, ...)
object |
|
... |
Unused. |
A numeric covariance matrix.