diff --git a/docs/LICENSE.html b/docs/LICENSE.html new file mode 100644 index 0000000..800c774 --- /dev/null +++ b/docs/LICENSE.html @@ -0,0 +1,131 @@ + + + + + + + + +License • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
YEAR: 2016
+COPYRIGHT HOLDER: Patrick Schratz
+
+ +
+ +
+ + + +
+ + + diff --git a/docs/articles/function_tutorial.html b/docs/articles/function_tutorial.html new file mode 100644 index 0000000..1b9f6a0 --- /dev/null +++ b/docs/articles/function_tutorial.html @@ -0,0 +1,246 @@ + + + + + + + +Function tutorial • oddsratio + + + + + + +
+
+ + + +
+
+ + + + +
+
+

+Load example data & fit model

+

Data source: ?mgcv::predict.gam

+
library(oddsratio)
+
+fit_gam <- mgcv::gam(y ~ s(x0) + s(I(x1^2)) + s(x2) + offset(x3) + x4, 
+                     data = data_gam)
+
+
+

+GAM example

+
+

+Calculate OR for specific increment step of continuous variable

+

To calculate specific increment steps of fit_gam, we take predictor x2 (randomly chosen) and specify for which values we want to calculate the odds ratio.
+We can see that the odds of response y happening are 22 times higher when predictor x2 increases from 0.099 to 0.198 while holding all other predictors constant.

+
or_gam(data = data_gam, model = fit_gam, pred = "x2", 
+       values = c(0.099, 0.198))
+#>   predictor value1 value2 oddsratio CI_low (2.5%) CI_high (97.5%)
+#> 1        x2  0.099  0.198  23.32353      23.30424        23.34283
+

Usually, this calculation is done by setting all predictors to their mean value, predict the response, change the desired predictor to a new value and predict the response again. These actions results in two log odds values, respectively, which are transformed into odds by exponentiating them. Finally, the odds ratio can be calculated from these two odds values.

+
+
+

+Calculate OR for level change of indicator variable

+

If the predictor is an indicator variable, i.e. consists of fixed levels, you can use the function in the same way by just putting in the respective levels you are interested in:

+
or_gam(data = data_gam, model = fit_gam, 
+       pred = "x4", values = c("A", "B"))
+#>   predictor value1 value2 oddsratio CI_low (2.5%) CI_high (97.5%)
+#> 1        x4      A      B  1.377537      1.334837        1.421604
+

Here, the change in odds of y happening if predictor x4 is changing from level A to B is rather small. In detail, an increase in odds of 37.8% is reported.

+
+
+

+Calculate ORs for percentage increments of predictor distribution

+

To get an impression of odds ratio behaviour throughout the complete range of the smoothing function of the fitted GAM model, you can calculate odds ratios based on percentage breaks of the predictors distribution.
+Here we slice predictor x2 into 5 parts by taking the predictor values of every 20% increment step.

+
or_gam(data = data_gam, model = fit_gam, pred = "x2", 
+       percentage = 20, slice = TRUE)
+#>   predictor value1 value2 perc1 perc2 oddsratio CI_low (2.5%)
+#> 1        x2  0.001  0.200     0    20   2510.77       1091.68
+#> 2        x2  0.200  0.400    20    40      0.03          0.03
+#> 3        x2  0.400  0.599    40    60      0.58          0.56
+#> 4        x2  0.599  0.799    60    80      0.06          0.06
+#> 5        x2  0.799  0.998    80   100      0.41          0.75
+#>   CI_high (97.5%)
+#> 1         5774.53
+#> 2            0.03
+#> 3            0.60
+#> 4            0.06
+#> 5            0.22
+

We can see that there is a high odds ratio reported when increasing predictor x2 from 0.008 to 0.206 while all further predictor increases decrease the odds of response y happening substantially.

+
+
+

+Plot GAM(M) smoothing functions

+

Right now, the only (quick) possibility to plot the smoothing functions of a GAM(M) was to use the base plot() function. The fiddly work to do the same using the ggplot2 plotting system is done by plot_gam():

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

+

You can further customize the look using other colors or linetypes.

+
+
+

+Add odds ratio information into smoothing function plot

+

So now, we have the odds ratios and we have a plot of the smoothing function. Why not combine both? We can do so using insert_or(). Its main arguments are (i) a ggplot plotting object containing the smooth function and a data frame returned from or_gam() containing information about the predictor and the respective values we want to insert.

+
plot_object <- plot_gam(fit_gam, pred = "x2", title = "Predictor 'x2'")
+or_object <- or_gam(data = data_gam, model = fit_gam, 
+                    pred = "x2", values = c(0.099, 0.198))
+
+plot <- insert_or(plot_object, or_object, or_yloc = 3,
+                  values_xloc = 0.05, arrow_length = 0.02, 
+                  arrow_col = "red")
+plot
+

+

The odds ratio information is always centered between the two vertical lines. Hence it only looks nice if the gap between the two chosen values (here 0.099 and 0.198) is large enough. If the smoothing line crosses your inserted text, you can just correct it adjusting or_yloc. This param sets the y-location of the inserted odds ratio information.

+

Depending on the digits of your chosen values (here 3), you might also need to adjust the x-axis location of the two values so that they do not interfer with the vertical line.

+

Let’s do all this by inserting another odds ratio into this plot! This time we simply take the already produced plot as an input to insert_or() and use a new odds ratio object:

+
or_object2 <- or_gam(data = data_gam, model = fit_gam, 
+                     pred = "x2", values = c(0.4, 0.6))
+
+insert_or(plot, or_object2, or_yloc = 2.1, values_yloc = 2,
+          line_col = "green4", text_col = "black",
+          rect_col = "green4", rect_alpha = 0.2,
+          line_alpha = 1, line_type = "dashed",
+          arrow_xloc_r = 0.01, arrow_xloc_l = -0.01,
+          arrow_length = 0.02, rect = TRUE) 
+

+

Using rect = TRUE, you can additionally highlight certain odds ratio intervals. Aesthetics like opacity or color are fully customizable.

+
+
+
+

+GLM example

+

Fit model.
+Data source: http://www.ats.ucla.edu/stat/r/dae/logit.htm

+
fit_glm <- glm(admit ~ gre + gpa + rank, data = data_glm, family = "binomial")
+
+

+Calculate odds ratio for continuous predictors

+

