MyNixOS website logo
Description
Work with Two-by-Two Tables
A collection of functions for data analysis with two-by-two contingency tables. The package provides tools to compute measures of effect (odds ratio, risk ratio, and risk difference), calculate impact numbers and attributable fractions, and perform hypothesis testing. Statistical analysis methods are oriented towards epidemiological investigation of relationships between exposures and outcomes.

twoxtwo

build status(main) build status(dev)

The twoxtwo package provides a collection of functions to display, summarize, and analyze data in two-by-two contingency tables. Statistical analysis functions are oriented towards epidemiological investigation of exposure/outcome relationships.

Installation

## install.packages("devtools")
devtools::install_github("vpnagraj/twoxtwo", build_vignettes = TRUE)

Features

  • twoxtwo(): Construct twoxtwo object
  • odds_ratio(): Estimate odds ratio and confidence interval
  • risk_ratio(): Estimate risk ratio and confidence interval
  • risk_diff(): Estimate risk difference and confidence interval
  • fisher(): Perform Fisher’s exact test
  • chisq(): Perform Pearson’s chi-squared test
  • arp(): Estimate attributable risk proportion (ARP) and confidence interval
  • parp(): Estimate population attributable risk proportion (PARP) and confidence interval
  • ein(): Estimate exposure impact number (EIN) and confidence interval
  • cin(): Estimate case impact number (CIN) and confidence interval
  • ecin(): Estimate exposed cases impact number (ECIN) and confidence interval
  • summary.twoxtwo(): Summarize twoxtwo object
  • print.twoxtwo(): Print twoxtwo object
  • display(): Render twoxtwo table contents as a knitr::kable

Usage

Example

First load twoxtwo and dplyr to help prep data:

library(twoxtwo)
library(dplyr)

Next create a object with S3 class twoxtwo. For this example, use the twoxtwo::titanic dataset. Note that “exposure” and “outcome” variables must each be binary variables:

crew_2x2 <-
  titanic %>%
  twoxtwo(.data = ., exposure = Crew, outcome = Survived)

crew_2x2
# |         |           |OUTCOME      |OUTCOME     |
# |:--------|:----------|:------------|:-----------|
# |         |           |Survived=Yes |Survived=No |
# |EXPOSURE |Crew=TRUE  |212          |673         |
# |EXPOSURE |Crew=FALSE |499          |817         |

The twoxtwo class has its own summary.twoxtwo() method that computes effect measures (odds ratio, risk ratio, and risk difference):

summary(crew_2x2)
# 
# |         |           |OUTCOME      |OUTCOME     |
# |:--------|:----------|:------------|:-----------|
# |         |           |Survived=Yes |Survived=No |
# |EXPOSURE |Crew=TRUE  |212          |673         |
# |EXPOSURE |Crew=FALSE |499          |817         |
# 
# 
# Outcome: Survived
# Outcome + : Yes
# Outcome - : No
# 
# Exposure: Crew
# Exposure + : TRUE
# Exposure - : FALSE
# 
# Number of missing observations: 0
# 
# Odds Ratio: 0.516 (0.426,0.624)
# Risk Ratio: 0.632 (0.551,0.724)
# Risk Difference: -0.14 (-0.178,-0.101)

Individual measures of effect, hypothesis tests, and impact numbers can be calculated using the twoxtwo object. For example:

crew_2x2 %>%
  odds_ratio()
# # A tibble: 1 x 6
#   measure    estimate ci_lower ci_upper exposure         outcome         
#   <chr>         <dbl>    <dbl>    <dbl> <chr>            <chr>           
# 1 Odds Ratio    0.516    0.426    0.624 Crew::TRUE/FALSE Survived::Yes/No
crew_2x2 %>%
  chisq()
# # A tibble: 1 x 9
#   test      estimate ci_lower ci_upper statistic    df   pvalue exposure outcome
#   <chr>     <lgl>    <lgl>    <lgl>        <dbl> <int>    <dbl> <chr>    <chr>  
# 1 Pearson'… NA       NA       NA            46.5     1 8.97e-12 Crew::T… Surviv…

Note that data analysis can also be performed without first creating the twoxtwo object:

titanic %>%
  odds_ratio(.data = ., exposure = Crew, outcome = Survived)
# # A tibble: 1 x 6
#   measure    estimate ci_lower ci_upper exposure         outcome         
#   <chr>         <dbl>    <dbl>    <dbl> <chr>            <chr>           
# 1 Odds Ratio    0.516    0.426    0.624 Crew::TRUE/FALSE Survived::Yes/No
titanic %>%
  chisq(.data = ., exposure = Crew, outcome = Survived)
# # A tibble: 1 x 9
#   test      estimate ci_lower ci_upper statistic    df   pvalue exposure outcome
#   <chr>     <lgl>    <lgl>    <lgl>        <dbl> <int>    <dbl> <chr>    <chr>  
# 1 Pearson'… NA       NA       NA            46.5     1 8.97e-12 Crew::T… Surviv…

Vignettes

The package includes vignettes to describe usage in more detail.

For details on the twoxtwo data structure and demonstration of basic usage:

vignette("basic-usage", package = "twoxtwo")

For formulas and examples of how to calculate measures of effect:

vignette("measures-of-effect", package = "twoxtwo")

For information on hypothesis testing functionality in the package:

vignette("hypothesis-testing", package = "twoxtwo")

For formulas and demonstration of attributable fraction and impact number calculations:

vignette("af-impact", package = "twoxtwo")

Contributing

Please use GitHub issues to report bugs or request features. Contributions will be reviewed via pull requests.

Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows