AMR/docs/reference/g.test.html

419 lines
24 KiB
HTML
Raw Normal View History

2018-12-23 21:26:21 +01:00
<!-- Generated by pkgdown: do not edit by hand -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2020-08-10 12:46:03 +02:00
<title>G-test for Count Data — g.test • AMR (for R)</title>
2018-12-29 22:24:19 +01:00
<!-- favicons -->
<link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png" />
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png" />
2019-10-13 09:31:58 +02:00
2018-12-23 21:26:21 +01:00
<!-- jquery -->
2020-04-13 21:09:56 +02:00
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
2018-12-23 21:26:21 +01:00
<!-- Bootstrap -->
2020-12-27 00:07:00 +01:00
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/flatly/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous" />
2019-10-13 09:31:58 +02:00
2020-12-21 22:46:29 +01:00
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script>
2020-12-21 22:46:29 +01:00
2020-04-17 19:16:30 +02:00
<!-- bootstrap-toc -->
<link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script>
2018-12-23 21:26:21 +01:00
<!-- Font Awesome icons -->
2020-04-17 19:16:30 +02:00
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous" />
2018-12-23 21:26:21 +01:00
<!-- clipboard.js -->
2020-04-17 19:16:30 +02:00
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script>
2018-12-23 21:26:21 +01:00
2019-10-13 09:31:58 +02:00
<!-- headroom.js -->
2020-04-17 19:16:30 +02:00
<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script>
2018-12-23 21:26:21 +01:00
<!-- pkgdown -->
<link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script>
2018-12-29 22:24:19 +01:00
<link href="../extra.css" rel="stylesheet">
<script src="../extra.js"></script>
2018-12-23 21:26:21 +01:00
2020-08-10 12:46:03 +02:00
<meta property="og:title" content="G-test for Count Data — g.test" />
<meta property="og:description" content="g.test() performs chi-squared contingency table tests and goodness-of-fit tests, just like chisq.test() but is more reliable (1). A G-test can be used to see whether the number of observations in each category fits a theoretical expectation (called a G-test of goodness-of-fit), or to see whether the proportions of one variable are different for different values of the other variable (called a G-test of independence)." />
2020-10-04 19:26:43 +02:00
<meta property="og:image" content="https://msberends.github.io/AMR/logo.png" />
2018-12-23 21:26:21 +01:00
2019-10-13 09:31:58 +02:00
2018-12-23 21:26:21 +01:00
<!-- mathjax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
2019-10-13 09:31:58 +02:00
2018-12-23 21:26:21 +01:00
</head>
2020-04-17 19:16:30 +02:00
<body data-spy="scroll" data-target="#toc">
2018-12-23 21:26:21 +01:00
<div class="container template-reference-topic">
<header>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
2018-12-29 22:24:19 +01:00
<a class="navbar-link" href="../index.html">AMR (for R)</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Latest development version">1.5.0.9016</span>
2018-12-23 21:26:21 +01:00
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-home"></span>
2018-12-23 21:26:21 +01:00
2018-12-29 22:24:19 +01:00
Home
2018-12-23 21:26:21 +01:00
</a>
</li>
2019-01-02 23:24:07 +01:00
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
2020-12-17 16:22:25 +01:00
<span class="fas fa-question-circle"></span>
2019-01-02 23:24:07 +01:00
How to
2018-12-29 22:24:19 +01:00
2019-01-02 23:24:07 +01:00
<span class="caret"></span>
2018-12-29 22:24:19 +01:00
</a>
2019-01-02 23:24:07 +01:00
<ul class="dropdown-menu" role="menu">
<li>
<a href="../articles/AMR.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-directions"></span>
2019-01-02 23:24:07 +01:00
Conduct AMR analysis
</a>
</li>
<li>
2019-02-14 10:23:51 +01:00
<a href="../articles/resistance_predict.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-dice"></span>
2019-01-02 23:24:07 +01:00
Predict antimicrobial resistance
</a>
</li>
2020-08-21 11:40:13 +02:00
<li>
<a href="../articles/datasets.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-database"></span>
2020-08-21 11:40:13 +02:00
Data sets for download / own use
2020-08-21 11:40:13 +02:00
</a>
</li>
2020-04-13 21:09:56 +02:00
<li>
<a href="../articles/PCA.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-compress"></span>
2020-04-13 21:09:56 +02:00
Conduct principal component analysis for AMR
</a>
</li>
2019-05-28 16:50:40 +02:00
<li>
<a href="../articles/MDR.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-skull-crossbones"></span>
2019-05-28 16:50:40 +02:00
Determine multi-drug resistance (MDR)
</a>
</li>
2019-01-29 00:06:50 +01:00
<li>
<a href="../articles/WHONET.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-globe-americas"></span>
2019-01-29 00:06:50 +01:00
Work with WHONET data
</a>
</li>
2019-02-14 15:18:17 +01:00
<li>
<a href="../articles/SPSS.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-file-upload"></span>
2019-02-14 15:18:17 +01:00
Import data from SPSS/SAS/Stata
</a>
</li>
2019-01-02 23:24:07 +01:00
<li>
<a href="../articles/EUCAST.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-exchange-alt"></span>
2019-01-02 23:24:07 +01:00
Apply EUCAST rules
</a>
</li>
<li>
2019-02-14 10:23:51 +01:00
<a href="../reference/mo_property.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-bug"></span>
2019-01-02 23:24:07 +01:00
Get properties of a microorganism
</a>
</li>
<li>
2019-05-16 21:20:00 +02:00
<a href="../reference/ab_property.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-capsules"></span>
2019-01-02 23:24:07 +01:00
Get properties of an antibiotic
</a>
</li>
2019-01-11 20:37:23 +01:00
<li>
<a href="../articles/benchmarks.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-shipping-fast"></span>
2019-01-11 20:37:23 +01:00
Other: benchmarks
</a>
</li>
2019-01-02 23:24:07 +01:00
</ul>
2018-12-23 21:26:21 +01:00
</li>
<li>
2020-07-28 18:39:57 +02:00
<a href="../reference/index.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-book-open"></span>
2018-12-29 22:24:19 +01:00
Manual
</a>
</li>
<li>
<a href="../authors.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-users"></span>
2018-12-29 22:24:19 +01:00
Authors
</a>
2018-12-23 21:26:21 +01:00
</li>
2018-12-29 22:24:19 +01:00
<li>
2020-07-28 18:39:57 +02:00
<a href="../news/index.html">
2020-12-17 16:22:25 +01:00
<span class="far fa-newspaper"></span>
2018-12-23 21:26:21 +01:00
2018-12-29 22:24:19 +01:00
Changelog
2018-12-23 21:26:21 +01:00
</a>
</li>
2019-01-02 23:24:07 +01:00
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
2020-07-08 14:48:06 +02:00
<a href="https://github.com/msberends/AMR">
2020-12-17 16:22:25 +01:00
<span class="fab fa-github"></span>
2018-12-29 22:24:19 +01:00
Source Code
</a>
2018-12-23 21:26:21 +01:00
</li>
2019-01-02 23:24:07 +01:00
<li>
2020-07-28 18:39:57 +02:00
<a href="../survey.html">
2020-12-17 16:22:25 +01:00
<span class="fas fa-clipboard-list"></span>
2018-12-29 22:24:19 +01:00
2020-07-28 18:39:57 +02:00
Survey
2018-12-29 22:24:19 +01:00
</a>
</li>
2018-12-23 21:26:21 +01:00
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
2019-10-13 09:31:58 +02:00
2018-12-23 21:26:21 +01:00
</header>
<div class="row">
<div class="col-md-9 contents">
<div class="page-header">
<h1><em>G</em>-test for Count Data</h1>
2020-07-08 14:48:06 +02:00
<small class="dont-index">Source: <a href='https://github.com/msberends/AMR/blob/master/R/g.test.R'><code>R/g.test.R</code></a></small>
2018-12-23 21:26:21 +01:00
<div class="hidden name"><code>g.test.Rd</code></div>
</div>
<div class="ref-description">
<p><code>g.test()</code> performs chi-squared contingency table tests and goodness-of-fit tests, just like <code><a href='https://rdrr.io/r/stats/chisq.test.html'>chisq.test()</a></code> but is more reliable (1). A <em>G</em>-test can be used to see whether the number of observations in each category fits a theoretical expectation (called a <strong><em>G</em>-test of goodness-of-fit</strong>), or to see whether the proportions of one variable are different for different values of the other variable (called a <strong><em>G</em>-test of independence</strong>).</p>
2018-12-23 21:26:21 +01:00
</div>
<pre class="usage"><span class='fu'>g.test</span><span class='op'>(</span><span class='va'>x</span>, y <span class='op'>=</span> <span class='cn'>NULL</span>, p <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span><span class='op'>(</span><span class='fl'>1</span><span class='op'>/</span><span class='fu'><a href='https://rdrr.io/r/base/length.html'>length</a></span><span class='op'>(</span><span class='va'>x</span><span class='op'>)</span>, <span class='fu'><a href='https://rdrr.io/r/base/length.html'>length</a></span><span class='op'>(</span><span class='va'>x</span><span class='op'>)</span><span class='op'>)</span>, rescale.p <span class='op'>=</span> <span class='cn'>FALSE</span><span class='op'>)</span></pre>
2019-10-13 09:31:58 +02:00
2018-12-23 21:26:21 +01:00
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
<table class="ref-arguments">
<colgroup><col class="name" /><col class="desc" /></colgroup>
<tr>
<th>x</th>
<td><p>a numeric vector or matrix. <code>x</code> and <code>y</code> can also
both be factors.</p></td>
</tr>
<tr>
<th>y</th>
<td><p>a numeric vector; ignored if <code>x</code> is a matrix. If
<code>x</code> is a factor, <code>y</code> should be a factor of the same length.</p></td>
</tr>
<tr>
<th>p</th>
<td><p>a vector of probabilities of the same length of <code>x</code>.
An error is given if any entry of <code>p</code> is negative.</p></td>
</tr>
<tr>
<th>rescale.p</th>
<td><p>a logical scalar; if TRUE then <code>p</code> is rescaled
(if necessary) to sum to 1. If <code>rescale.p</code> is FALSE, and
<code>p</code> does not sum to 1, an error is given.</p></td>
</tr>
</table>
2019-10-13 09:31:58 +02:00
2018-12-23 21:26:21 +01:00
<h2 class="hasAnchor" id="source"><a class="anchor" href="#source"></a>Source</h2>
<p>The code for this function is identical to that of <code><a href='https://rdrr.io/r/stats/chisq.test.html'>chisq.test()</a></code>, except that:</p><ul>
<li><p>The calculation of the statistic was changed to \(2 * sum(x * log(x / E))\)</p></li>
2018-12-23 21:26:21 +01:00
<li><p>Yates' continuity correction was removed as it does not apply to a <em>G</em>-test</p></li>
<li><p>The possibility to simulate p values with <code>simulate.p.value</code> was removed</p></li>
</ul>
2019-10-13 09:31:58 +02:00
2018-12-23 21:26:21 +01:00
<h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>
<p>A list with class <code>"htest"</code> containing the following
components:</p>
<dt>statistic</dt><dd><p>the value the chi-squared test statistic.</p></dd>
<dt>parameter</dt><dd><p>the degrees of freedom of the approximate
chi-squared distribution of the test statistic, <code>NA</code> if the
p-value is computed by Monte Carlo simulation.</p></dd>
<dt>p.value</dt><dd><p>the p-value for the test.</p></dd>
<dt>method</dt><dd><p>a character string indicating the type of test
performed, and whether Monte Carlo simulation or continuity
correction was used.</p></dd>
<dt>data.name</dt><dd><p>a character string giving the name(s) of the data.</p></dd>
<dt>observed</dt><dd><p>the observed counts.</p></dd>
<dt>expected</dt><dd><p>the expected counts under the null hypothesis.</p></dd>
<dt>residuals</dt><dd><p>the Pearson residuals,
<code>(observed - expected) / sqrt(expected)</code>.</p></dd>
<dt>stdres</dt><dd><p>standardized residuals,
<code>(observed - expected) / sqrt(V)</code>, where <code>V</code> is the residual cell variance (Agresti, 2007,
section 2.4.5 for the case where <code>x</code> is a matrix, <code>n * p * (1 - p)</code> otherwise).</p></dd>
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
<p>If <code>x</code> is a matrix with one row or column, or if <code>x</code> is a vector and <code>y</code> is not given, then a <em>goodness-of-fit test</em> is performed (<code>x</code> is treated as a one-dimensional contingency table). The entries of <code>x</code> must be non-negative integers. In this case, the hypothesis tested is whether the population probabilities equal those in <code>p</code>, or are all equal if <code>p</code> is not given.</p>
<p>If <code>x</code> is a matrix with at least two rows and columns, it is taken as a two-dimensional contingency table: the entries of <code>x</code> must be non-negative integers. Otherwise, <code>x</code> and <code>y</code> must be vectors or factors of the same length; cases with missing values are removed, the objects are coerced to factors, and the contingency table is computed from these. Then Pearson's chi-squared test is performed of the null hypothesis that the joint distribution of the cell counts in a 2-dimensional contingency table is the product of the row and column marginals.</p>
<p>The p-value is computed from the asymptotic chi-squared distribution of the test statistic.</p>
2020-12-17 16:22:25 +01:00
<p>In the contingency table case simulation is done by random sampling from the set of all contingency tables with given marginals, and works only if the marginals are strictly positive. Note that this is not the usual sampling situation assumed for a chi-squared test (such as the <em>G</em>-test) but rather that for Fisher's exact test.</p>
<p>In the goodness-of-fit case simulation is done by random sampling from the discrete distribution specified by <code>p</code>, each sample being of size <code>n = sum(x)</code>. This simulation is done in <span style="R">R</span> and may be slow.</p><h3 class='hasAnchor' id='arguments'><a class='anchor' href='#arguments'></a><em>G</em>-test Of Goodness-of-Fit (Likelihood Ratio Test)</h3>
2018-12-23 21:26:21 +01:00
2019-10-13 09:31:58 +02:00
<p>Use the <em>G</em>-test of goodness-of-fit when you have one nominal variable with two or more values (such as male and female, or red, pink and white flowers). You compare the observed counts of numbers of observations in each category with the expected counts, which you calculate using some kind of theoretical expectation (such as a 1:1 sex ratio or a 1:2:1 ratio in a genetic cross).</p>
<p>If the expected number of observations in any category is too small, the <em>G</em>-test may give inaccurate results, and you should use an exact test instead (<code><a href='https://rdrr.io/r/stats/fisher.test.html'>fisher.test()</a></code>).</p>
<p>The <em>G</em>-test of goodness-of-fit is an alternative to the chi-square test of goodness-of-fit (<code><a href='https://rdrr.io/r/stats/chisq.test.html'>chisq.test()</a></code>); each of these tests has some advantages and some disadvantages, and the results of the two tests are usually very similar.</p>
<h3 class='hasAnchor' id='arguments'><a class='anchor' href='#arguments'></a><em>G</em>-test of Independence</h3>
2018-12-23 21:26:21 +01:00
2019-10-13 09:31:58 +02:00
<p>Use the <em>G</em>-test of independence when you have two nominal variables, each with two or more possible values. You want to know whether the proportions for one variable are different among values of the other variable.</p>
2018-12-23 21:26:21 +01:00
<p>It is also possible to do a <em>G</em>-test of independence with more than two nominal variables. For example, Jackson et al. (2013) also had data for children under 3, so you could do an analysis of old vs. young, thigh vs. arm, and reaction vs. no reaction, all analyzed together.</p>
<p>Fisher's exact test (<code><a href='https://rdrr.io/r/stats/fisher.test.html'>fisher.test()</a></code>) is an <strong>exact</strong> test, where the <em>G</em>-test is still only an <strong>approximation</strong>. For any 2x2 table, Fisher's Exact test may be slower but will still run in seconds, even if the sum of your observations is multiple millions.</p>
<p>The <em>G</em>-test of independence is an alternative to the chi-square test of independence (<code><a href='https://rdrr.io/r/stats/chisq.test.html'>chisq.test()</a></code>), and they will give approximately the same results.</p>
2018-12-23 21:26:21 +01:00
<h3 class='hasAnchor' id='arguments'><a class='anchor' href='#arguments'></a>How the Test Works</h3>
2019-10-13 09:31:58 +02:00
<p>Unlike the exact test of goodness-of-fit (<code><a href='https://rdrr.io/r/stats/fisher.test.html'>fisher.test()</a></code>), the <em>G</em>-test does not directly calculate the probability of obtaining the observed results or something more extreme. Instead, like almost all statistical tests, the <em>G</em>-test has an intermediate step; it uses the data to calculate a test statistic that measures how far the observed data are from the null expectation. You then use a mathematical relationship, in this case the chi-square distribution, to estimate the probability of obtaining that value of the test statistic.</p>
2018-12-23 21:26:21 +01:00
<p>The <em>G</em>-test uses the log of the ratio of two likelihoods as the test statistic, which is why it is also called a likelihood ratio test or log-likelihood ratio test. The formula to calculate a <em>G</em>-statistic is:</p>
<p>\(G = 2 * sum(x * log(x / E))\)</p>
<p>where <code>E</code> are the expected values. Since this is chi-square distributed, the p value can be calculated in <span style="R">R</span> with:</p><pre><span class='va'>p</span> <span class='op'>&lt;-</span> <span class='fu'>stats</span><span class='fu'>::</span><span class='fu'><a href='https://rdrr.io/r/stats/Chisquare.html'>pchisq</a></span><span class='op'>(</span><span class='va'>G</span>, <span class='va'>df</span>, lower.tail <span class='op'>=</span> <span class='cn'>FALSE</span><span class='op'>)</span>
2020-10-04 19:26:43 +02:00
</pre>
2018-12-23 21:26:21 +01:00
<p>where <code>df</code> are the degrees of freedom.</p>
<p>If there are more than two categories and you want to find out which ones are significantly different from their null expectation, you can use the same method of testing each category vs. the sum of all categories, with the Bonferroni correction. You use <em>G</em>-tests for each category, of course.</p>
<h2 class="hasAnchor" id="questioning-lifecycle"><a class="anchor" href="#questioning-lifecycle"></a>Questioning Lifecycle</h2>
<p><img src='figures/lifecycle_questioning.svg' style=margin-bottom:5px /> <br />
The <a href='lifecycle.html'>lifecycle</a> of this function is <strong>questioning</strong>. This function might be no longer be optimal approach, or is it questionable whether this function should be in this <code>AMR</code> package at all.</p>
<h2 class="hasAnchor" id="read-more-on-our-website-"><a class="anchor" href="#read-more-on-our-website-"></a>Read more on Our Website!</h2>
2019-01-02 23:24:07 +01:00
2019-10-13 09:31:58 +02:00
<p>On our website <a href='https://msberends.github.io/AMR/'>https://msberends.github.io/AMR/</a> you can find <a href='https://msberends.github.io/AMR/articles/AMR.html'>a comprehensive tutorial</a> about how to conduct AMR data analysis, the <a href='https://msberends.github.io/AMR/reference/'>complete documentation of all functions</a> and <a href='https://msberends.github.io/AMR/articles/WHONET.html'>an example analysis using WHONET data</a>. As we would like to better understand the backgrounds and needs of our users, please <a href='https://msberends.github.io/AMR/survey.html'>participate in our survey</a>!</p>
2018-12-23 21:26:21 +01:00
<h2 class="hasAnchor" id="references"><a class="anchor" href="#references"></a>References</h2>
<ol>
<li><p>McDonald, J.H. 2014. <strong>Handbook of Biological Statistics (3rd ed.)</strong>. Sparky House Publishing, Baltimore, Maryland. <a href='http://www.biostathandbook.com/gtestgof.html'>http://www.biostathandbook.com/gtestgof.html</a>.</p></li>
</ol>
2018-12-23 21:26:21 +01:00
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p><code><a href='https://rdrr.io/r/stats/chisq.test.html'>chisq.test()</a></code></p></div>
2018-12-23 21:26:21 +01:00
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
2019-10-13 09:31:58 +02:00
<pre class="examples"><span class='co'># = EXAMPLE 1 =</span>
2018-12-23 21:26:21 +01:00
<span class='co'># Shivrain et al. (2006) crossed clearfield rice (which are resistant</span>
<span class='co'># to the herbicide imazethapyr) with red rice (which are susceptible to</span>
<span class='co'># imazethapyr). They then crossed the hybrid offspring and examined the</span>
<span class='co'># F2 generation, where they found 772 resistant plants, 1611 moderately</span>
<span class='co'># resistant plants, and 737 susceptible plants. If resistance is controlled</span>
<span class='co'># by a single gene with two co-dominant alleles, you would expect a 1:2:1</span>
<span class='co'># ratio.</span>
<span class='va'>x</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>772</span>, <span class='fl'>1611</span>, <span class='fl'>737</span><span class='op'>)</span>
<span class='va'>G</span> <span class='op'>&lt;-</span> <span class='fu'>g.test</span><span class='op'>(</span><span class='va'>x</span>, p <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>1</span>, <span class='fl'>2</span>, <span class='fl'>1</span><span class='op'>)</span> <span class='op'>/</span> <span class='fl'>4</span><span class='op'>)</span>
2018-12-23 21:26:21 +01:00
<span class='co'># G$p.value = 0.12574.</span>
<span class='co'># There is no significant difference from a 1:2:1 ratio.</span>
<span class='co'># Meaning: resistance controlled by a single gene with two co-dominant</span>
<span class='co'># alleles, is plausible.</span>
<span class='co'># = EXAMPLE 2 =</span>
<span class='co'># Red crossbills (Loxia curvirostra) have the tip of the upper bill either</span>
<span class='co'># right or left of the lower bill, which helps them extract seeds from pine</span>
<span class='co'># cones. Some have hypothesized that frequency-dependent selection would</span>
<span class='co'># keep the number of right and left-billed birds at a 1:1 ratio. Groth (1992)</span>
<span class='co'># observed 1752 right-billed and 1895 left-billed crossbills.</span>
<span class='va'>x</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>1752</span>, <span class='fl'>1895</span><span class='op'>)</span>
<span class='fu'>g.test</span><span class='op'>(</span><span class='va'>x</span><span class='op'>)</span>
2019-01-02 23:24:07 +01:00
<span class='co'># p = 0.01787343</span>
2018-12-23 21:26:21 +01:00
2019-01-02 23:24:07 +01:00
<span class='co'># There is a significant difference from a 1:1 ratio.</span>
2020-08-10 12:46:03 +02:00
<span class='co'># Meaning: there are significantly more left-billed birds.</span>
2020-10-04 19:26:43 +02:00
2020-08-10 12:46:03 +02:00
</pre>
2018-12-23 21:26:21 +01:00
</div>
2020-04-13 21:09:56 +02:00
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
2020-04-17 19:16:30 +02:00
<nav id="toc" data-toggle="toc" class="sticky-top">
<h2 data-toc-skip>Contents</h2>
</nav>
2018-12-23 21:26:21 +01:00
</div>
</div>
2019-10-13 09:31:58 +02:00
2018-12-23 21:26:21 +01:00
<footer>
<div class="copyright">
2020-01-26 20:38:54 +01:00
<p>Developed by <a href='https://www.rug.nl/staff/m.s.berends/'>Matthijs S. Berends</a>, <a href='https://www.rug.nl/staff/c.f.luz/'>Christian F. Luz</a>, <a href='https://www.rug.nl/staff/a.w.friedrich/'>Alexander W. Friedrich</a>, <a href='https://www.rug.nl/staff/b.sinha/'>Bhanu N. M. Sinha</a>, <a href='https://www.rug.nl/staff/c.j.albers/'>Casper J. Albers</a>, <a href='https://www.rug.nl/staff/c.glasner/'>Corinna Glasner</a>.</p>
2018-12-23 21:26:21 +01:00
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
2018-12-23 21:26:21 +01:00
</div>
2019-10-13 09:31:58 +02:00
2018-12-23 21:26:21 +01:00
</footer>
</div>
2019-10-13 09:31:58 +02:00
2018-12-23 21:26:21 +01:00
</body>
</html>
2019-10-13 09:31:58 +02:00