twoxtwo: Create a twoxtwo table

Description Usage Arguments Details Value

View source: R/twoxtwo.R


The twoxtwo constructor function takes an input data frame and summarizes counts of the specified exposure and outcome variables as a two-by-two contingency table. This function is used internally in other functions, but can be used on its own as well. The returned object is given a twoxtwo class which allows dispatch of the twoxtwo S3 methods (see print.twoxtwo and summary.twoxtwo).

For more information on how the two-by-two table is created see 'Details'.


twoxtwo(.data, exposure, outcome, levels = NULL, na.rm = TRUE, retain = TRUE)



Data frame with observation-level exposure and outcome data


Name of exposure variable


Name of outcome variable


Levels for the exposure and outcome as a named list; if supplied, then the contingency table will be oriented with respect to the sequence of levels specified; default is NULL


Logical as to whether or not to remove NA values when constructing contingency table; default is TRUE


Logical as to whether or not the original data passed to the ".data" argument should be retained; if FALSE the summary.twoxtwo() function will not compute effect measures; default is TRUE


The two-by-two table covers four conditions that can be specified with A,B,C,D notation:

twoxtwo() requires that the exposure and outcome variables are binary. The columns can be character, numeric, or factor but must have only two levels. Each column will internally be coerced to a factor with levels reversed. The reversal results in exposures with TRUE and FALSE (or 1 and 0) oriented in the two-by-two table with the TRUE as "+" (first row) and FALSE as "-" (second row). Likewise, TRUE/FALSE outcomes will be oriented with TRUE as "+" (first column) and FALSE as "-" (second column). Note that the user can also define the orientation of the table using the "levels" argument.


A named list with the twoxtwo class. Elements include:

twoxtwo documentation built on July 9, 2021, 9:08 a.m.