Ivan Jacob Agaloos Pesigan 2026-11-30 04:29:56
Description
Generates robust confidence intervals for standardized regression coefficients using heteroskedasticity-consistent standard errors for models fitted by lm() as described in Dudgeon (2017, doi:10.1007/s11336-017-9563-z). Sampling covariance matrices can also be obtained under multivariate normal theory and the asymptotically distribution-free approach. The package can also be used to generate confidence intervals for R-squared, adjusted R-squared, differences of standardized regression coefficients, semipartial correlations, squared partial correlations, the improvement in R-squared, and Cohen’s f-squared. A description of the package and code examples are presented in Pesigan, Sun, and Cheung (2023, doi:10.1080/00273171.2023.2201277).
Installation
You can install the CRAN release of betaSandwich with:
install.packages("betaSandwich")You can install the development version of betaSandwich from GitHub with:
if (!require("pak")) install.packages("pak")
pak::pkg_install("jeksterslab/betaSandwich")Example
In this example, a multiple regression model is fitted using program quality ratings (QUALITY) as the regressand/outcome variable and number of published articles attributed to the program faculty members (NARTIC), percent of faculty members holding research grants (PCTGRT), and percentage of program graduates who received support (PCTSUPP) as regressor/predictor variables using a data set from 1982 ratings of 46 doctoral programs in psychology in the USA (National Research Council, 1982). Robust confidence intervals for the standardized regression coefficients are generated using the BetaHC() function from the betaSandwich package following Dudgeon (2017).
library(package = betaSandwich)
df <- betaSandwich::nas1982Fit the regression model using the lm() function.
object <- stats::lm(formula = QUALITY ~ NARTIC + PCTGRT + PCTSUPP, data = df)Estimate the standardized regression slopes and the corresponding robust sampling covariance matrix.
BetaHC(object = object, type = "hc3", alpha = 0.05)
#> Call:
#> BetaHC(object = object, type = "hc3", alpha = 0.05)
#>
#> Standardized regression slopes with HC3 standard errors:
#> est se t df p 2.5% 97.5%
#> NARTIC 0.4951 0.0786 6.3025 42 0.0000 0.3366 0.6537
#> PCTGRT 0.3915 0.0818 4.7831 42 0.0000 0.2263 0.5567
#> PCTSUPP 0.2632 0.0855 3.0786 42 0.0037 0.0907 0.4358Other Features
The package provides the following functions.
| Function | Purpose |
|---|---|
BetaHC() |
Standardized regression coefficients with a heteroskedasticity-consistent sampling covariance matrix (HC0-HC5) |
BetaADF() |
Standardized regression coefficients with an asymptotically distribution-free sampling covariance matrix |
BetaN() |
Standardized regression coefficients with a multivariate normal-theory sampling covariance matrix |
RSqSandwich() |
R-squared and adjusted R-squared |
DiffBetaSandwich() |
Differences of standardized regression coefficients |
SCorSandwich() |
Semipartial correlations |
SCorSqSandwich() |
Squared semipartial correlations (squared signed interval) |
PCorSandwich() |
Squared partial correlations |
DeltaRSqSandwich() |
Improvement in R-squared |
FSqSandwich() |
Cohen’s f-squared and local f-squared |
The coef(), vcov(), confint(), summary(), and print() methods are available for the returned objects. Examples for each function are in the package vignettes.
Effect Sizes
The definitions, formulas, and notes on effect sizes near zero are in the help pages of the functions and in the vignette betaSandwich: Example Using the SCorSandwich, SCorSqSandwich, PCorSandwich, DeltaRSqSandwich, and FSqSandwich Functions.
Documentation
See GitHub Pages for package documentation.