View source: R/tab_univariate.R
tab_univariate | R Documentation |
Produce odds ratios, risk ratios or incidence rate ratios
tab_univariate(
x,
outcome,
...,
perstime = NULL,
strata = NULL,
measure = "OR",
extend_output = TRUE,
digits = 3,
mergeCI = FALSE,
woolf_test = FALSE
)
x |
A data frame |
outcome |
Name of A TRUE/FALSE variable as your outcome of interest (e.g. illness) |
... |
Names of TRUE/FALSE variables as exposures of interest (e.g. risk factors) |
perstime |
A numeric variable containing the observation time for each individual |
strata |
Name of a TRUE/FALSE variable to be used for stratifying
results. Note that this results in a different output table - giving you a
table of crude measure, measures for each strata and the mantel-haeszel
adjusted measure for each exposure variable listed in |
measure |
Specify what you would like to calculated, options are "OR", "RR" or "IRR" default is "OR" |
extend_output |
TRUE/FALSE to specify whether would like all columns in the outputs (default is TRUE) Non-extended output drops group odds or risk calculations as well as p-values |
digits |
Specify number of decimal places (default is 3) |
mergeCI |
Whether or not to put the confidence intervals in one column (default is FALSE) |
woolf_test |
Only if strata specified and measure is "RR" or "OR". TRUE/FALSE to specify whether to include woolf test for homogeneity p-value. Tests whether there is a significant difference in the estimates between strata. |
Inspired by Daniel Gardiner, see github repo Real data set for example from http://sphweb.bumc.bu.edu/otlt/mph-modules/bs/bs704-ep713_confounding-em/BS704-EP713_Confounding-EM7.html
data_frame_from_2x2()
# set up data set, first as 2x2x2 table
arr <- array(
data = c(10, 35, 90, 465, 36, 25, 164, 175),
dim = c(2 , 2 , 2),
dimnames = list(
risk = c(TRUE , FALSE),
outcome = c(TRUE , FALSE),
old = c(FALSE, TRUE)
)
)
arr
# Create data frame from 2x2x2 table
library("tidyr")
a <- arr %>%
as.data.frame.table() %>%
tidyr::uncount(weights = Freq) %>%
dplyr::mutate_all(as.logical) %>%
tibble::as_tibble()
# get the results from tab_univariate function
tab_univariate(a, outcome, risk, strata = old, digits = 6, measure = "OR")
tab_univariate(a, outcome, risk, strata = old, digits = 6, measure = "RR")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.