Skip to content

Commit

Permalink
update data source of glm data
Browse files Browse the repository at this point in the history
  • Loading branch information
pat-s committed Sep 10, 2018
1 parent 72155b3 commit 30721f3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ For factor variables (here: `rank` with 4 levels), automatically all odds ratios
corresponding to the base level (here: `rank1`) are returned including their
respective confident intervals. The default level is 95%.
However, other levels can be specified with the param `CI`.
Data source: http://www.ats.ucla.edu/stat/r/dae/logit.htm
Data source: https://stats.idre.ucla.edu/stat/data/binary.csv

```{r}
pacman::p_load(oddsratio, mgcv)
Expand Down
56 changes: 42 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@

#### General

[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1095473.svg)](https://doi.org/10.5281/zenodo.1095473)
[![Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1095473.svg)](https://doi.org/10.5281/zenodo.1095473)

| Resource: | CRAN | Travis CI | Appveyor |
|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *Platforms:* | *Multiple* | *Linux & macOS* | *Windows* |
| R CMD check | <a href="https://cran.r-project.org/web/checks/check_results_oddsratio.html"><img border="0" src="http://www.r-pkg.org/badges/version/oddsratio" alt="CRAN version"></a> | <a href="https://travis-ci.org/pat-s/oddsratio"><img src="https://travis-ci.org/pat-s/oddsratio.svg?branch=dev" alt="Build status"></a> | <a href="https://ci.appveyor.com/project/pat-s/oddsratio"><img src="https://ci.appveyor.com/api/projects/status/p72njexjxqa9ko96/branch/dev?svg=true" alt="Build status"></a> |
| Test coverage | | <a href="https://codecov.io/gh/pat-s/oddsratio"><img src="https://codecov.io/gh/pat-s/oddsratio/branch/dev/graph/badge.svg" alt="Coverage Status"/></a> | |

#### CRAN

[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/oddsratio)](https://cran.r-project.org/package=oddsratio) [![Downloads](https://cranlogs.r-pkg.org/badges/oddsratio?color=brightgreen)](https://www.r-pkg.org/pkg/oddsratio) ![](https://cranlogs.r-pkg.org/badges/grand-total/oddsratio)
[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/oddsratio)](https://cran.r-project.org/package=oddsratio)
[![Downloads](https://cranlogs.r-pkg.org/badges/oddsratio?color=brightgreen)](https://www.r-pkg.org/pkg/oddsratio)
![](https://cranlogs.r-pkg.org/badges/grand-total/oddsratio)

Functions for calculation and plotting of odds ratios of Generalized Additive (Mixed) Models and Generalized Linear (Mixed) Models with a binomial response variable (i.e. logistic regression models).
Functions for calculation and plotting of odds ratios of Generalized
Additive (Mixed) Models and Generalized Linear (Mixed) Models with a
binomial response variable (i.e. logistic regression models).

Installation
------------
## Installation

Install from CRAN:

Expand All @@ -30,13 +36,17 @@ Get the development version from Github:
remotes::install_github("pat-s/oddsratio")
```

Examples
--------
## Examples

### GLM

Odds ratio calculation of predictors `gre` & `gpa` of a fitted model `fit_glm` with increment steps of 380 and 5, respectively.
For factor variables (here: `rank` with 4 levels), automatically all odds ratios corresponding to the base level (here: `rank1`) are returned including their respective confident intervals. The default level is 95%. However, other levels can be specified with the param `CI`. Data source: <http://www.ats.ucla.edu/stat/r/dae/logit.htm>
Odds ratio calculation of predictors `gre` & `gpa` of a fitted model
`fit_glm` with increment steps of 380 and 5, respectively.
For factor variables (here: `rank` with 4 levels), automatically all
odds ratios corresponding to the base level (here: `rank1`) are returned
including their respective confident intervals. The default level is
95%. However, other levels can be specified with the param `CI`. Data
source: <https://stats.idre.ucla.edu/stat/data/binary.csv>

``` r
pacman::p_load(oddsratio, mgcv)
Expand All @@ -50,9 +60,17 @@ or_glm(data = df, model = fit_glm,

### GAM

For GAMs, the calculation of odds ratio is different. Due to its non-linear definition, odds ratios do only apply to specific value changes and are not constant throughout the whole value range of the predictor as for GLMs. Hence, odds ratios of GAMs can only be computed for one predictor at a time by holding all other predictors at a fixed value while changing the value of the specific predictor. Confident intervals are currently fixed to the 95% level for GAMs. Data source: `?mgcv::predict.gam()`
For GAMs, the calculation of odds ratio is different. Due to its
non-linear definition, odds ratios do only apply to specific value
changes and are not constant throughout the whole value range of the
predictor as for GLMs. Hence, odds ratios of GAMs can only be computed
for one predictor at a time by holding all other predictors at a fixed
value while changing the value of the specific predictor. Confident
intervals are currently fixed to the 95% level for GAMs. Data source:
`?mgcv::predict.gam()`

Here, the usage of `or_gam()` is shown by calculating odds ratios of pred `x2` for a 20% steps across the whole value range of the predictor.
Here, the usage of `or_gam()` is shown by calculating odds ratios of
pred `x2` for a 20% steps across the whole value range of the predictor.

``` r
set.seed(1234)
Expand All @@ -66,22 +84,27 @@ or_gam(data = df, model = fit_gam, pred = "x2",
percentage = 20, slice = TRUE)
```

If you want to compute a single odds ratio for specific values, simply set param `slice = FALSE`:
If you want to compute a single odds ratio for specific values, simply
set param `slice = FALSE`:

``` r
or_gam(data = df, model = fit_gam,
pred = "x2", values = c(0.099, 0.198))
```

Plotting of GAM smooths is also supported:
Plotting of GAM smooths is also
supported:

``` r
plot_gam(fit_gam, pred = "x2", title = "Predictor 'x2'")
```

<p align="center">

<img src="https://raw.githubusercontent.com/pat-s/oddsratio/dev/man/figures/plot_gam.png" width="80%"/>

</p>

Insert the calculated odds ratios into the smoothing function:

``` r
Expand All @@ -97,8 +120,11 @@ plot
```

<p align="center">

<img src="https://raw.githubusercontent.com/pat-s/oddsratio/dev/man/figures/plot_gam2.png" width="80%"/>

</p>

Insert multiple odds ratios into one smooth:

``` r
Expand All @@ -114,5 +140,7 @@ insert_or(plot, or_object2, or_yloc = 2.1, values_yloc = 2,
```

<p align="center">

<img src="https://raw.githubusercontent.com/pat-s/oddsratio/dev/man/figures/plot_gam3.png" width="80%"/>

</p>
2 changes: 1 addition & 1 deletion vignettes/function_tutorial.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Aesthetics like opacity or color are fully customizable.
## GLM example

Fit model.
Data source: http://www.ats.ucla.edu/stat/r/dae/logit.htm
Data source: https://stats.idre.ucla.edu/stat/data/binary.csv

```{r}
fit_glm <- glm(admit ~ gre + gpa + rank, data = data_glm, family = "binomial")
Expand Down

0 comments on commit 30721f3

Please sign in to comment.