Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Files changed: M .setup/build/betaDelta.pdf M .setup/build/betaDelta_1.0.4.9000.tar.gz A vignettes/example-beta-delta.Rmd A vignettes/example-delta-generic.Rmd A vignettes/example-delta.Rmd A vignettes/example-diff-beta-delta.Rmd
- Loading branch information
1 parent
ff5ae25
commit 664b79b
Showing
6 changed files
with
533 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
--- | ||
title: "betaDelta: Example Using the BetaDelta Function" | ||
author: "Ivan Jacob Agaloos Pesigan" | ||
output: rmarkdown::html_vignette | ||
bibliography: "vignettes.bib" | ||
csl: https://raw.githubusercontent.com/citation-style-language/styles/master/apa.csl | ||
nocite: | | ||
@Pesigan-Sun-Cheung-2023 | ||
@Yuan-Chan-2011 | ||
@Jones-Waller-2015 | ||
@NationalResearchCouncil-1982 | ||
vignette: > | ||
%\VignetteIndexEntry{betaDelta: Example Using the BetaDelta Function} | ||
%\VignetteEngine{knitr::rmarkdown} | ||
%\VignetteEncoding{UTF-8} | ||
--- | ||
|
||
|
||
|
||
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 [@NationalResearchCouncil-1982]. | ||
Confidence intervals for the standardized regression coefficients are generated | ||
using the `BetaDelta()` function from the `betaDelta` package following @Yuan-Chan-2011 and @Jones-Waller-2015. | ||
|
||
|
||
```r | ||
library(betaDelta) | ||
``` | ||
|
||
|
||
|
||
|
||
```r | ||
df <- betaDelta::nas1982 | ||
``` | ||
|
||
## Fit the regression model using the `lm()` function. | ||
|
||
|
||
```r | ||
object <- lm(QUALITY ~ NARTIC + PCTGRT + PCTSUPP, data = df) | ||
``` | ||
|
||
## Estimate the standardized regression slopes and the corresponding sampling covariance matrix. | ||
|
||
#### Multivariate Normal-Theory Approach | ||
|
||
|
||
```r | ||
BetaDelta(object, type = "mvn", alpha = 0.05) | ||
#> Call: | ||
#> BetaDelta(object = object, type = "mvn", alpha = 0.05) | ||
#> | ||
#> Standardized regression slopes with MVN standard errors: | ||
#> est se t df p 2.5% 97.5% | ||
#> NARTIC 0.4951 0.0759 6.5272 42 0.000 0.3421 0.6482 | ||
#> PCTGRT 0.3915 0.0770 5.0824 42 0.000 0.2360 0.5469 | ||
#> PCTSUPP 0.2632 0.0747 3.5224 42 0.001 0.1124 0.4141 | ||
``` | ||
|
||
#### Asymptotic Distribution-Free Approach | ||
|
||
|
||
```r | ||
BetaDelta(object, type = "adf", alpha = 0.05) | ||
#> Call: | ||
#> BetaDelta(object = object, type = "adf", alpha = 0.05) | ||
#> | ||
#> Standardized regression slopes with ADF standard errors: | ||
#> est se t df p 2.5% 97.5% | ||
#> NARTIC 0.4951 0.0674 7.3490 42 0.0000 0.3592 0.6311 | ||
#> PCTGRT 0.3915 0.0710 5.5164 42 0.0000 0.2483 0.5347 | ||
#> PCTSUPP 0.2632 0.0769 3.4231 42 0.0014 0.1081 0.4184 | ||
``` | ||
|
||
## Methods | ||
|
||
|
||
```r | ||
mvn <- BetaDelta(object, type = "mvn") | ||
adf <- BetaDelta(object, type = "adf") | ||
``` | ||
|
||
### summary | ||
|
||
Summary of the results of `BetaDelta()`. | ||
|
||
|
||
```r | ||
summary(mvn) | ||
#> Call: | ||
#> BetaDelta(object = object, type = "mvn") | ||
#> | ||
#> Standardized regression slopes with MVN standard errors: | ||
#> est se t df p 0.05% 0.5% 2.5% 97.5% 99.5% | ||
#> NARTIC 0.4951 0.0759 6.5272 42 0.000 0.2268 0.2905 0.3421 0.6482 0.6998 | ||
#> PCTGRT 0.3915 0.0770 5.0824 42 0.000 0.1190 0.1837 0.2360 0.5469 0.5993 | ||
#> PCTSUPP 0.2632 0.0747 3.5224 42 0.001 -0.0011 0.0616 0.1124 0.4141 0.4649 | ||
#> 99.95% | ||
#> NARTIC 0.7635 | ||
#> PCTGRT 0.6640 | ||
#> PCTSUPP 0.5276 | ||
summary(adf) | ||
#> Call: | ||
#> BetaDelta(object = object, type = "adf") | ||
#> | ||
#> Standardized regression slopes with ADF standard errors: | ||
#> est se t df p 0.05% 0.5% 2.5% 97.5% 99.5% | ||
#> NARTIC 0.4951 0.0674 7.3490 42 0.0000 0.2568 0.3134 0.3592 0.6311 0.6769 | ||
#> PCTGRT 0.3915 0.0710 5.5164 42 0.0000 0.1404 0.2000 0.2483 0.5347 0.5830 | ||
#> PCTSUPP 0.2632 0.0769 3.4231 42 0.0014 -0.0088 0.0558 0.1081 0.4184 0.4707 | ||
#> 99.95% | ||
#> NARTIC 0.7335 | ||
#> PCTGRT 0.6426 | ||
#> PCTSUPP 0.5353 | ||
``` | ||
|
||
### coef | ||
|
||
Calculate the standardized regression slopes. | ||
|
||
|
||
```r | ||
coef(mvn) | ||
#> NARTIC PCTGRT PCTSUPP | ||
#> 0.4951451 0.3914887 0.2632477 | ||
coef(adf) | ||
#> NARTIC PCTGRT PCTSUPP | ||
#> 0.4951451 0.3914887 0.2632477 | ||
``` | ||
|
||
### vcov | ||
|
||
Calculate the sampling covariance matrix of the standardized regression slopes. | ||
|
||
|
||
```r | ||
vcov(mvn) | ||
#> NARTIC PCTGRT PCTSUPP | ||
#> NARTIC 0.005754524 -0.003360334 -0.002166127 | ||
#> PCTGRT -0.003360334 0.005933462 -0.001769723 | ||
#> PCTSUPP -0.002166127 -0.001769723 0.005585256 | ||
vcov(adf) | ||
#> NARTIC PCTGRT PCTSUPP | ||
#> NARTIC 0.004539472 -0.002552698 -0.001742698 | ||
#> PCTGRT -0.002552698 0.005036538 -0.001906216 | ||
#> PCTSUPP -0.001742698 -0.001906216 0.005914088 | ||
``` | ||
|
||
### confint | ||
|
||
Generate confidence intervals for standardized regression slopes. | ||
|
||
|
||
```r | ||
confint(mvn, level = 0.95) | ||
#> 2.5 % 97.5 % | ||
#> NARTIC 0.3420563 0.6482339 | ||
#> PCTGRT 0.2360380 0.5469395 | ||
#> PCTSUPP 0.1124272 0.4140682 | ||
confint(adf, level = 0.95) | ||
#> 2.5 % 97.5 % | ||
#> NARTIC 0.3591757 0.6311146 | ||
#> PCTGRT 0.2482683 0.5347091 | ||
#> PCTSUPP 0.1080509 0.4184444 | ||
``` | ||
|
||
## References |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
--- | ||
title: "betaDelta: Example Using the DeltaGeneric Function" | ||
author: "Ivan Jacob Agaloos Pesigan" | ||
output: rmarkdown::html_vignette | ||
bibliography: "vignettes.bib" | ||
csl: https://raw.githubusercontent.com/citation-style-language/styles/master/apa.csl | ||
nocite: | | ||
@Pesigan-Sun-Cheung-2023 | ||
vignette: > | ||
%\VignetteIndexEntry{betaDelta: Example Using the DeltaGeneric Function} | ||
%\VignetteEngine{knitr::rmarkdown} | ||
%\VignetteEncoding{UTF-8} | ||
--- | ||
|
||
|
||
|
||
In this example, we use the delta method to calculate the odds ratio, the associated standard errors, and confidence intervals within a logistic regression model. | ||
|
||
|
||
```r | ||
library(betaDelta) | ||
``` | ||
|
||
|
||
```r | ||
object <- glm( | ||
formula = vs ~ wt + disp, | ||
family = "binomial", | ||
data = mtcars | ||
) | ||
def <- list("exp(wt)", "exp(disp)") | ||
DeltaGeneric( | ||
object = object, | ||
def = def, | ||
alpha = 0.05 | ||
) | ||
#> Call: | ||
#> DeltaGeneric(object = object, def = def, alpha = 0.05) | ||
#> est se z p 2.5% 97.5% | ||
#> exp(wt) 5.0853 7.5805 0.6708 0.5023 -9.7723 19.9429 | ||
#> exp(disp) 0.9662 0.0148 65.0838 0.0000 0.9371 0.9952 | ||
``` | ||
|
||
## Methods | ||
|
||
|
||
```r | ||
delta <- DeltaGeneric( | ||
object = object, | ||
def = def, | ||
alpha = 0.05 | ||
) | ||
``` | ||
|
||
### summary | ||
|
||
Summary of the results of `DeltaGeneric()`. | ||
|
||
|
||
```r | ||
summary(delta) | ||
#> Call: | ||
#> DeltaGeneric(object = object, def = def, alpha = 0.05) | ||
#> est se z p 2.5% 97.5% | ||
#> exp(wt) 5.0853 7.5805 0.6708 0.5023 -9.7723 19.9429 | ||
#> exp(disp) 0.9662 0.0148 65.0838 0.0000 0.9371 0.9952 | ||
``` | ||
|
||
### coef | ||
|
||
Calculate the estimates. | ||
|
||
|
||
```r | ||
coef(delta) | ||
#> exp(wt) exp(disp) | ||
#> 5.0852960 0.9661524 | ||
``` | ||
|
||
### vcov | ||
|
||
Calculate the sampling covariance matrix. | ||
|
||
|
||
```r | ||
vcov(delta) | ||
#> exp(wt) exp(disp) | ||
#> exp(wt) 57.46443026 -0.0977480169 | ||
#> exp(disp) -0.09774802 0.0002203662 | ||
``` | ||
|
||
### confint | ||
|
||
Generate confidence intervals. | ||
|
||
|
||
```r | ||
confint(delta, level = 0.95) | ||
#> 2.5 % 97.5 % | ||
#> exp(wt) -9.7722691 19.9428612 | ||
#> exp(disp) 0.9370572 0.9952475 | ||
``` | ||
|
||
## References |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--- | ||
title: "betaDelta: Example Using the Delta Function" | ||
author: "Ivan Jacob Agaloos Pesigan" | ||
output: rmarkdown::html_vignette | ||
bibliography: "vignettes.bib" | ||
csl: https://raw.githubusercontent.com/citation-style-language/styles/master/apa.csl | ||
nocite: | | ||
@Pesigan-Sun-Cheung-2023 | ||
vignette: > | ||
%\VignetteIndexEntry{betaDelta: Example Using the Delta Function} | ||
%\VignetteEngine{knitr::rmarkdown} | ||
%\VignetteEncoding{UTF-8} | ||
--- | ||
|
||
|
||
|
||
In this example, we use the delta method to calculate the odds ratio, the associated standard errors, and confidence intervals within a logistic regression model. | ||
|
||
|
||
```r | ||
library(betaDelta) | ||
``` | ||
|
||
|
||
```r | ||
object <- glm( | ||
formula = vs ~ wt + disp, | ||
family = "binomial", | ||
data = mtcars | ||
) | ||
func <- function(x) { | ||
y <- exp(x) | ||
names(y) <- paste0("exp", "(", names(x), ")") | ||
return(y[-1]) | ||
} | ||
Delta( | ||
coef = coef(object), | ||
vcov = vcov(object), | ||
func = func, | ||
alpha = 0.05 | ||
) | ||
#> Call: | ||
#> Delta(coef = coef(object), vcov = vcov(object), func = func, | ||
#> alpha = 0.05) | ||
#> est se z p 2.5% 97.5% | ||
#> exp(wt) 5.0853 7.5805 0.6708 0.5023 -9.7723 19.9429 | ||
#> exp(disp) 0.9662 0.0148 65.0838 0.0000 0.9371 0.9952 | ||
``` | ||
|
||
## Methods | ||
|
||
|
||
```r | ||
delta <- Delta( | ||
coef = coef(object), | ||
vcov = vcov(object), | ||
func = func, | ||
alpha = 0.05 | ||
) | ||
``` | ||
|
||
### summary | ||
|
||
Summary of the results of `Delta()`. | ||
|
||
|
||
```r | ||
summary(delta) | ||
#> Call: | ||
#> Delta(coef = coef(object), vcov = vcov(object), func = func, | ||
#> alpha = 0.05) | ||
#> est se z p 2.5% 97.5% | ||
#> exp(wt) 5.0853 7.5805 0.6708 0.5023 -9.7723 19.9429 | ||
#> exp(disp) 0.9662 0.0148 65.0838 0.0000 0.9371 0.9952 | ||
``` | ||
|
||
### coef | ||
|
||
Calculate the estimates. | ||
|
||
|
||
```r | ||
coef(delta) | ||
#> exp(wt) exp(disp) | ||
#> 5.0852960 0.9661524 | ||
``` | ||
|
||
### vcov | ||
|
||
Calculate the sampling covariance matrix. | ||
|
||
|
||
```r | ||
vcov(delta) | ||
#> exp(wt) exp(disp) | ||
#> exp(wt) 57.46443026 -0.0977480169 | ||
#> exp(disp) -0.09774802 0.0002203662 | ||
``` | ||
|
||
### confint | ||
|
||
Generate confidence intervals. | ||
|
||
|
||
```r | ||
confint(delta, level = 0.95) | ||
#> 2.5 % 97.5 % | ||
#> exp(wt) -9.7722691 19.9428612 | ||
#> exp(disp) 0.9370572 0.9952475 | ||
``` | ||
|
||
## References |
Oops, something went wrong.