| Title: | Heteroskedasticity-Consistent Inference for Linear Models |
|---|---|
| Description: | Computes heteroskedasticity-consistent covariance matrix estimators for ordinary least squares regression models. 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>, Horn et al. (1975) <doi:10.1080/01621459.1975.10479877>, 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>, 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 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.1.0.9000 |
| Built: | 2026-06-10 15:12:49 UTC |
| Source: | https://github.com/prdm0/hcinfer |
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.
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
Horn, S. D., Horn, R. A., and Duncan, D. B. (1975). Estimating heteroscedastic variances in linear models. Journal of the American Statistical Association, 70(350), 380-385. doi:10.1080/01621459.1975.10479877
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
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) hcinfer(fit, type = "hcbeta", c1 = 7, c2 = 0.75, lower = 0.01, upper = 0.99) 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) hcinfer(fit, type = "hcbeta", c1 = 7, c2 = 0.75, lower = 0.01, upper = 0.99) hcinfer(fit, type = "hc5", k = 0.7) hcinfer(fit, type = "hc5m", k = 0.7, k1 = 1, k2 = 0, k3 = 1)
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 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 US states and Washington DC 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:
US state or Washington DC.
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")
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
Horn, S. D., Horn, R. A., and Duncan, D. B. (1975). Estimating heteroscedastic variances in linear models. Journal of the American Statistical Association, 70(350), 380-385. doi:10.1080/01621459.1975.10479877
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
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, and upper = 0.99.
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 truncation is
.
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
Horn, S. D., Horn, R. A., and Duncan, D. B. (1975). Estimating heteroscedastic variances in linear models. Journal of the American Statistical Association, 70(350), 380-385. doi:10.1080/01621459.1975.10479877
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
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) vcov_hc(fit, type = "hcbeta", c1 = 7, c2 = 0.75, lower = 0.01, upper = 0.99) 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) vcov_hc(fit, type = "hcbeta", c1 = 7, c2 = 0.75, lower = 0.01, upper = 0.99) 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.