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'.
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
Logical as to whether or not to remove
Logical as to whether or not the original data passed to the ".data" argument should be retained; if
The two-by-two table covers four conditions that can be specified with A,B,C,D notation:
A: Exposure "+" and Outcome "+"
B: Exposure "+" and Outcome "-"
C: Exposure "-" and Outcome "+"
D: Exposure "-" and Outcome "-"
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
0) oriented in the two-by-two table with the
TRUE as "+" (first row) and
FALSE as "-" (second row). Likewise,
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:
tbl: The summarized two-by-two contingency table as a
cells: Named list with the counts in each of the cells in the two-by-two contingency table (i.e. A,B,C,D)
exposure: Named list of exposure information (name of variable and levels)
outcome: Named list of outcome information (name of variable and levels)
n_missing: The number of missing values (in either exposure or outcome variable) removed prior to computing counts for the two-by-two table
data: The original data frame passed to the ".data" argument. If
retain=FALSE, then this element will be
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.