For GLMs, the odds ratio calculation is simpler because odds ratio changes correspond to fixed predictor increases throughout the complete value range of each predictor.

+

Hence, function or_glm takes the increment steps of each predictor directly as an input in its parameter incr.

+

To avoid false predictor/value assignments, the combinations need to be given in a list.

+

Odds ratios of indicator variables are computed automatically and do always refer to the base factor level.

+

Indicator predictor rank has four levels. Subsequently, we will get three odds ratio outputs referring to the base factor level (here: rank1).

+

The output is interpreted as follows: “Having rank2 instead of rank1 while holding all other values constant results in a decrease in odds of 49.1% (1-0.509)”.

+
or_glm(data = data_glm, model = fit_glm, incr = list(gre = 380, gpa = 5))
+#>   predictor oddsratio CI_low (2.5 %) CI_high (97.5 %)          increment
+#> 1       gre     2.364          1.054            5.396                380
+#> 2       gpa    55.712          2.229         1511.282                  5
+#> 3     rank2     0.509          0.272            0.945 Indicator variable
+#> 4     rank3     0.262          0.132            0.512 Indicator variable
+#> 5     rank4     0.212          0.091            0.471 Indicator variable
+

You can also set other confident intervals for GLM(M) models. The resulting data frame will automatically adjust its column names to the specified level.

+
or_glm(data = data_glm, model = fit_glm, 
+       incr = list(gre = 380, gpa = 5), CI = 0.70)
+#>   predictor oddsratio CI_low (15 %) CI_high (85 %)          increment
+#> 1       gre     2.364         1.540          3.647                380
+#> 2       gpa    55.712        10.084        314.933                  5
+#> 3     rank2     0.509         0.366          0.706 Indicator variable
+#> 4     rank3     0.262         0.183          0.374 Indicator variable
+#> 5     rank4     0.212         0.136          0.325 Indicator variable
+
+
+
+
+ + + +
+ + + +
+ + + diff --git a/docs/articles/function_tutorial_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/function_tutorial_files/figure-html/unnamed-chunk-6-1.png new file mode 100644 index 0000000..7427427 Binary files /dev/null and b/docs/articles/function_tutorial_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/function_tutorial_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/function_tutorial_files/figure-html/unnamed-chunk-7-1.png new file mode 100644 index 0000000..71bee68 Binary files /dev/null and b/docs/articles/function_tutorial_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/function_tutorial_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/function_tutorial_files/figure-html/unnamed-chunk-8-1.png new file mode 100644 index 0000000..6136821 Binary files /dev/null and b/docs/articles/function_tutorial_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html new file mode 100644 index 0000000..b38cbd1 --- /dev/null +++ b/docs/articles/index.html @@ -0,0 +1,133 @@ + + + + + + + + +Articles • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+

All vignettes

+

+ + +
+
+
+ + +
+ + + diff --git a/docs/authors.html b/docs/authors.html new file mode 100644 index 0000000..1329d44 --- /dev/null +++ b/docs/authors.html @@ -0,0 +1,133 @@ + + + + + + + + +Authors • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
    +
  • +

    Patrick Schratz. Author, maintainer. +

    +
  • +
+ +
+ +
+ + +
+ + + diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..a4a7803 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,245 @@ + + + + + + + +Odds Ratio Calculation for GAM(M)s & GLM(M)s • oddsratio + + + + + + +
+
+ + + +
+
+ + + + +
+
+

+General

+ + ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Resource:CRANTravis CIAppveyor
Platforms:MultipleLinux & macOSWindows
R CMD checkCRAN versionBuild statusBuild status
Test coverageCoverage Status
+
+
+

+CRAN

+

CRAN_Status_Badge Downloads

+

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

+

Install from CRAN:

+
install.packages("oddsratio")
+

Get the development version from Github:

+
remotes::install_github("pat-s/oddsratio@dev")
+
+
+

+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

+
pacman::p_load(oddsratio, mgcv)
+df <- data_glm
+df$rank <- factor(df$rank)
+fit_glm <- glm(admit ~ gre + gpa + rank, data = df, family = "binomial")
+
+or_glm(data = df, model = fit_glm, 
+       incr = list(gre = 380, gpa = 5, CI = 0.95))
+
+
+

+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.

+
set.seed(1234)
+n <- 200
+sig <- 2
+df <- gamSim(1, n = n,scale = sig, verbose = FALSE)
+df$x4 <- as.factor(c(rep("A", 50), rep("B", 50), rep("C", 50), rep("D", 50)))
+fit_gam <- mgcv::gam(y ~ s(x0) + s(I(x1^2)) + s(x2) + offset(x3) + x4, data = df)
+
+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:

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

Plotting of GAM smooths is also supported:

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

+

+

Insert the calculated odds ratios into the smoothing function:

+
plot_object <- plot_gam(fit_gam, pred = "x2", title = "Predictor 'x2'")
+or_object <- or_gam(data = df, model = fit_gam, 
+                    pred = "x2", values = c(0.099, 0.198))
+
+plot <- insert_or(plot_object, or_object, or_yloc = 3,
+                  values_xloc = 0.04, line_size = 0.5, 
+                  line_type = "dotdash", values_yloc = 0.5,
+                  arrow_col = "red")
+plot
+

+

+

Insert multiple odds ratios into one smooth:

+
or_object2 <- or_gam(data = df, model = fit_gam, pred = "x2", 
+                     values = c(0.4, 0.6))
+
+insert_or(plot, or_object2, or_yloc = 2.1, values_yloc = 2,
+          line_col = "green4", text_col = "black",
+          rect_col = "green4", rect_alpha = 0.2,
+          line_alpha = 1, line_type = "dashed",
+          arrow_xloc_r = 0.01, arrow_xloc_l = -0.01,
+          arrow_length = 0.01, rect = T)   
+

+

