Skip to content

Commit

Permalink
updated pkg docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimtyuryaev committed Jan 14, 2025
1 parent a520707 commit 9058b82
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 38 deletions.
30 changes: 15 additions & 15 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ knitr::opts_chunk$set(
![Build Status](https://img.shields.io/badge/build-passing-brightgreen)
![Lifecycle:Stable](https://img.shields.io/badge/Lifecycle-Stable-97ca00)
[![R-CMD-check](https://github.com/r-lib/rcmdcheck/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/rcmdcheck/actions/workflows/R-CMD-check.yaml)
[![CRAN Status](https://www.r-pkg.org/badges/version/RegrCoeffsExplorer)](https://CRAN.R-project.org/package=RegrCoeffsExplorer)
<!-- badges: end -->

_Always present effect sizes for primary outcomes_ [@Wilkinson1999Statistical].
Expand All @@ -40,7 +41,15 @@ Elastic-Net Regularized Generalized Linear Models (GLMNET) frameworks.

## Installation

You can install the current version of `RegrCoeffsExplorer` from
CRAN version[@R-RegrCoeffsExplorer] can be installed with:

```{r, eval=F, echo=T, results="hide", warning=F, message=F }
install.packages("RegrCoeffsExplorer")
```

You can install the development version of `RegrCoeffsExplorer` from
[GitHub](https://github.com/vadimtyuryaev/RegrCoeffsExplorer) with:

```{r, eval=F, echo=T, results="hide", warning=F, message=F }
Expand Down Expand Up @@ -240,6 +249,8 @@ median and jitters to add random noise to data points preventing overlap and
revealing the underlying data distribution more clearly. Substantial changes in
the OR progressing alone the empirical data are clearly observed.



### Customize plots - 1/2

```{r, warning=F, message=F}
Expand Down Expand Up @@ -319,24 +330,13 @@ how these interactions can be estimated and interpreted on the probability scale
Consider a Linear Model with two continuous predictors and an interaction term:

$$E[Y|\textbf{X}] = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_{12} x_1 x_2$$

Define the **marginal effect** by taking the partial derivative with respect to
$x_2$:

$$\gamma_2 = \frac{\partial E[Y|\textbf{X}]}{\partial x_2} = \beta_2$$

Therefore, $\beta_2$ is sufficient to quantify how much $E[Y|\textbf{X}]$ changes
with respect to every one unit increase in $\beta_2$, holding all other variables
constant.

Now, take the second order cross-partial derivative of $E[Y|\textbf{X}]$ with
Take the second order cross-partial derivative of $E[Y|\textbf{X}]$ with
respect to both $x_1$ and $x_2$:

$$\gamma_{12}^2 = \frac{\partial^2 E[Y| \textbf{X}]}{\partial x_1 \partial x_2} = \beta_{12}$$

Similar intuition as above holds. The interaction term $\beta_{12}$ shows
how effect of $x_1$ on $E[Y|\textbf{X}]$ changes for every one unit increase in
$x_2$ and vice versa.
The interaction term $\beta_{12}$ shows how effect of $x_1$ on $E[Y|\textbf{X}]$
changes for every one unit increase in $x_2$ and vice versa.

Now consider a logistic regression model with a non-linear link function $g(\cdot)$,
two continuous predictors and an interaction term:
Expand Down
49 changes: 29 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
![Build Status](https://img.shields.io/badge/build-passing-brightgreen)
![Lifecycle:Stable](https://img.shields.io/badge/Lifecycle-Stable-97ca00)
[![R-CMD-check](https://github.com/r-lib/rcmdcheck/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/rcmdcheck/actions/workflows/R-CMD-check.yaml)
[![CRAN
Status](https://www.r-pkg.org/badges/version/RegrCoeffsExplorer)](https://CRAN.R-project.org/package=RegrCoeffsExplorer)
<!-- badges: end -->

*Always present effect sizes for primary outcomes* (Wilkinson 1999).
Expand All @@ -33,7 +35,14 @@ Elastic-Net Regularized Generalized Linear Models (GLMNET) frameworks.

## Installation

You can install the current version of `RegrCoeffsExplorer` from
CRAN version(Tyuryaev et al. 2024) can be installed with:

``` r

install.packages("RegrCoeffsExplorer")
```

You can install the development version of `RegrCoeffsExplorer` from
[GitHub](https://github.com/vadimtyuryaev/RegrCoeffsExplorer) with:

``` r
Expand Down Expand Up @@ -286,7 +295,7 @@ vis_reg(glm_model, CI = TRUE, intercept = TRUE,
theme(plot.title = element_text(hjust = 0.5))
```

<img src="man/figures/README-unnamed-chunk-3-1.png" width="100%" /> As
<img src="man/figures/README-unnamed-chunk-4-1.png" width="100%" /> As
observed, when returning individual plots, the resulting entities are
`ggplot` objects. Consequently, any operation that is compatible with
ggplot can be applied to these plots using the `+` operator.
Expand All @@ -301,7 +310,7 @@ vis_reg(glm_model, CI = TRUE, intercept = TRUE,
linetype="dashed", color = "orange", size=1)
```

<img src="man/figures/README-unnamed-chunk-4-1.png" width="100%" />
<img src="man/figures/README-unnamed-chunk-5-1.png" width="100%" />

## Vignettes

Expand Down Expand Up @@ -357,24 +366,14 @@ Consider a Linear Model with two continuous predictors and an
interaction term:

$$E[Y|\textbf{X}] = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_{12} x_1 x_2$$

Define the **marginal effect** by taking the partial derivative with
respect to $x_2$:

$$\gamma_2 = \frac{\partial E[Y|\textbf{X}]}{\partial x_2} = \beta_2$$

Therefore, $\beta_2$ is sufficient to quantify how much
$E[Y|\textbf{X}]$ changes with respect to every one unit increase in
$\beta_2$, holding all other variables constant.

Now, take the second order cross-partial derivative of $E[Y|\textbf{X}]$
with respect to both $x_1$ and $x_2$:
Take the second order cross-partial derivative of $E[Y|\textbf{X}]$ with
respect to both $x_1$ and $x_2$:

$$\gamma_{12}^2 = \frac{\partial^2 E[Y| \textbf{X}]}{\partial x_1 \partial x_2} = \beta_{12}$$

Similar intuition as above holds. The interaction term $\beta_{12}$
shows how effect of $x_1$ on $E[Y|\textbf{X}]$ changes for every one
unit increase in $x_2$ and vice versa.
The interaction term $\beta_{12}$ shows how effect of $x_1$ on
$E[Y|\textbf{X}]$ changes for every one unit increase in $x_2$ and vice
versa.

Now consider a logistic regression model with a non-linear link function
$g(\cdot)$, two continuous predictors and an interaction term:
Expand Down Expand Up @@ -583,7 +582,7 @@ ggplot(long_gamma_df, aes(x = X2_Quantile, y = GammaSquared)) +
theme(plot.title = element_text(hjust = 0.5))
```

<img src="man/figures/README-unnamed-chunk-7-1.png" width="100%" />
<img src="man/figures/README-unnamed-chunk-8-1.png" width="100%" />

Note that the estimate of the interaction term is positive ($0.68345$).
Yet, significant number of the gamma squared values are negative.
Expand Down Expand Up @@ -651,7 +650,7 @@ lines(x1_values, predictions[[3]], lty = 3, lwd = 2)
legend("topleft", legend = c("25% X2b", "50% X2b", "75% X2b"), lty = 1:3, lwd = 2)
```

<img src="man/figures/README-unnamed-chunk-8-1.png" width="100%" />
<img src="man/figures/README-unnamed-chunk-9-1.png" width="100%" />

The alterations in $\hat{E}[Y|\textbf{x}]$ associated with one-unit
increments in `X1b` at the first and third quartiles of `X2b`
Expand Down Expand Up @@ -733,6 +732,16 @@ Research:apantheon of Statistical Significance and Other Faux Pas.”

</div>

<div id="ref-R-RegrCoeffsExplorer" class="csl-entry">

Tyuryaev, Vadim, Aleksandr Tsybakin, Jane Heffernan, Hanna Jankowski,
and Kevin McGregor. 2024. *RegrCoeffsExplorer: Efficient Visualization
of Regression Coefficients for Lm(), Glm(), and Glmnet() Objects*.
Comprehensive R Archive Network (CRAN).
<https://doi.org/10.32614/CRAN.package.RegrCoeffsExplorer>.

</div>

<div id="ref-Wilkinson1999Statistical" class="csl-entry">

Wilkinson, Leland. 1999. “Statistical Methods in Psychology Journals:
Expand Down
Binary file modified man/figures/README-unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-8-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-unnamed-chunk-9-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,16 @@ @book{Hastie2015
publisher = {Chapman \& Hall/CRC},
url={https://www.ime.unicamp.br/~dias/SLS.pdf}}

@Manual{R-RegrCoeffsExplorer,
title = {RegrCoeffsExplorer: Efficient Visualization of Regression Coefficients for lm(), glm(), and glmnet() Objects},
author = {Vadim Tyuryaev and Aleksandr Tsybakin and Jane Heffernan and Hanna Jankowski and Kevin McGregor},
year = {2024},
note = {R package version 1.1.0},
doi = {10.32614/CRAN.package.RegrCoeffsExplorer},
url = {https://CRAN.R-project.org/package=RegrCoeffsExplorer},
abstract = {The visualization tool offers a nuanced understanding of regression dynamics, going beyond traditional per-unit interpretation of continuous variables versus categorical ones. It highlights the impact of unit changes as well as larger shifts like interquartile changes, acknowledging the distribution of empirical data. Furthermore, it generates visualizations depicting alterations in Odds Ratios for predictors across minimum, first quartile, median, third quartile, and maximum values, aiding in comprehending predictor-outcome interplay within empirical data distributions, particularly in logistic regression frameworks.},
publisher = {Comprehensive R Archive Network (CRAN)},
maintainer = {Vadim Tyuryaev <vadim.tyuryaev@gmail.com>},
license = {MIT + file LICENSE}
}

11 changes: 8 additions & 3 deletions vignettes/BetaVisualizer.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ their interpretation align with the paradigm change discussed previously.
plt_1=vis_reg(best_model_lasso,eff_size_diff=c(1,3),
glmnet_fct_var="Originnon-USA")$"PerUnitVis"+
ggtitle("Visualization of CV.GLMNET Results (per unit change)")+
ylim(-4,4)+
ylim(-5,5)+
xlab("Car characteristics")+
ylab("LASSO coefficients")+
theme_bw()+
Expand Down Expand Up @@ -368,12 +368,17 @@ heart_cont_table
# 'age' is skewed variable with a very big range
paste("Range of '\ age \' variable is : ",diff(range(heart_df_filtered$age)))
old_par = par()
# Save the current graphical parameters
old_par = par(no.readonly = TRUE)
# Produce boxplots and histograms
par(mfrow=c(2,2))
hist(heart_df_filtered$age, main="Histogram of Age", xlab="age")
boxplot(heart_df_filtered$age,main="Boxplot of Age", ylab="age")
hist(sqrt(heart_df_filtered$age),main="Histogram of transformed data", xlab="Sqrt(age)")
boxplot(sqrt(heart_df_filtered$age),main="Boxplot of transformed data", ylab="Sqrt(age)")
# Restore previous graphical parameters
par(old_par)
```
Expand Down Expand Up @@ -495,7 +500,7 @@ or up before passing the data to the function.

### 3.6.6 LASSO regression with CIs and custom realized effect size

```{r,fig.height=6,fig.width=12, warning=F}
```{r,fig.height=6,fig.width=12, warning=T}
grid.arrange(vis_reg(out_heart, CI=T, glmnet_fct_var=c("surgery1"),
round_func="none",eff_size_diff=c(1,3))$"SidebySide"
Expand Down

0 comments on commit 9058b82

Please sign in to comment.