View source: R/interpret_or2.R
interpret_or2 | R Documentation |
I always get tripped up interpreting odds ratios. Especially when trying to make sense of results from logistic regression. This function seems to help me out.
Unlike lamsic::interpret_or
, this function take the cells (a
, b
, c
,
and d
) of a 2x2 contingency table as inputs directly rather than columns of
a data frame.
The function returns a list with a 2x2 table, a sample interpretation, and the odds ratio with Wald confidence interval. This can then be compared to logisitc regression results and make sure that thing are making sense.
Much of this is owed to the ExploringDataBlog
interpret_or2(
a,
b,
c,
d,
dim_names = list(exposure_status = c("Exposed", "Unexposed"), outcome_status =
c("Postive", "Negative")),
alpha = 0.05
)
a |
Count of the upper left quadrant of 2x2 contingency table |
b |
Count of upper right |
c |
Count of lower left |
d |
Count of lower right |
dim_names |
A list; labels or the rows and columns of the 2x2
contingency table. Default is |
alpha |
Default = 0.05. The significance level for the two-sided Wald confidence interval. |
A list with the following:
2x2 contingency table
Sample interpretation of the odds ratio of the outcome and the exposure levels
Odds ratio and Wald confidence interval
Results of Fisher's test
Results of Chi-square test
https://exploringdatablog.blogspot.com/2011/05/computing-odds-ratios-in-r.html
https://stats.idre.ucla.edu/other/mult-pkg/faq/general/faq-how-do-i-interpret-odds-ratios-in-logistic-regression/
library(dplyr)
library(broom)
library(janitor)
# Example 1: Interpreting a 2x2 table
interpret_or2(a = 40, b = 148, c = 87, d = 125,
dim_names = list(rank = c("2", "1"),
admit = c("Yes", "No")))
# Example 2: Using a contingency table from data
dis_df <- tibble::tibble(
Outcome = sample(c("Diseased", "Non-diseased"), 100, TRUE, c(0.25, 0.75)),
Exposure = sample(c("Exposed", "Unexposed"), 100, TRUE, c(0.40, 0.60))
)
janitor::tabyl(dis_df, Exposure, Outcome)
interpret_or2(a = 11, b = 28, c = 15, d = 46,
dim_names = list(Exposure = c("Exposed", "Unexposed"),
Outcome = c("Diseased", "Non-diseased")))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.