knitr::opts_chunk$set( collapse = TRUE, comment = "#", fig.path = "man/figures/README-", out.width = "100%" )
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.
To install the stable release from CRAN:
install.packages("twoxtwo")
Or to install the development release from GitHub:
## install.packages("devtools") devtools::install_github("vpnagraj/twoxtwo", build_vignettes = TRUE)
twoxtwo()
: Construct twoxtwo
objectodds_ratio()
: Estimate odds ratio and confidence intervalrisk_ratio()
: Estimate risk ratio and confidence intervalrisk_diff()
: Estimate risk difference and confidence intervalfisher()
: Perform Fisher's exact testchisq()
: Perform Pearson's chi-squared testarp()
: Estimate attributable risk proportion (ARP) and confidence intervalparp()
: Estimate population attributable risk proportion (PARP) and confidence intervalein()
: Estimate exposure impact number (EIN) and confidence intervalcin()
: Estimate case impact number (CIN) and confidence intervalecin()
: Estimate exposed cases impact number (ECIN) and confidence intervalsummary.twoxtwo()
: Summarize twoxtwo
objectprint.twoxtwo()
: Print twoxtwo
objectdisplay()
: Render twoxtwo
table contents as a knitr::kable
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
The twoxtwo
class has its own summary.twoxtwo()
method that computes effect measures (odds ratio, risk ratio, and risk difference):
summary(crew_2x2)
Individual measures of effect, hypothesis tests, and impact numbers can be calculated using the twoxtwo
object. For example:
crew_2x2 %>% odds_ratio()
crew_2x2 %>% chisq()
Note that data analysis can also be performed without first creating the twoxtwo
object:
titanic %>% odds_ratio(.data = ., exposure = Crew, outcome = Survived)
titanic %>% chisq(.data = ., exposure = Crew, outcome = Survived)
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")
Please use GitHub issues to report bugs or request features. Contributions will be reviewed via pull requests.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.