betaSandwich: Example Using the RSqSandwich Function
Ivan Jacob Agaloos Pesigan
Source:vignettes/example-r-sq-sandwich.Rmd
example-r-sq-sandwich.RmdConfidence intervals for multiple correlation are generated using the
RSqSandwich() 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 the multiple correlation coefficients (R-squared and adjusted R-squared) and the corresponding sampling covariance matrix.
The R-squared and the adjusted R-squared are R^{2} = \boldsymbol{\beta}^{\ast\prime} \boldsymbol{R}_{x} \boldsymbol{\beta}^{\ast} and \bar{R}^{2} = 1 - \left( 1 - R^{2} \right) \left( n - 1 \right) / \left( n - k \right), where \boldsymbol{\beta}^{\ast} is the vector of standardized slopes, \boldsymbol{R}_{x} is the correlation matrix of the regressors, n is the sample size, and k is the number of parameters of the regression model, including the intercept. The sampling covariance matrix is obtained by the delta method from the sampling covariance matrix of the standardized parameters.
mvn <- RSqSandwich(object = std_mvn, alpha = 0.05)
adf <- RSqSandwich(object = std_adf, alpha = 0.05)
hc3 <- RSqSandwich(object = std_hc3, alpha = 0.05)Methods
summary
Summary of the results of RSqSandwich().
summary(object = mvn)
#> Call:
#> RSqSandwich(object = std_mvn, alpha = 0.05)
#>
#> R-squared and adjusted R-squared with MVN standard errors:
#> est se z p 2.5% 97.5%
#> rsq 0.8045 0.0517 15.5608 0 0.7032 0.9059
#> adj 0.7906 0.0554 14.2713 0 0.6820 0.8991
summary(object = adf)
#> Call:
#> RSqSandwich(object = std_adf, alpha = 0.05)
#>
#> R-squared and adjusted R-squared with MVN standard errors:
#> est se z p 2.5% 97.5%
#> rsq 0.8045 0.0519 15.4910 0 0.7027 0.9063
#> adj 0.7906 0.0556 14.2073 0 0.6815 0.8996
summary(object = hc3)
#> Call:
#> RSqSandwich(object = std_hc3, alpha = 0.05)
#>
#> R-squared and adjusted R-squared with HC3 standard errors:
#> est se z p 2.5% 97.5%
#> rsq 0.8045 0.0573 14.0286 0 0.6921 0.9169
#> adj 0.7906 0.0614 12.8662 0 0.6701 0.9110confint
Generate confidence intervals for R-squared and adjusted R-squared.
stats::confint(object = mvn, level = 0.95)
#> 2.5 % 97.5 %
#> rsq 0.7031917 0.9058608
#> adj 0.6819911 0.8991366
stats::confint(object = adf, level = 0.95)
#> 2.5 % 97.5 %
#> rsq 0.7027351 0.9063174
#> adj 0.6815019 0.8996258
stats::confint(object = hc3, level = 0.95)
#> 2.5 % 97.5 %
#> rsq 0.6921245 0.9169280
#> adj 0.6701334 0.9109943