EVOLUTION-MANAGER
Edit File: r2dtable.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Random 2-way Tables with Given Marginals</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for r2dtable {stats}"><tr><td>r2dtable {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Random 2-way Tables with Given Marginals</h2> <h3>Description</h3> <p>Generate random 2-way tables with given marginals using Patefield's algorithm. </p> <h3>Usage</h3> <pre> r2dtable(n, r, c) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>n</code></td> <td> <p>a non-negative numeric giving the number of tables to be drawn.</p> </td></tr> <tr valign="top"><td><code>r</code></td> <td> <p>a non-negative vector of length at least 2 giving the row totals, to be coerced to <code>integer</code>. Must sum to the same as <code>c</code>.</p> </td></tr> <tr valign="top"><td><code>c</code></td> <td> <p>a non-negative vector of length at least 2 giving the column totals, to be coerced to <code>integer</code>.</p> </td></tr> </table> <h3>Value</h3> <p>A list of length <code>n</code> containing the generated tables as its components. </p> <h3>References</h3> <p>Patefield, W. M. (1981). Algorithm AS 159: An efficient method of generating r x c tables with given row and column totals. <em>Applied Statistics</em>, <b>30</b>, 91–97. doi: <a href="https://doi.org/10.2307/2346669">10.2307/2346669</a>. </p> <h3>Examples</h3> <pre> ## Fisher's Tea Drinker data. TeaTasting <- matrix(c(3, 1, 1, 3), nrow = 2, dimnames = list(Guess = c("Milk", "Tea"), Truth = c("Milk", "Tea"))) ## Simulate permutation test for independence based on the maximum ## Pearson residuals (rather than their sum). rowTotals <- rowSums(TeaTasting) colTotals <- colSums(TeaTasting) nOfCases <- sum(rowTotals) expected <- outer(rowTotals, colTotals, "*") / nOfCases maxSqResid <- function(x) max((x - expected) ^ 2 / expected) simMaxSqResid <- sapply(r2dtable(1000, rowTotals, colTotals), maxSqResid) sum(simMaxSqResid >= maxSqResid(TeaTasting)) / 1000 ## Fisher's exact test gives p = 0.4857 ... </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>