odds_plot: odds_plot - a function to create Odds Plots

Description Usage Arguments Value Examples

View source: R/OddsPlotR.R.R

Description

This has been created to generate odds plots on the back of results from a generalised linear model.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
odds_plot(
  x,
  x_label = "Variables",
  y_label = "Odds Ratio",
  title = NULL,
  subtitle = NULL,
  point_col = "blue",
  error_bar_colour = "black",
  point_size = 5,
  error_bar_width = 0.3,
  h_line_color = "black"
)

Arguments

x

The trained caret GLM logistic regression model

x_label

The label name for the x_label

y_label

The label name for the y_label

title

Title for the Odds Plot

subtitle

Subtitle for the Odds Plot

point_col

Defaults to blues, but R colour codes can be passed

error_bar_colour

the colour of the error bar

point_size

the point size of the plot

error_bar_width

the width of the displayed error bar

h_line_color

the colour of the horizontal line

Value

A list of the odds returned from logistic regression and a plot showing the odds

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#We will use the cancer dataset to build a GLM model to predict cancer status
#this will detail whether the patient has a benign or malignant
library(mlbench)
library(caret)
library(tibble)
library(ggplot2)
library(OddsPlotty)
library(e1071)
library(ggthemes)

#Bring in the data
data("BreastCancer", package = "mlbench")
breast <- BreastCancer[complete.cases(BreastCancer), ]
breast <- breast[, -1]
head(breast, 10)
breast$Class <- factor(breast$Class)
for(i in 1:9) {
breast[, i] <- as.numeric(as.character(breast[, i]))
}

#Train GLM model
glm_model <- train(Class ~ ., data = breast, method = "glm", family = "binomial")

#Visualise the data with OddsPlotty
plotty <- OddsPlotty::odds_plot(glm_model$finalModel,title = "Odds Plot")
plotty$odds_plot

#Extract underlying odds ratios
plotty$odds_data

OddsPlotty documentation built on Nov. 13, 2021, 5:06 p.m.