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
)

Arguments

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.

References

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

See also

Examples

# 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
#> , , old = FALSE #> #> outcome #> risk TRUE FALSE #> TRUE 10 90 #> FALSE 35 465 #> #> , , old = TRUE #> #> outcome #> risk TRUE FALSE #> TRUE 36 164 #> FALSE 25 175 #>
# Create data frame from 2x2x2 table library("tidyr")
#> #> Attaching package: ‘tidyr’
#> The following objects are masked from ‘package:Matrix’: #> #> expand, pack, unpack
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")
#> # A tibble: 4 x 12 #> variable est_type exp_cases unexp_cases cases_odds exp_controls unexp_controls #> <chr> <chr> <int> <int> <dbl> <int> <int> #> 1 risk crude 46 60 0.767 254 640 #> 2 risk old: TR… 36 25 1.44 164 175 #> 3 risk old: FA… 10 35 0.286 90 465 #> 4 risk MH NA NA NA NA NA #> # … with 5 more variables: controls_odds <dbl>, ratio <dbl>, lower <dbl>, #> # upper <dbl>, p.value <dbl>
tab_univariate(a, outcome, risk, strata = old, digits = 6, measure = "RR")
#> # A tibble: 4 x 12 #> variable est_type exp_cases exp_total exp_risk unexp_cases unexp_total #> <chr> <chr> <int> <int> <dbl> <int> <int> #> 1 risk crude 46 300 15.3 60 700 #> 2 risk old: TR… 36 200 18 25 200 #> 3 risk old: FA… 10 100 10 35 500 #> 4 risk MH NA NA NA NA NA #> # … with 5 more variables: unexp_risk <dbl>, ratio <dbl>, lower <dbl>, #> # upper <dbl>, p.value <dbl>