Skip to content

Commit

Permalink
oddsratio v2.0 (#35)
Browse files Browse the repository at this point in the history
oddsratio v2.0
  • Loading branch information
pat-s authored Jun 13, 2019
2 parents 59a7fc9 + f5fe73c commit 2a252b9
Show file tree
Hide file tree
Showing 41 changed files with 692 additions and 1,322 deletions.
83 changes: 35 additions & 48 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,38 @@
language: r
sudo: false
dist: trusty
cache:
- packages
- ccache
latex: false
# DO NOT CHANGE THE CODE BELOW
before_install:
- R -q -e 'if (!requireNamespace("remotes", quietly = TRUE)) install.packages("remotes")'
- R -q -e 'if (!requireNamespace("curl", quietly = TRUE)) install.packages("curl")'
- R -q -e 'remotes::install_github("ropenscilabs/tic"); tic::prepare_all_stages(); tic::before_install()'
install: R -q -e 'tic::install()'
after_install: R -q -e 'tic::after_install()'
before_script: R -q -e 'tic::before_script()'
script: R -q -e 'tic::script()'
after_success: R -q -e 'tic::after_success()'
after_failure: R -q -e 'tic::after_failure()'
before_deploy: R -q -e 'tic::before_deploy()'
deploy:
provider: script
script: R -q -e 'tic::deploy()'
on:
all_branches: true
after_deploy: R -q -e 'tic::after_deploy()'
after_script: R -q -e 'tic::after_script()'
# DO NOT CHANGE THE CODE ABOVE


# These steps apply to all matrix jobs unless defined differently in tic.R
before_install:
- R -q -e 'install.packages("remotes"); remotes::install_github("ropenscilabs/tic"); tic::prepare_all_stages(); tic::before_install(); remotes::install_github("tidyverse/ggplot2")'
# Custom parts:

matrix:
fast_finish: true
allow_failures:
- env: NB='w/ lintr'
- env: NB='w/ covr'
include:
- os: linux
r: devel
install: R -q -e 'tic::install()'
after_install: R -q -e 'tic::after_install()'
before_script: R -q -e 'tic::before_script()'
script: R -q -e 'tic::script()'
before_deploy: R -q -e 'tic::before_deploy()'
deploy:
provider: script
script: R -q -e 'tic::deploy()'
on:
branch: master
condition:
- $TRAVIS_PULL_REQUEST = false
- $TRAVIS_EVENT_TYPE != cron
after_deploy: R -q -e 'tic::after_deploy()'
- os: osx
r: release
install: R -q -e 'tic::install()'
after_install: R -q -e 'tic::after_install()'
before_script: R -q -e 'tic::before_script()'
script: R -q -e 'tic::script()'
- os: linux
r: devel
env: NB='w/ covr'
- os: linux
r: devel
env: NB='w/ lintr'
# Header
language: r
sudo: false
dist: xenial
cache: packages
latex: true
pandoc_version: 2.5

notifications:
on_success: change # default: always
on_failure: change # default: always
email: false
env:
global:
- _R_CHECK_FORCE_SUGGESTS_=false
- MAKEFLAGS="-j 2"
- BUILD_PKGDOWN=true
- _R_CHECK_TESTS_NLINES_=0
79 changes: 46 additions & 33 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
Package: oddsratio
Version: 1.0.3
Date: 2018-07-15
Title: Odds Ratio Calculation for GAM(M)s & GLM(M)s
Authors@R: c(
person("Patrick", "Schratz", ,
email = "[email protected]",
role = c("aut", "cre"),
comment = c(ORCID = '0000-0003-0748-6624'))
)
Description: Simplified odds ratio calculation of GAM(M)s & GLM(M)s.
Provides structured output (data frame) of all predictors and their corresponding odds ratios and confident intervals for further analyses.
It helps to avoid false references of predictors and increments by specifying these parameters in a list instead of using 'exp(coef(model))' (standard approach of odds ratio calculation for GLMs) which just returns a plain numeric output.
For GAM(M)s, odds ratio calculation is highly simplified with this package since it takes care of the multiple 'predict()' calls of the chosen predictor while holding other predictors constant.
Also, this package allows odds ratio calculation of percentage steps across the whole predictor distribution range for GAM(M)s.
In both cases, confident intervals are returned additionally.
Calculated odds ratio of GAM(M)s can be inserted into the smooth function plot.
Version: 2.0.0
Date: 2019-06-13
Authors@R:
person(given = "Patrick",
family = "Schratz",
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-0748-6624"))
Description: Simplified odds ratio calculation of GAM(M)s &
GLM(M)s. Provides structured output (data frame) of all predictors
and their corresponding odds ratios and confident intervals for
further analyses. It helps to avoid false references of predictors
and increments by specifying these parameters in a list instead of
using 'exp(coef(model))' (standard approach of odds ratio calculation
for GLMs) which just returns a plain numeric output. For GAM(M)s,
odds ratio calculation is highly simplified with this package since it
takes care of the multiple 'predict()' calls of the chosen predictor
while holding other predictors constant. Also, this package allows
odds ratio calculation of percentage steps across the whole predictor
distribution range for GAM(M)s. In both cases, confident intervals
are returned additionally. Calculated odds ratio of GAM(M)s can be
inserted into the smooth function plot.
License: MIT + file LICENSE
URL: https://github.com/pat-s/oddsratio
BugReports: https://github.com/pat-s/oddsratio/issues
Depends: R (>= 3.0.0)
Imports: mgcv,
MASS,
stats,
ggplot2 (>= 3.0.0),
cowplot
License: MIT + file LICENSE
RoxygenNote: 6.0.1
Suggests: knitr,
rmarkdown,
grid,
gtable,
scales,
testthat,
pacman,
gam
LazyData: true
Depends:
R (>= 3.0.0)
Imports:
ggplot2 (>= 3.0.0),
mgcv,
stats,
stringr,
tibble
Suggests:
cowplot,
gam,
grid,
gtable,
knitr,
MASS,
rmarkdown,
scales,
testthat
VignetteBuilder:
knitr
ByteCompile: true
VignetteBuilder: knitr
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1
5 changes: 3 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ export(no_plot)
export(or_gam)
export(or_glm)
export(plot_gam)
import(MASS)
import(ggplot2)
import(mgcv)
importFrom(cowplot,background_grid)
importFrom(grDevices,dev.off)
importFrom(grDevices,png)
importFrom(graphics,plot)
importFrom(stats,coefficients)
importFrom(stats,confint)
importFrom(stats,predict)
importFrom(stringr,str_remove_all)
importFrom(tibble,as_tibble)
importFrom(tibble,tibble)
48 changes: 0 additions & 48 deletions NEWS

This file was deleted.

7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# oddsratio 2.0.0 (June 13 2019)

* return a `tibble` instead of a `data.frame`
* clean up code base
* don't use `cowplot` ggplot theme by default
* optimize wording in vignette

# oddsratio 1.0.3 (June 19 2018)

* update functions to work with ggplot2 v3.0.0
Expand Down
6 changes: 3 additions & 3 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#'
#' @docType data
#'
#' @format a `data.frame` randomly created numerical and non-numerical variables
#' @format a [tibble] randomly created numerical and non-numerical variables
NULL

#' data_glm
Expand All @@ -23,8 +23,8 @@ NULL
#' @keywords datasets
#' @keywords internal
#'
#' @format a `data.frame` randomly created numerical and non-numerical variables
#' @format a [tibble] randomly created numerical and non-numerical variables
#'
#' @source Taken from \url{http://www.ats.ucla.edu/stat/r/dae/logit.htm}, direct download
#' link: \url{http://www.ats.ucla.edu/stat/data/binary.csv}
NULL
NULL
26 changes: 16 additions & 10 deletions R/helper_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
#' n <- 200
#' sig <- 2
#' dat <- gamSim(1, n = n, scale = sig, verbose = FALSE)
#' dat$x4 <- as.factor(c(rep("A", 50), rep("B", 50), rep("C", 50),
#' rep("D", 50)))
#' dat$x4 <- as.factor(c(
#' rep("A", 50), rep("B", 50), rep("C", 50),
#' rep("D", 50)
#' ))
#' fit_gam <- gam(y ~ s(x0) + s(I(x1^2)) + s(x2) +
#' offset(x3) + x4, data = dat) # fit model
#' offset(x3) + x4, data = dat) # fit model
#'
#' tmp <- plot(fit_gam, pages = 1) # plot output
#' tmp <- no_plot(fit_gam) # no plot output
Expand Down Expand Up @@ -65,10 +67,12 @@ no_plot <- function(model = NULL) {
#' n <- 200
#' sig <- 2
#' dat <- gamSim(1, n = n, scale = sig, verbose = FALSE)
#' dat$x4 <- as.factor(c(rep("A", 50), rep("B", 50), rep("C", 50),
#' rep("D", 50)))
#' dat$x4 <- as.factor(c(
#' rep("A", 50), rep("B", 50), rep("C", 50),
#' rep("D", 50)
#' ))
#' fit_gam <- gam(y ~ s(x0) + s(I(x1^2)) + s(x2) +
#' offset(x3) + x4, data = dat) # fit model
#' offset(x3) + x4, data = dat) # fit model
#'
#' tmp <- gam_to_df(fit_gam, "x2")
#' @export
Expand All @@ -80,9 +84,11 @@ gam_to_df <- function(model = NULL, pred = NULL) {
# get list index of spec. predictor
set_pred <- which(grepl(pred, plot_df))

df <- data.frame(x = plot_df[[set_pred]]$x,
se_upr = plot_df[[set_pred]]$fit + plot_df[[set_pred]]$se,
se_lwr = plot_df[[set_pred]]$fit - plot_df[[set_pred]]$se,
y = plot_df[[set_pred]]$fit)
df <- tibble(
x = plot_df[[set_pred]]$x,
se_upr = plot_df[[set_pred]]$fit + plot_df[[set_pred]]$se,
se_lwr = plot_df[[set_pred]]$fit - plot_df[[set_pred]]$se,
y = plot_df[[set_pred]]$fit
)
return(df)
}
Loading

0 comments on commit 2a252b9

Please sign in to comment.