reconstruct_four | R Documentation |
Sometimes, fourfold tables are reformatted by replacing rows or columns by
marginal totals. This makes it impossible to use them straight away for
statistical tests like Fisher's exact test. But with that knowledge, the
missing values can easily be restored. The reconstruct_four
function uses a set of such reduced tables, stored row-wise in a matrix or a
data frame, and rebuilds the two reformatted cells when they were replaced by
marginal totals.
reconstruct_four(dat, idx_marginals = NULL, colnames_add = NULL)
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 |
idx_marginals |
integer vector of exactly two values or
|
colnames_add |
character vector of exactly two unique character
strings or |
An integer data frame with four columns.
X1 <- c(4, 2, 2, 14, 6, 9, 4, 0, 1)
X2 <- c(0, 0, 1, 3, 2, 1, 2, 2, 2)
N1 <- rep(148, 9)
N2 <- rep(132, 9)
df1 <- data.frame(X1, X2, N1, N2)
reconstruct_four(df1, colnames_add = c("Y1", "Y2"))
# same as reconstruct_four(df1, c(3, 4), c("Y1", "Y2"))
df2 <- data.frame(X1, N1, X2, N2)
reconstruct_four(df2, c(2, 4), c("Y1", "Y2"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.