twoxtwo {twoxtwo}R Documentation

Create a twoxtwo table

Description

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'.

Usage

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

Arguments

.data

Data frame with observation-level exposure and outcome data

exposure

Name of exposure variable

outcome

Name of outcome variable

levels

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

na.rm

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

retain

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

Details

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.

Value

A named list with the twoxtwo class. Elements include:


[Package twoxtwo version 0.1.0 Index]