betaSandwich: Example Using the DiffBetaSandwich Function
Ivan Jacob Agaloos Pesigan
Source:vignettes/example-diff-beta-sandwich.Rmd
example-diff-beta-sandwich.RmdConfidence intervals for differences of standardized regression
slopes are generated using the DiffBetaSandwich() function
from the betaSandwich package. In this example, we use the
data set and the model used in betaSandwich: Example Using the BetaHC
Function.
library(package = betaSandwich)
df <- betaSandwich::nas1982Fit the regression model using the lm() function.
object <- stats::lm(formula = QUALITY ~ NARTIC + PCTGRT + PCTSUPP, data = df)Estimate differences of standardized regression slopes and the corresponding sampling covariance matrix.
The difference between the standardized slopes of regressors j and l is \beta^{\ast}_{j} - \beta^{\ast}_{l}. It compares the standardized effects of the two regressors on the same scale. The sampling variance of the difference is \operatorname{var} \left( \hat{\beta}^{\ast}_{j} \right) + \operatorname{var} \left( \hat{\beta}^{\ast}_{l} \right) - 2 \, \operatorname{cov} \left( \hat{\beta}^{\ast}_{j}, \hat{\beta}^{\ast}_{l} \right), obtained from the sampling covariance matrix of the standardized slopes.
mvn <- DiffBetaSandwich(object = std_mvn, alpha = 0.05)
adf <- DiffBetaSandwich(object = std_adf, alpha = 0.05)
hc3 <- DiffBetaSandwich(object = std_hc3, alpha = 0.05)Methods
summary
Summary of the results of DiffBetaSandwich().
summary(object = mvn)
#> Call:
#> DiffBetaSandwich(object = std_mvn, alpha = 0.05)
#>
#> Differences of standardized regression slopes with MVN standard errors:
#> est se z p 2.5% 97.5%
#> NARTIC-PCTGRT 0.1037 0.1357 0.7640 0.4449 -0.1623 0.3696
#> NARTIC-PCTSUPP 0.2319 0.1252 1.8524 0.0640 -0.0135 0.4773
#> PCTGRT-PCTSUPP 0.1282 0.1227 1.0451 0.2960 -0.1123 0.3688
summary(object = adf)
#> Call:
#> DiffBetaSandwich(object = std_adf, alpha = 0.05)
#>
#> Differences of standardized regression slopes with MVN standard errors:
#> est se z p 2.5% 97.5%
#> NARTIC-PCTGRT 0.1037 0.1212 0.8555 0.3923 -0.1338 0.3411
#> NARTIC-PCTSUPP 0.2319 0.1181 1.9642 0.0495 0.0005 0.4633
#> PCTGRT-PCTSUPP 0.1282 0.1215 1.0555 0.2912 -0.1099 0.3664
summary(object = hc3)
#> Call:
#> DiffBetaSandwich(object = std_hc3, alpha = 0.05)
#>
#> Differences of standardized regression slopes with HC3 standard errors:
#> est se z p 2.5% 97.5%
#> NARTIC-PCTGRT 0.1037 0.1417 0.7316 0.4644 -0.1741 0.3814
#> NARTIC-PCTSUPP 0.2319 0.1318 1.7595 0.0785 -0.0264 0.4902
#> PCTGRT-PCTSUPP 0.1282 0.1375 0.9329 0.3509 -0.1412 0.3977coef
Calculate differences of standardized regression slopes.
stats::coef(object = mvn)
#> NARTIC-PCTGRT NARTIC-PCTSUPP PCTGRT-PCTSUPP
#> 0.1036564 0.2318974 0.1282410
stats::coef(object = adf)
#> NARTIC-PCTGRT NARTIC-PCTSUPP PCTGRT-PCTSUPP
#> 0.1036564 0.2318974 0.1282410
stats::coef(object = hc3)
#> NARTIC-PCTGRT NARTIC-PCTSUPP PCTGRT-PCTSUPP
#> 0.1036564 0.2318974 0.1282410vcov
Calculate the sampling covariance matrix of differences of standardized regression slopes.
stats::vcov(object = mvn)
#> NARTIC-PCTGRT NARTIC-PCTSUPP PCTGRT-PCTSUPP
#> NARTIC-PCTGRT 0.018408653 0.009511262 -0.008897391
#> NARTIC-PCTSUPP 0.009511262 0.015672035 0.006160773
#> PCTGRT-PCTSUPP -0.008897391 0.006160773 0.015058164
stats::vcov(object = adf)
#> NARTIC-PCTGRT NARTIC-PCTSUPP PCTGRT-PCTSUPP
#> NARTIC-PCTGRT 0.014681407 0.006928651 -0.007752755
#> NARTIC-PCTSUPP 0.006928651 0.013938955 0.007010303
#> PCTGRT-PCTSUPP -0.007752755 0.007010303 0.014763058
stats::vcov(object = hc3)
#> NARTIC-PCTGRT NARTIC-PCTSUPP PCTGRT-PCTSUPP
#> NARTIC-PCTGRT 0.020076382 0.009274583 -0.010801799
#> NARTIC-PCTSUPP 0.009274583 0.017370731 0.008096148
#> PCTGRT-PCTSUPP -0.010801799 0.008096148 0.018897947confint
Generate confidence intervals for differences of standardized regression slopes.
stats::confint(object = mvn, level = 0.95)
#> 2.5 % 97.5 %
#> NARTIC-PCTGRT -0.16226855 0.3695814
#> NARTIC-PCTSUPP -0.01346652 0.4772614
#> PCTGRT-PCTSUPP -0.11226950 0.3687516
stats::confint(object = adf, level = 0.95)
#> 2.5 % 97.5 %
#> NARTIC-PCTGRT -0.1338262589 0.3411391
#> NARTIC-PCTSUPP 0.0004975295 0.4632974
#> PCTGRT-PCTSUPP -0.1099011119 0.3663832
stats::confint(object = hc3, level = 0.95)
#> 2.5 % 97.5 %
#> NARTIC-PCTGRT -0.17405314 0.3813660
#> NARTIC-PCTSUPP -0.02642203 0.4902169
#> PCTGRT-PCTSUPP -0.14119483 0.3976769