reconstruct_two {DiscreteDatasets}R Documentation

Reconstruct a set of four-fold tables from rows or columns

Description

In some situations, fourfold tables are reduced to two elements, which makes it impossible to use them straight away for statistical tests like Fisher's exact test. But sometimes, when all tables had the same known marginal sums, the missing values can be restored using that additional information. The reconstruct_two function uses a set of such reduced tables, stored row-wise in a matrix or a data frame, and rebuilds the two missing columns from automatically computed or given marginal totals.

Usage

reconstruct_two(
  dat,
  totals = NULL,
  insert_at = NULL,
  colnames_add = NULL,
  colnames_prepend = NULL,
  colnames_append = NULL,
  colnames_sep = "_"
)

Arguments

dat

integer matrix or data frame with exactly two columns; each row represents the first column of a 2x2 matrix for which the other two values are to be computed and appended to dat as two new columns; real numbers will be coerced to integer.

totals

integer vector of exactly one or two values or NULL (the default); the new columns will be derived by subtracting the existing column values from totals; if NULL, the sums of the two existing columns of dat are used.

insert_at

integer vector of exactly two values between 1 and 4 or NULL (the default) indicating the indices at which the values are to be inserted; if NULL, the new values are appended at the end, i.e. at positions 3 and 4.

colnames_add

character vector of exactly two unique character strings or NULL (the default), which contains the desired headers of the new (reconstructed) columns of the input; if NULL, the headers of dat are used (with appended strings; see below).

colnames_prepend

character vector of exactly two unique character strings (NAs are allowed) or NULL (the default); the first string will be prepended to the headers of the original headers of dat, while the second is used in the same manner for the reconstructed columns.

colnames_append

character vector of exactly two unique character strings (NAs are allowed) or NULL (the default); the first string will be appended to the headers of the original headers of dat, while the second is used in the same manner for the reconstructed columns; if colnames_add = NULL and colnames_append = NULL, c("A", "B") will be used.

colnames_sep

a single character or NULL (the default) giving the separator for combining colnames_prepend and colnames_append with the column names.

Value

An integer data frame with four columns.

Examples

data(amnesia)
amnesia_four_columns <- reconstruct_two(
  amnesia,
  NULL,
  NULL,
  NULL,
  NULL,
  c("ThisDrug", "AllOtherDrugs"),
  "."
)
head(amnesia_four_columns)

data(hiv)
hiv_four_columns <- reconstruct_two(
  hiv,
  73,
  NULL,
  NULL,
  NULL,
  c("Mutation", "NoMutation"),
  "."
)
head(hiv_four_columns)

data(listerdata)
listerdata_four_columns <- reconstruct_two(
  listerdata,
  c(34244, 39342),
  NULL,
  NULL,
  NULL,
  c("This_Cyto", "All_Other_Cytos"),
  "_"
)
head(listerdata_four_columns)


[Package DiscreteDatasets version 0.1.0 Index]