diff --git a/README.Rmd b/README.Rmd index e75b63c..e94828a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -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) _Always present effect sizes for primary outcomes_ [@Wilkinson1999Statistical]. @@ -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 } @@ -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} @@ -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: diff --git a/README.md b/README.md index d6513a6..b224386 100644 --- a/README.md +++ b/README.md @@ -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) *Always present effect sizes for primary outcomes* (Wilkinson 1999). @@ -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 @@ -286,7 +295,7 @@ vis_reg(glm_model, CI = TRUE, intercept = TRUE, theme(plot.title = element_text(hjust = 0.5)) ``` - As + 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. @@ -301,7 +310,7 @@ vis_reg(glm_model, CI = TRUE, intercept = TRUE, linetype="dashed", color = "orange", size=1) ``` - + ## Vignettes @@ -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: @@ -583,7 +582,7 @@ ggplot(long_gamma_df, aes(x = X2_Quantile, y = GammaSquared)) + theme(plot.title = element_text(hjust = 0.5)) ``` - + Note that the estimate of the interaction term is positive ($0.68345$). Yet, significant number of the gamma squared values are negative. @@ -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) ``` - + The alterations in $\hat{E}[Y|\textbf{x}]$ associated with one-unit increments in `X1b` at the first and third quartiles of `X2b` @@ -733,6 +732,16 @@ Research:apantheon of Statistical Significance and Other Faux Pas.” +
+ +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). +. + +
+
Wilkinson, Leland. 1999. “Statistical Methods in Psychology Journals: diff --git a/man/figures/README-unnamed-chunk-4-1.png b/man/figures/README-unnamed-chunk-4-1.png index ba4b742..4e3250e 100644 Binary files a/man/figures/README-unnamed-chunk-4-1.png and b/man/figures/README-unnamed-chunk-4-1.png differ diff --git a/man/figures/README-unnamed-chunk-5-1.png b/man/figures/README-unnamed-chunk-5-1.png new file mode 100644 index 0000000..ba4b742 Binary files /dev/null and b/man/figures/README-unnamed-chunk-5-1.png differ diff --git a/man/figures/README-unnamed-chunk-8-1.png b/man/figures/README-unnamed-chunk-8-1.png index b7e0e23..283f6d5 100644 Binary files a/man/figures/README-unnamed-chunk-8-1.png and b/man/figures/README-unnamed-chunk-8-1.png differ diff --git a/man/figures/README-unnamed-chunk-9-1.png b/man/figures/README-unnamed-chunk-9-1.png new file mode 100644 index 0000000..b7e0e23 Binary files /dev/null and b/man/figures/README-unnamed-chunk-9-1.png differ diff --git a/references.bib b/references.bib index 61afdb4..5fc81e9 100644 --- a/references.bib +++ b/references.bib @@ -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 }, + license = {MIT + file LICENSE} +} + diff --git a/vignettes/BetaVisualizer.Rmd b/vignettes/BetaVisualizer.Rmd index bca0eea..727f20f 100644 --- a/vignettes/BetaVisualizer.Rmd +++ b/vignettes/BetaVisualizer.Rmd @@ -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()+ @@ -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) ``` @@ -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"