+
+
+
+
+ + + +
+ + + +
+ + + diff --git a/docs/jquery.sticky-kit.min.js b/docs/jquery.sticky-kit.min.js new file mode 100644 index 0000000..e2a3c6d --- /dev/null +++ b/docs/jquery.sticky-kit.min.js @@ -0,0 +1,9 @@ +/* + Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | http://leafo.net +*/ +(function(){var b,f;b=this.jQuery||window.jQuery;f=b(window);b.fn.stick_in_parent=function(d){var A,w,J,n,B,K,p,q,k,E,t;null==d&&(d={});t=d.sticky_class;B=d.inner_scrolling;E=d.recalc_every;k=d.parent;q=d.offset_top;p=d.spacer;w=d.bottoming;null==q&&(q=0);null==k&&(k=void 0);null==B&&(B=!0);null==t&&(t="is_stuck");A=b(document);null==w&&(w=!0);J=function(a,d,n,C,F,u,r,G){var v,H,m,D,I,c,g,x,y,z,h,l;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);I=A.height();g=a.parent();null!=k&&(g=g.closest(k)); +if(!g.length)throw"failed to find stick parent";v=m=!1;(h=null!=p?p&&a.closest(p):b("
"))&&h.css("position",a.css("position"));x=function(){var c,f,e;if(!G&&(I=A.height(),c=parseInt(g.css("border-top-width"),10),f=parseInt(g.css("padding-top"),10),d=parseInt(g.css("padding-bottom"),10),n=g.offset().top+c+f,C=g.height(),m&&(v=m=!1,null==p&&(a.insertAfter(h),h.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(t),e=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q, +u=a.outerHeight(!0),r=a.css("float"),h&&h.css({width:a.outerWidth(!0),height:u,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),e))return l()};x();if(u!==C)return D=void 0,c=q,z=E,l=function(){var b,l,e,k;if(!G&&(e=!1,null!=z&&(--z,0>=z&&(z=E,x(),e=!0)),e||A.height()===I||x(),e=f.scrollTop(),null!=D&&(l=e-D),D=e,m?(w&&(k=e+u+c>C+n,v&&!k&&(v=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),eb&&!v&&(c-=l,c=Math.max(b-u,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):e>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(t),null==p&&(a.after(h),"left"!==r&&"right"!==r||h.append(a)),a.trigger("sticky_kit:stick")),m&&w&&(null==k&&(k=e+u+c>C+n),!v&&k)))return v=!0,"static"===g.css("position")&&g.css({position:"relative"}), +a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},y=function(){x();return l()},H=function(){G=!0;f.off("touchmove",l);f.off("scroll",l);f.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});g.position("position","");if(m)return null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),h.remove()),a.removeClass(t)},f.on("touchmove",l),f.on("scroll",l),f.on("resize", +y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(l,0)}};n=0;for(K=this.length;n + + + + + diff --git a/docs/news/index.html b/docs/news/index.html new file mode 100644 index 0000000..371f78e --- /dev/null +++ b/docs/news/index.html @@ -0,0 +1,203 @@ + + + + + + + + +All news • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+ +
+ + +
+
+

+oddsratio 1.0.0 (June 12 2017)

+
+

+Major

+
    +
  • rename functions (snake_case)
  • +
+
+
+
+

+oddsratio 0.3.1 (Nov 9 2016)

+
    +
  • update functions to work with ggplot2 v2.2
  • +
  • add data and enable lazy loading in examples
  • +
+
+
+

+oddsratio 0.3.0 (Oct 27 2016)

+
+

+New functions

+
    +
  • +plot_smooth.gam(): Lets you plot smoothing functions of GAM(M)s using ggplot2.
  • +
  • +add.oddsratio.into.plot(): Add odds ratios into plot of GAM(M) smoothing function.
  • +
+
+
+

+Function updates

+
    +
  • +calc.oddsratio.glm, calc.oddsratio.gam: Add odds ratio confident interval calculation
  • +
  • For GLM models CI level can be specified manually.
  • +
  • Print ‘CI’ warning if model is of type glmmPQL +
  • +
+
+
+
+

+oddsratio 0.2.0 (Oct 12 2016)

+
    +
  • Remove param quietly +
  • +
  • return data.frame in any case
  • +
  • update DESCRIPTION
  • +
+
+
+

+oddsratio 0.1.0 (Oct 11 2016)

+
    +
  • Initial release attempt to CRAN
  • +
+
+
+
+ + + +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/pkgdown.css b/docs/pkgdown.css new file mode 100644 index 0000000..209ce57 --- /dev/null +++ b/docs/pkgdown.css @@ -0,0 +1,163 @@ +/* Sticker footer */ +body > .container { + display: flex; + padding-top: 60px; + min-height: calc(100vh); + flex-direction: column; +} + +body > .container .row { + flex: 1; +} + +footer { + margin-top: 45px; + padding: 35px 0 36px; + border-top: 1px solid #e5e5e5; + color: #666; + display: flex; +} +footer p { + margin-bottom: 0; +} +footer div { + flex: 1; +} +footer .pkgdown { + text-align: right; +} +footer p { + margin-bottom: 0; +} + +img.icon { + float: right; +} + +img { + max-width: 100%; +} + +/* Section anchors ---------------------------------*/ + +a.anchor { + margin-left: -30px; + display:inline-block; + width: 30px; + height: 30px; + visibility: hidden; + + background-image: url(./link.svg); + background-repeat: no-repeat; + background-size: 20px 20px; + background-position: center center; +} + +.hasAnchor:hover a.anchor { + visibility: visible; +} + +@media (max-width: 767px) { + .hasAnchor:hover a.anchor { + visibility: hidden; + } +} + + +/* Fixes for fixed navbar --------------------------*/ + +.contents h1, .contents h2, .contents h3, .contents h4 { + padding-top: 60px; + margin-top: -60px; +} + +/* Static header placement on mobile devices */ +@media (max-width: 767px) { + .navbar-fixed-top { + position: absolute; + } + .navbar { + padding: 0; + } +} + + +/* Sidebar --------------------------*/ + +#sidebar { + margin-top: 30px; +} +#sidebar h2 { + font-size: 1.5em; + margin-top: 1em; +} + +#sidebar h2:first-child { + margin-top: 0; +} + +#sidebar .list-unstyled li { + margin-bottom: 0.5em; +} + +/* Reference index & topics ----------------------------------------------- */ + +.ref-index th {font-weight: normal;} +.ref-index h2 {font-size: 20px;} + +.ref-index td {vertical-align: top;} +.ref-index .alias {width: 40%;} +.ref-index .title {width: 60%;} + +.ref-index .alias {width: 40%;} +.ref-index .title {width: 60%;} + +.ref-arguments th {text-align: right; padding-right: 10px;} +.ref-arguments th, .ref-arguments td {vertical-align: top;} +.ref-arguments .name {width: 20%;} +.ref-arguments .desc {width: 80%;} + +/* Nice scrolling for wide elements --------------------------------------- */ + +table { + display: block; + overflow: auto; +} + +/* Syntax highlighting ---------------------------------------------------- */ + +pre { + word-wrap: normal; + word-break: normal; + border: 1px solid #eee; +} + +pre, code { + background-color: #f8f8f8; + color: #333; +} + +pre .img { + margin: 5px 0; +} + +pre .img img { + background-color: #fff; + display: block; + height: auto; +} + +code a, pre a { + color: #375f84; +} + +.fl {color: #1514b5;} +.fu {color: #000000;} /* function */ +.ch,.st {color: #036a07;} /* string */ +.kw {color: #264D66;} /* keyword */ +.co {color: #888888;} /* comment */ + +.message { color: black; font-weight: bolder;} +.error { color: orange; font-weight: bolder;} +.warning { color: #6A0366; font-weight: bolder;} + diff --git a/docs/pkgdown.js b/docs/pkgdown.js new file mode 100644 index 0000000..4b81713 --- /dev/null +++ b/docs/pkgdown.js @@ -0,0 +1,45 @@ +$(function() { + $("#sidebar").stick_in_parent({offset_top: 40}); + $('body').scrollspy({ + target: '#sidebar', + offset: 60 + }); + + var cur_path = paths(location.pathname); + $("#navbar ul li a").each(function(index, value) { + if (value.text == "Home") + return; + if (value.getAttribute("href") === "#") + return; + + var path = paths(value.pathname); + if (is_prefix(cur_path, path)) { + // Add class to parent
  • , and enclosing
  • if in dropdown + var menu_anchor = $(value); + menu_anchor.parent().addClass("active"); + menu_anchor.closest("li.dropdown").addClass("active"); + } + }); +}); + +function paths(pathname) { + var pieces = pathname.split("/"); + pieces.shift(); // always starts with / + + var end = pieces[pieces.length - 1]; + if (end === "index.html" || end === "") + pieces.pop(); + return(pieces); +} + +function is_prefix(needle, haystack) { + if (needle.length > haystack.lengh) + return(false); + + for (var i = 0; i < haystack.length; i++) { + if (needle[i] != haystack[i]) + return(false); + } + + return(true); +} diff --git a/docs/reference/data_gam.html b/docs/reference/data_gam.html new file mode 100644 index 0000000..8f30b35 --- /dev/null +++ b/docs/reference/data_gam.html @@ -0,0 +1,150 @@ + + + + + + + + +data_gam — data_gam • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + + +

    data_gam

    + + +
    data(data_gam)
    + +

    Format

    + +

    a data.frame randomly created numerical and non-numerical variables

    + +

    Source

    + +

    Taken from ?mgcv::gam and added variable "x4"

    + + +
    + +
    + +
    + + +
    +

    Site built with pkgdown.

    +
    + +
    +
    + + + diff --git a/docs/reference/data_glm.html b/docs/reference/data_glm.html new file mode 100644 index 0000000..11049a1 --- /dev/null +++ b/docs/reference/data_glm.html @@ -0,0 +1,151 @@ + + + + + + + + +data_glm — data_glm • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + + +

    data_glm

    + + +
    data(data_glm)
    + +

    Format

    + +

    a data.frame randomly created numerical and non-numerical variables

    + +

    Source

    + +

    Taken from http://www.ats.ucla.edu/stat/r/dae/logit.htm, direct download +link: http://www.ats.ucla.edu/stat/data/binary.csv

    + + +
    + +
    + +
    + + +
    +

    Site built with pkgdown.

    +
    + +
    +
    + + + diff --git a/docs/reference/figures/plot_gam.png b/docs/reference/figures/plot_gam.png new file mode 100644 index 0000000..840be4d Binary files /dev/null and b/docs/reference/figures/plot_gam.png differ diff --git a/docs/reference/figures/plot_gam2.png b/docs/reference/figures/plot_gam2.png new file mode 100644 index 0000000..59dd1e1 Binary files /dev/null and b/docs/reference/figures/plot_gam2.png differ diff --git a/docs/reference/figures/plot_gam3.png b/docs/reference/figures/plot_gam3.png new file mode 100644 index 0000000..213d1ba Binary files /dev/null and b/docs/reference/figures/plot_gam3.png differ diff --git a/docs/reference/gam_to_df.html b/docs/reference/gam_to_df.html new file mode 100644 index 0000000..362d835 --- /dev/null +++ b/docs/reference/gam_to_df.html @@ -0,0 +1,184 @@ + + + + + + + + +Converts a fitted GAM model into a tidy data frame — gam_to_df • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + + +

    This function converts a fitted GAM model into a tidy data frame

    + + +
    gam_to_df(model = NULL, pred = NULL)
    + +

    Arguments

    + + + + + + + + + + +
    model

    A fitted GAM(M).

    pred

    Character. Predictor name for which to calculate +the odds ratio.

    + +

    Details

    + +

    To be able to plot the smoothing function of a GAM using ggplot2, +some preprocessing is needed coming from the raw fitted GAM model output.

    +

    Used in plot_gam.

    + +

    See also

    + +

    plot_gam

    + + +

    Examples

    +
    # load data (Source: ?mgcv::gam) +library(mgcv)
    #> Loading required package: nlme
    #> This is mgcv 1.8-22. For overview type 'help("mgcv-package")'.
    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))) +fit_gam <- gam(y ~ s(x0) + s(I(x1^2)) + s(x2) + + offset(x3) + x4, data = dat) # fit model + +tmp <- gam_to_df(fit_gam, "x2")
    +
    + +
    + +
    + + +
    +

    Site built with pkgdown.

    +
    + +
    +
    + + + diff --git a/docs/reference/index.html b/docs/reference/index.html new file mode 100644 index 0000000..87d144b --- /dev/null +++ b/docs/reference/index.html @@ -0,0 +1,178 @@ + + + + + + + + +Function reference • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +

    All functions

    +

    +
    +

    insert_or

    +

    Insert odds ratios of GAM(M)s into smoothing function

    +

    or_gam

    +

    Calculate odds ratios of Generalized Additive (Mixed) Models

    +

    or_glm

    +

    Calculate odds ratios of Generalized Linear (Mixed) Models

    +

    plot_gam

    +

    Plot smoothing functions of GAM(M) models

    +
    +
    + + +
    + +
    + + +
    +

    Site built with pkgdown.

    +
    + +
    +
    + + + diff --git a/docs/reference/insert_or-1.png b/docs/reference/insert_or-1.png new file mode 100644 index 0000000..c197c70 Binary files /dev/null and b/docs/reference/insert_or-1.png differ diff --git a/docs/reference/insert_or.html b/docs/reference/insert_or.html new file mode 100644 index 0000000..fa10eb9 --- /dev/null +++ b/docs/reference/insert_or.html @@ -0,0 +1,266 @@ + + + + + + + + +Insert odds ratios of GAM(M)s into smoothing function — insert_or • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + + +

    This function inserts calculated odds ratios of GAM(M)s into +a plot of a GAM(M) smoothing function.

    + + +
    insert_or(plot_object = NULL, or_object = NULL, line_col = "red",
    +  line_size = 1.2, line_type = "solid", line_alpha = 1, text_alpha = 1,
    +  text_size = 4, text_col = "black", rect_alpha = 0.5, rect_col = NULL,
    +  rect = FALSE, arrow = TRUE, values = TRUE, values_yloc = 0,
    +  values_xloc = NULL, or_yloc = 0, arrow_length = NULL,
    +  arrow_yloc = NULL, arrow_col = NULL, arrow_xloc_r = NULL,
    +  arrow_xloc_l = NULL)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    plot_object

    A ggplot object from plot_gam.

    or_object

    A returned data.frame from or_gam.

    line_col, line_alpha, line_type, line_size

    Aesthetics of vertical lines.

    text_col, text_alpha, text_size

    Aesthetics of inserted values.

    rect_col, rect_alpha

    Aesthetics of shaded rectangle.

    rect

    Logical. Whether to print a shaded rectangle between the +vertical lines.

    arrow

    Logical. Whether to print arrows above the inserted values. +Default to TRUE.

    values

    Logical. Whether to print predictor value information nearby +the inserted vertical lines. Default to TRUE.

    values_xloc

    Numeric. X-axis location/shift of values relative to +their vertical line. +Default to 2% of x-axis range.

    or_yloc, values_yloc

    Numeric. Specifies y-location of inserted +odds ratio / values. +Relative to plotted y-axis range. A positive/negative value will place the +the text higher/lower.

    arrow_xloc_r, arrow_xloc_l, arrow_yloc, arrow_length, arrow_col

    Numeric. +Axis placement options of inserted arrows. +Relative to respective axis ranges.

    + +

    Value

    + +

    Returns a ggplot plotting object

    + +

    Details

    + +

    The idea behind this function is to add calculated odds ratio of +fitted GAM models (or_gam) into a plot +showing the smooth function (plot_gam) of the chosen +predictor for which the odds ratio was calculated for. Multiple insertions +can be made by iteratively calling the function (see examples).

    +

    Right now the function does only accept results of +or_gam with slice = FALSE. +If you want to insert multiple odds ratio you have to do it iteratively.

    + +

    See also

    + +

    plot_gam + or_gam

    + + +

    Examples

    +
    # load data (Source: ?mgcv::gam) and fit model +library(mgcv) +fit_gam <- gam(y ~ s(x0) + s(I(x1^2)) + s(x2) + + offset(x3) + x4, data = data_gam) # fit model + +# create input objects (plot + odds ratios) +library(oddsratio) +plot_object <- plot_gam(fit_gam, pred = "x2", title = "Predictor 'x2'") +or_object1 <- or_gam(data = data_gam, model = fit_gam, + pred = "x2", values = c(0.099, 0.198)) + +# insert first odds ratios to plot +plot_object <- insert_or(plot_object, or_object1, or_yloc = 3, + values_xloc = 0.04, line_size = 0.5, + line_type = "dotdash", text_size = 6, + values_yloc = 0.5, arrow_col = "red") + +# calculate second odds ratio +or_object2 <- or_gam(data = data_gam, model = fit_gam, pred = "x2", + values = c(0.4, 0.6)) + +# add or_object2 into plot +insert_or(plot_object, or_object2, or_yloc = 2.1, values_yloc = 2, + line_col = "green4", text_col = "black", + rect_col = "green4", rect_alpha = 0.2, + line_alpha = 1, line_type = "dashed", + arrow_xloc_r = 0.01, arrow_xloc_l = -0.01, + arrow_length = 0.01, rect = TRUE)
    +
    + +
    + +
    + + +
    +

    Site built with pkgdown.

    +
    + +
    +
    + + + diff --git a/docs/reference/no_plot-1.png b/docs/reference/no_plot-1.png new file mode 100644 index 0000000..67eb881 Binary files /dev/null and b/docs/reference/no_plot-1.png differ diff --git a/docs/reference/no_plot.html b/docs/reference/no_plot.html new file mode 100644 index 0000000..67d1d29 --- /dev/null +++ b/docs/reference/no_plot.html @@ -0,0 +1,180 @@ + + + + + + + + +Suppress plotting output of plot function — no_plot • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + + +

    This function suppresses plotting output of plot function

    + + +
    no_plot(model = NULL)
    + +

    Arguments

    + + + + + + +
    model

    A fitted GAM(M).

    + +

    Details

    + +

    To prevent unwanted plot printing of plot in a function call +in which the only desire is to work with the returned information of +plot. Used in plot_gam.

    + +

    See also

    + +

    plot_gam

    + + +

    Examples

    +
    # load data (Source: ?mgcv::gam) +library(mgcv) +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))) +fit_gam <- gam(y ~ s(x0) + s(I(x1^2)) + s(x2) + + offset(x3) + x4, data = dat) # fit model + +tmp <- plot(fit_gam, pages = 1) # plot output
    tmp <- no_plot(fit_gam) # no plot output
    +
    + +
    + +
    + + +
    +

    Site built with pkgdown.

    +
    + +
    +
    + + + diff --git a/docs/reference/or_gam.html b/docs/reference/or_gam.html new file mode 100644 index 0000000..27ddf46 --- /dev/null +++ b/docs/reference/or_gam.html @@ -0,0 +1,250 @@ + + + + + + + + +Calculate odds ratios of Generalized Additive (Mixed) Models — or_gam • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + + +

    This function calculates odds ratio(s) for specific increment +steps of a GAM(M)s.

    +

    Odds ratios can also be calculated for continuous percentage +increment steps across the whole predictor distribution using slice = TRUE.

    + + +
    or_gam(data = NULL, model = NULL, pred = NULL, values = NULL,
    +  percentage = NULL, slice = FALSE, CI = NULL)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    data

    The data used for model fitting.

    model

    A fitted GAM(M).

    pred

    Character. Predictor name for which to calculate +the odds ratio.

    values

    Numeric vector of length two. +Predictor values to estimate odds ratio from. Function is written to use the +first provided value as the "lower" one, i.e. calculating the odds ratio +'from value1 to value2'. Only used if slice = FALSE.

    percentage

    Numeric. Percentage number to split the +predictor distribution into. +A value of 10 would split the predictor distribution by 10% intervals. +Only needed if slice = TRUE.

    slice

    Logical. Default = FALSE. Whether to calculate +odds ratios for fixed increment steps over the whole predictor distribution. +See percentage for setting the increment values.

    CI

    Numeric. Currently fixed to 95% confidence interval level +(2.5% - 97.5%). +It should not be changed in a function call!

    + +

    Value

    + +

    A data frame with (up to) eight columns. perc1 and perc2 +are only returned if slice = TRUE:

    +
    predictor

    Predictor name

    +
    value1

    First value of odds ratio calculation

    +
    value2

    Second value of odds ratio calculation

    +
    perc1

    Percentage value of value1

    +
    perc2

    Percentage value of value2

    +
    oddsratio

    Calculated odds ratio(s)

    +
    CI_low

    Lower (2.5%) confident interval of odds ratio

    +
    CI_high

    Higher (97.5%) confident interval of odds ratio

    + + +

    Details

    + +

    Currently supported functions: mgcv::gam, +mgcv::gamm, gam::gam.

    +

    For mgcv::gamm, the model input of +or_gam needs to be the gam output (e.g. fit_gam$gam).

    + +

    See also

    + +

    or_glm + plot_gam + insert_or

    + + +

    Examples

    +
    # load data (Source: ?mgcv::gam) and fit model +library(mgcv) +fit_gam <- gam(y ~ s(x0) + s(I(x1^2)) + s(x2) + + offset(x3) + x4, data = data_gam) # fit model + +# Calculate OR for specific increment step of continuous variable +or_gam(data = data_gam, model = fit_gam, pred = "x2", + values = c(0.099, 0.198))
    #> predictor value1 value2 oddsratio CI_low (2.5%) CI_high (97.5%) +#> 1 x2 0.099 0.198 23.32353 23.30424 23.34283
    +## Calculate OR for change of indicator variable +or_gam(data = data_gam, model = fit_gam, pred = "x4", + values = c("B", "D"))
    #> predictor value1 value2 oddsratio CI_low (2.5%) CI_high (97.5%) +#> 1 x4 B D 0.4744264 0.4976375 0.452298
    +## Calculate ORs for percentage increments of predictor distribution +## (here: 20%) +or_gam(data = data_gam, model = fit_gam, pred = "x2", + percentage = 20, slice = TRUE)
    #> predictor value1 value2 perc1 perc2 oddsratio CI_low (2.5%) CI_high (97.5%) +#> 1 x2 0.001 0.200 0 20 2510.77 1091.68 5774.53 +#> 2 x2 0.200 0.400 20 40 0.03 0.03 0.03 +#> 3 x2 0.400 0.599 40 60 0.58 0.56 0.60 +#> 4 x2 0.599 0.799 60 80 0.06 0.06 0.06 +#> 5 x2 0.799 0.998 80 100 0.41 0.75 0.22
    +
    +
    + +
    + +
    + + +
    +

    Site built with pkgdown.

    +
    + +
    +
    + + + diff --git a/docs/reference/or_glm.html b/docs/reference/or_glm.html new file mode 100644 index 0000000..b9c0102 --- /dev/null +++ b/docs/reference/or_glm.html @@ -0,0 +1,234 @@ + + + + + + + + +Calculate odds ratios of Generalized Linear (Mixed) Models — or_glm • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + + +

    This function calculates odds ratio(s) for specific +increment steps of GLMs.

    + + +
    or_glm(data, model, incr, CI = 0.95)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + +
    data

    The data used for model fitting.

    model

    A fitted GLM(M).

    incr

    List. Increment values of each predictor.

    CI

    numeric. Which confident interval to calculate. +Must be between 0 and 1. Default to 0.95

    + +

    Value

    + +

    A data frame with five columns:

    +
    predictor

    Predictor name(s)

    +
    oddsratio

    Calculated odds ratio(s)

    +
    CI_low

    Lower confident interval of odds ratio

    +
    CI_high

    Higher confident interval of odds ratio

    +
    increment

    Increment of the predictor(s)

    + + +

    Details

    + +

    CI_low and CI_high are only calculated for GLM models because +glmmPQL does not return confident intervals due to its penalizing +behaviour.

    +

    Currently supported functions: glm, +glmmPQL

    + +

    See also

    + +

    or_gam

    + + +

    Examples

    +
    ## Example with glm() +# load data (source: http://www.ats.ucla.edu/stat/r/dae/logit.htm) and +# fit model +fit_glm <- glm(admit ~ gre + gpa + rank, data = data_glm, + family = "binomial") # fit model + +# Calculate OR for specific increment step of continuous variable +or_glm(data = data_glm, model = fit_glm, incr = list(gre = 380, gpa = 5))
    #> predictor oddsratio CI_low (2.5 %) CI_high (97.5 %) increment +#> 1 gre 2.364 1.054 5.396 380 +#> 2 gpa 55.712 2.229 1511.282 5 +#> 3 rank2 0.509 0.272 0.945 Indicator variable +#> 4 rank3 0.262 0.132 0.512 Indicator variable +#> 5 rank4 0.212 0.091 0.471 Indicator variable
    +# Calculate OR and change the confidence interval level +or_glm(data = data_glm, model = fit_glm, + incr = list(gre = 380, gpa = 5), CI = .70)
    #> predictor oddsratio CI_low (15 %) CI_high (85 %) increment +#> 1 gre 2.364 1.540 3.647 380 +#> 2 gpa 55.712 10.084 314.933 5 +#> 3 rank2 0.509 0.366 0.706 Indicator variable +#> 4 rank3 0.262 0.183 0.374 Indicator variable +#> 5 rank4 0.212 0.136 0.325 Indicator variable
    +## Example with MASS:glmmPQL() +# load data +library(MASS) +data(bacteria) +fit_glmmPQL <- glmmPQL(y ~ trt + week, random = ~1 | ID, + family = binomial, data = bacteria, + verbose = FALSE) + +# Apply function +or_glm(data = bacteria, model = fit_glmmPQL, incr = list(week = 5))
    #> Warning: No confident interval calculation possible +#> for 'glmmPQL' models +#>
    #> predictor oddsratio CI_low CI_high increment +#> 1 trtdrug 0.296 NA NA Indicator variable +#> 2 trtdrug+ 0.454 NA NA Indicator variable +#> 3 week 0.485 NA NA 5
    +
    +
    + +
    + +
    + + +
    +

    Site built with pkgdown.

    +
    + +
    +
    + + + diff --git a/docs/reference/plot_gam-1.png b/docs/reference/plot_gam-1.png new file mode 100644 index 0000000..f511913 Binary files /dev/null and b/docs/reference/plot_gam-1.png differ diff --git a/docs/reference/plot_gam.html b/docs/reference/plot_gam.html new file mode 100644 index 0000000..a661de5 --- /dev/null +++ b/docs/reference/plot_gam.html @@ -0,0 +1,229 @@ + + + + + + + + +Plot smoothing functions of GAM(M) models — plot_gam • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + +
    +
    + + + +

    This function plots the smoothing function of selected GAM(M) models +using the ggplot2 plotting system.

    + + +
    plot_gam(model = NULL, pred = NULL, col_line = "blue",
    +  ci_line_col = "black", ci_line_type = "dashed", ci_fill = "grey",
    +  ci_alpha = 0.4, ci_line_size = 0.8, sm_fun_size = 1.1, title = NULL,
    +  xlab = NULL, ylab = NULL, limits_y = NULL, breaks_y = NULL)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    model

    A fitted model of class gam.

    pred

    The predictor of the fitted model to plot the smooth function of.

    col_line

    Character. Sets color for smoothing function. Default to +"blue".

    ci_line_col

    Character. Sets color for confident interval line of +smoothing function. Default to "black".

    ci_line_type

    Character. Sets linetype of confident interval line +of smoothing function. Default to "dashed".

    ci_fill

    Character. Fill color of area between smoothing function and +its confident interval lines.

    ci_alpha

    Numeric (range: 0-1). Opacity value of confidence interval shading.

    ci_line_size, sm_fun_size

    Line sizes.

    title

    Character. Plot title.

    xlab

    Character. X-axis title.

    ylab

    Character. Y-axis title.

    limits_y

    Numeric of length two. Sets y-axis limits.

    breaks_y

    Numeric of length three. Sets y-axis breaks. +See seq. +Values need to be given in a seq call, e.g. seq(-6, 6, 2).

    + +

    See also

    + +

    plot_gam + or_gam + insert_or

    + + +

    Examples

    +
    # load data (Source: ?mgcv::gam) and fit model +library(mgcv) +fit_gam <- mgcv::gam(y ~ s(x0) + s(I(x1^2)) + s(x2) + offset(x3) + x4, + data = data_gam) + +library(oddsratio) +plot_gam(fit_gam, pred = "x2", title = "Predictor 'x2'")
    +
    +
    + +
    + +
    + + +
    +

    Site built with pkgdown.

    +
    + +
    +
    + + + diff --git a/docs/search.html b/docs/search.html new file mode 100644 index 0000000..d0eb383 --- /dev/null +++ b/docs/search.html @@ -0,0 +1,133 @@ + + + + + + + + +Search results • oddsratio + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/search.js b/docs/search.js new file mode 100644 index 0000000..60f8483 --- /dev/null +++ b/docs/search.js @@ -0,0 +1,35 @@ +$.getJSON("site-index.json", function(json) { + + window.store = []; + window.index = lunr(function() { + this.ref("href"); + this.field("type"); + this.field("title"); + this.field("words", { boost: 10 }); + + json.forEach(function (doc) { + this.add(doc); + window.store[doc.href] = {'title': doc.title, 'type': doc.type} ; + }, this); + }); + }); + + +$(document).ready(function() { + + query = window.location.search.split("=")[1]; + + result = index.search(query); + + resultdiv = $('ul.search-results'); + + resultdiv.empty(); + resultdiv.prepend('

    Found ' + result.length + ' result(s)

    '); + + for (var item in result) { + ref = result[item].ref; + searchitem = '
  • ' + store[ref].title + ' (' + store[ref].type + ')
  • '; + resultdiv.append(searchitem); + } + +}); diff --git a/docs/site-index.json b/docs/site-index.json new file mode 100644 index 0000000..ff1b444 --- /dev/null +++ b/docs/site-index.json @@ -0,0 +1 @@ +[{"title":"README","type":"Home page","href":"index.html","words":["Odds","Ratio","Calculation","for","GAM","M","s","GLM","M","s","oddsratio","oddsratio","Reference","Articles","Function","tutorial","News","General","Resource","CRAN","Travis","CI","Appveyor","Platforms","Multiple","Linux","macOS","Windows","R","CMD","check","CRAN","version","Build","status","Build","status","Test","coverage","Coverage","Status","CRAN","CRAN","Status","Badge","Downloads","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","Install","from","CRAN","Get","the","development","version","from","Github","Examples","GLM","Odds","ratio","calculation","of","predictors","of","a","fitted","model","with","increment","steps","of","and","respectively","For","factor","variables","here","with","levels","automatically","all","odds","ratios","corresponding","to","the","base","level","here","are","returned","including","their","respective","confident","intervals","The","default","level","is","However","other","levels","can","be","specified","with","the","param","Data","source","http","www","ats","ucla","edu","stat","r","dae","logit","htm","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","level","for","GAMs","Data","source","Here","the","usage","of","is","shown","by","calculating","odds","ratios","of","pred","for","a","steps","across","the","whole","value","range","of","the","predictor","If","you","want","to","compute","a","single","odds","ratio","for","specific","values","simply","set","param","Plotting","of","GAM","smooths","is","also","supported","Insert","the","calculated","odds","ratios","into","the","smoothing","function","Insert","multiple","odds","ratios","into","one","smooth","Links","Download","from","CRAN","at","https","cran","r","project","org","package","oddsratio","Browse","source","code","at","https","github","com","pat","s","oddsratio","Report","a","bug","at","https","github","com","pat","s","oddsratio","issues","License","MIT","file","LICENSE","Developers","Patrick","Schratz","Author","maintainer","Dev","status","Project","Status","Active","The","project","has","reached","a","stable","usable","state","and","is","being","actively","developed","DOI","Developed","by","Patrick","Schratz","Site","built","with","pkgdown"]},{"title":"data_gam","type":"Rd","href":"reference/data_gam.html","words":["data","gam"]},{"title":"data_glm","type":"Rd","href":"reference/data_glm.html","words":["data","glm"]},{"title":"gam_to_df","type":"Rd","href":"reference/gam_to_df.html","words":["This","function","converts","a","fitted","GAM","model","into","a","tidy","data","frame"]},{"title":"insert_or","type":"Rd","href":"reference/insert_or.html","words":["This","function","inserts","calculated","odds","ratios","of","GAM","M","s","into","a","plot","of","a","GAM","M","smoothing","function"]},{"title":"no_plot","type":"Rd","href":"reference/no_plot.html","words":["This","function","suppresses","plotting","output","of","plot","function"]},{"title":"or_gam","type":"Rd","href":"reference/or_gam.html","words":["This","function","calculates","odds","ratio","s","for","specific","increment","steps","of","a","GAM","M","s","Odds","ratios","can","also","be","calculated","for","continuous","percentage","increment","steps","across","the","whole","predictor","distribution","using"]},{"title":"or_glm","type":"Rd","href":"reference/or_glm.html","words":["This","function","calculates","odds","ratio","s","for","specific","increment","steps","of","GLMs"]},{"title":"plot_gam","type":"Rd","href":"reference/plot_gam.html","words":["This","function","plots","the","smoothing","function","of","selected","GAM","M","models","using","the","plotting","system"]},{"title":"function_tutorial","type":"Vignette","href":"articles/function_tutorial.html","words":["Function","tutorial","oddsratio","oddsratio","Reference","Articles","Function","tutorial","News","Function","tutorial","Patrick","Schratz","Load","example","data","fit","model","Data","source","GAM","example","Calculate","OR","for","specific","increment","step","of","continuous","variable","To","calculate","specific","increment","steps","of","we","take","predictor","randomly","chosen","and","specify","for","which","values","we","want","to","calculate","the","odds","ratio","We","can","see","that","the","odds","of","response","happening","are","times","higher","when","predictor","increases","from","to","while","holding","all","other","predictors","constant","Usually","this","calculation","is","done","by","setting","all","predictors","to","their","mean","value","predict","the","response","change","the","desired","predictor","to","a","new","value","and","predict","the","response","again","These","actions","results","in","two","log","odds","values","respectively","which","are","transformed","into","odds","by","exponentiating","them","Finally","the","odds","ratio","can","be","calculated","from","these","two","odds","values","Calculate","OR","for","level","change","of","indicator","variable","If","the","predictor","is","an","indicator","variable","i","e","consists","of","fixed","levels","you","can","use","the","function","in","the","same","way","by","just","putting","in","the","respective","levels","you","are","interested","in","Here","the","change","in","odds","of","happening","if","predictor","is","changing","from","level","to","is","rather","small","In","detail","an","increase","in","odds","of","is","reported","Calculate","ORs","for","percentage","increments","of","predictor","distribution","To","get","an","impression","of","odds","ratio","behaviour","throughout","the","complete","range","of","the","smoothing","function","of","the","fitted","GAM","model","you","can","calculate","odds","ratios","based","on","percentage","breaks","of","the","predictors","distribution","Here","we","slice","predictor","into","parts","by","taking","the","predictor","values","of","every","increment","step","We","can","see","that","there","is","a","high","odds","ratio","reported","when","increasing","predictor","from","to","while","all","further","predictor","increases","decrease","the","odds","of","response","happening","substantially","Plot","GAM","M","smoothing","functions","Right","now","the","only","quick","possibility","to","plot","the","smoothing","functions","of","a","GAM","M","was","to","use","the","base","function","The","fiddly","work","to","do","the","same","using","the","plotting","system","is","done","by","You","can","further","customize","the","look","using","other","colors","or","linetypes","Add","odds","ratio","information","into","smoothing","function","plot","So","now","we","have","the","odds","ratios","and","we","have","a","plot","of","the","smoothing","function","Why","not","combine","both","We","can","do","so","using","Its","main","arguments","are","i","a","plotting","object","containing","the","smooth","function","and","a","data","frame","returned","from","containing","information","about","the","predictor","and","the","respective","values","we","want","to","insert","The","odds","ratio","information","is","always","centered","between","the","two","vertical","lines","Hence","it","only","looks","nice","if","the","gap","between","the","two","chosen","values","here","and","is","large","enough","If","the","smoothing","line","crosses","your","inserted","text","you","can","just","correct","it","adjusting","This","param","sets","the","y","location","of","the","inserted","odds","ratio","information","Depending","on","the","digits","of","your","chosen","values","here","you","might","also","need","to","adjust","the","x","axis","location","of","the","two","values","so","that","they","do","not","interfer","with","the","vertical","line","Let","s","do","all","this","by","inserting","another","odds","ratio","into","this","plot","This","time","we","simply","take","the","already","produced","plot","as","an","input","to","and","use","a","new","odds","ratio","object","Using","you","can","additionally","highlight","certain","odds","ratio","intervals","Aesthetics","like","opacity","or","color","are","fully","customizable","GLM","example","Fit","model","Data","source","http","www","ats","ucla","edu","stat","r","dae","logit","htm","Calculate","odds","ratio","for","continuous","predictors","For","GLMs","the","odds","ratio","calculation","is","simpler","because","odds","ratio","changes","correspond","to","fixed","predictor","increases","throughout","the","complete","value","range","of","each","predictor","Hence","function","takes","the","increment","steps","of","each","predictor","directly","as","an","input","in","its","parameter","To","avoid","false","predictor","value","assignments","the","combinations","need","to","be","given","in","a","list","Odds","ratios","of","indicator","variables","are","computed","automatically","and","do","always","refer","to","the","base","factor","level","Indicator","predictor","has","four","levels","Subsequently","we","will","get","three","odds","ratio","outputs","referring","to","the","base","factor","level","here","rank","The","output","is","interpreted","as","follows","Having","instead","of","while","holding","all","other","values","constant","results","in","a","decrease","in","odds","of","You","can","also","set","other","confident","intervals","for","GLM","M","models","The","resulting","data","frame","will","automatically","adjust","its","column","names","to","the","specified","level","Contents","Load","example","data","fit","model","GAM","example","GLM","example","Developed","by","Patrick","Schratz","Site","built","with","pkgdown"]}]