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

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")
#>            variable   est_type exp_cases unexp_cases cases_odds exp_controls
#> crude          risk      crude        46          60  0.7666667          254
#> old: TRUE      risk  old: TRUE        36          25  1.4400000          164
#> old: FALSE     risk old: FALSE        10          35  0.2857143           90
#> MH             risk         MH        NA          NA         NA           NA
#>            unexp_controls controls_odds    ratio     lower    upper     p.value
#> crude                 640     0.3968750 1.931759 1.2811369 2.912796 0.001456825
#> old: TRUE             175     0.9371429 1.536585 0.8839320 2.671127 0.126045958
#> old: FALSE            465     0.1935484 1.476190 0.7056245 3.088241 0.298455837
#> MH                     NA            NA 1.516129 0.9739216 2.360198          NA
tab_univariate(a, outcome, risk, strata = old, digits = 6, measure = "RR")
#>            variable   est_type exp_cases exp_total exp_risk unexp_cases
#> crude          risk      crude        46       300 15.33333          60
#> old: TRUE      risk  old: TRUE        36       200 18.00000          25
#> old: FALSE     risk old: FALSE        10       100 10.00000          35
#> MH             risk         MH        NA        NA       NA          NA
#>            unexp_total unexp_risk    ratio     lower    upper     p.value
#> crude              700   8.571429 1.788889 1.2486872 2.562790 0.001456825
#> old: TRUE          200  12.500000 1.440000 0.8989988 2.306566 0.126045958
#> old: FALSE         500   7.000000 1.428571 0.7316106 2.789484 0.298455837
#> MH                  NA         NA 1.436364 0.9769870 2.111738          NA