tab_univariate: Produce odds ratios, risk ratios or incidence rate ratios

View source: R/tab_univariate.R

tab_univariateR Documentation

Produce odds ratios, risk ratios or incidence rate ratios

Description

Produce odds ratios, risk ratios or incidence rate ratios

Usage

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

data_frame_from_2x2()

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

# 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")

R4EPI/tuni documentation built on March 20, 2023, 4:37 p.m.