Chapter 3 epitools

3.1 epitable

  • Create r x c contigency table for r exposure levels and c outcome levels
epitable(..., ncol =2, byrow = TRUE,
         rev = c("neither", "rows", "columns", "both"))
  • ... :

      1. four or more integers that be converted into r x 2 table (the number of integers must be even), e.g. epitable(88, 20, 555, 347)
      1. two categorical vectors (1st vector is exposure with r levels, 2nd vector is outcome with 2 levels), e.g. epitable("Exposure"=exposure, "Disease"=outcome), or epitable(dat$expo, dat$out)
      1. r x 2 contingency table, e.g. epitable(matrix(1:6, 3, 2))
      1. single vector that be converted into r x 2 table (the number of integers must be even), e.g. epitable(c(88, 20, 555, 347))
  • ncol: Default ncol=2, number of columns when a table is constructed from a vector or sequence of numbers

  • byrow: Default byrow=TRUE and single vector or collection of numbers is read in row-wise.

    • Set to FALSE to read in column-wise.
    • e.g. epitable(88, 20, 555, 347), by default 88, 20 would be regarded as the first row (under the same exposure status, Diseased and No disease respectively), and 555, 347 the second under the other exposure status.
    • e.g. epitable(88, 20, 555, 347, byrow = FALSE), then 88, 20 would be regarded as the first column (under the same disease status, Exposed and Unexposed respectively), and 555, 347 the second column under the other disease status.
  • rev: Default rev="neither" means no order reversal in the process, can be“rows,” “colums” or “both” to reverse the orders.

    • Usually the table we get from (2) two categorical vectors would be like:
dat <- read.dta("_data/diet.dta")
epitable(dat$diet, dat$mort)
##          Outcome
## Predictor   0   1
##         0 186 136
##         1 119  59
  • In the output table, the outcomes and predictors (exposure) are listed by 0 and then 1; But in the 2 by 2 tables we usually used for further calculation, the top left cell should be Exposed and Disease (Predictor = 1 & Outcome = 1)
Disease + Disease -
Expose +
Expose -
- So `rev="both"` is added: 
epitable(dat$diet, dat$mort, rev="both")
##          Outcome
## Predictor   1   0
##         1  59 119
##         0 136 186
  • The contingency table created by this function is usually used for additional analyses, for example, the epitab function.

3.2 epitab

  • Calculates risks, risk ratio, odds ratio, and confidence intervals for epidemiologic data
epitab(x, y = NULL,
       method = c("oddsratio", "riskratio", "rateratio"),
       conf.level = 0.95,
       rev = c("neither", "rows", "columns", "both"),           
       oddsratio = c("wald", "fisher", "midp", "small"),
       riskratio = c("wald", "boot", "small"),
       rateratio = c("wald", "midp"),
       pvalue = c("fisher.exact", "midp.exact", "chi2"),
       correction = FALSE,
       verbose = FALSE)
  • Input data:
odds.ratio.or.risk.ratio rate.ratio
x = r x 2 table \[\checkmark\] \[\checkmark\] (1stcol: disease counts; 2nd col: person time at risk)
x = numeric vectors \[\checkmark\] (transformed into r x 2 table in row-wise order) \[\checkmark\] (counts followed by person time at risk)
x and y \[\checkmark\] (both are single factor or character vectors) \[\checkmark\] (x = single numeric vector of counts, y = numeric vector of corresponding person time at risk)
  • Other arguments and default values

    • measure of association: method = "oddsratio"

    • confidence level: conf.level = 0.05

    • estimation methods: The default of oddsratio, riskratio and rateratio are "wald"

    • pvalue = "fisher.exact"

    • correction = FALSE means no Yate’s continuity correction.

    • verbose = FALSE, set to TRUE to return more detailed results

  • The function epitab requires:

Disease - Disease +
Expose -
Expose +
stat <- epitab(epitable(dat$diet, dat$mort))
stat
## $tab
##          Outcome
## Predictor   0        p0   1        p1 oddsratio    lower     upper    p.value
##         0 186 0.6098361 136 0.6974359 1.0000000       NA        NA         NA
##         1 119 0.3901639  59 0.3025641 0.6780771 0.462563 0.9940021 0.05535248
## 
## $measure
## [1] "wald"
## 
## $conf.level
## [1] 0.95
## 
## $pvalue
## [1] "fisher.exact"
  • Outputs:
stat$tab
##          Outcome
## Predictor   0        p0   1        p1 oddsratio    lower     upper    p.value
##         0 186 0.6098361 136 0.6974359 1.0000000       NA        NA         NA
##         1 119 0.3901639  59 0.3025641 0.6780771 0.462563 0.9940021 0.05535248
  • The epidemiologic tabulation generated.
stat$measure
[1] "wald"
  • Wald (i.e. Normal approximation) is used to generate the CIs
$statconf.level
[1] 0.95
  • The confidence level is set to 95%
stat$pvalue
[1] "fisher.exact"
  • The Fisher exact test was used to generate the p-value.