| 1 |
<html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 |
<title>binomialQ</title> |
| 3 |
<style> |
| 4 |
td { padding-left: 5pt; padding-right: 5pt; } |
| 5 |
th { padding-left: 5pt; padding-right: 5pt; } |
| 6 |
code { white-space: pre-wrap; } |
| 7 |
dd { white-space: pre-wrap; } |
| 8 |
</style> |
| 9 |
</head><body bgcolor="#FFFFFF"> |
| 10 |
|
| 11 |
<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Monaco,Courier" size=6 color="#999900"><b> |
| 12 |
binomialQ |
| 13 |
</b></font></table></table> |
| 14 |
<p>A function that can be used in <a href="Formulas.html">Formulas</a>. The complement of the cumulative binomial distribution.</p> |
| 15 |
<h2>Syntax and semantics</h2> |
| 16 |
<dl> |
| 17 |
<dt><b><code><font size=+1>binomialQ</font></code></b> (<i><code><font size=+1>p</font></code></i>, <i><code><font size=+1>k</font></code></i>, <i><code><font size=+1>n</font></code></i>) |
| 18 |
<dd>compute the probability that in <i><code><font size=+1>n</font></code></i> trials an event with probability <i><code><font size=+1>p</font></code></i> will occur at least <i><code><font size=+1>k</font></code></i> times.</dd> |
| 19 |
</dl> |
| 20 |
<h2>Calculator example</h2> |
| 21 |
<p>A die is suspected to yield more sixes than a perfect die would do. In order to test this suspicion, you throw it 1,000 times. The result is 211 sixes.</p> |
| 22 |
<p>The probability that a perfect die yields at least 211 sixes is, according to <a href="Calculator___.html">Calculator...</a>,</p> |
| 23 |
<code> appendInfoLine: <b>binomialQ</b> (1/6, 211, 1000)<br></code> |
| 24 |
<code style="color:red">=></code><br> |
| 25 |
<code> 0.0001521645728419145<br></code> |
| 26 |
<p>which should be 0.000152.</p> |
| 27 |
<h2>Script example</h2> |
| 28 |
<p>You convert 1000 values of pitch targets in Hz to the nearest note on the piano keyboard. 597 of those values turn out to be in the A, B, C, D, E, F, or G regions (the white keys), and 403 values turn out to be in the A#, C#, D#, F#, or G# regions (the black keys). Do our subjects have a preference for the white keys? The following script computes the probability that in the case of no preference the subjects would target the white keys at least 597 times. This is compared with a <i>χ</i><sup>2</sup> test.</p> |
| 29 |
<code> a = 597<br></code> |
| 30 |
<code> b = 403<br></code> |
| 31 |
<code> p = 7/12 ; no preference<br></code> |
| 32 |
<code> writeInfoLine: “*** Binomial test ”, a, “, ”, b, “, p = ”, fixed$ (p, 6), “ ***”<br></code> |
| 33 |
<code> pbin = <b>binomialQ</b> (p, a, a+b)<br></code> |
| 34 |
<code> appendInfoLine: “P (binomial) = ”, fixed$ (pbin, 6)<br></code> |
| 35 |
<code> # Chi-square test with Yates correction:<br></code> |
| 36 |
<code> x2 = (a - 1/2 - p * (a+b)) ^ 2 / ( p * (a+b)) +<br></code> |
| 37 |
<code> ... (b + 1/2 - (1-p) * (a+b)) ^ 2 / ((1-p) * (a+b))<br></code> |
| 38 |
<code> px2 = chiSquareQ (x2, 1)<br></code> |
| 39 |
<code> appendInfoLine: “P (chi-square) = ”, fixed$ (px2, 6)<br></code> |
| 40 |
<code style="color:red">=></code><br> |
| 41 |
<code> *** Binomial test 597, 403, p = 0.583333 ***<br></code> |
| 42 |
<code> P (binomial) = 0.199330<br></code> |
| 43 |
<code> P (chi-square) = 0.398365<br></code> |
| 44 |
<p>The result is:</p> |
| 45 |
<code> *** Binomial test 597, 403, p = 0.583333 ***<br></code> |
| 46 |
<code> P (binomial) = 0.199330<br></code> |
| 47 |
<code> P (chi-square) = 0.398365<br></code> |
| 48 |
<p>The <i>χ</i><sup>2</sup> test is two-sided (it signals a preference for the white or for the black keys), so it has twice the probability of the binomial test.</p> |
| 49 |
<p>We cannot conclude from this test that people have a preference for the white keys. Of course, we cannot conclude either that people <i>don’t</i> have such a preference.</p> |
| 50 |
<h3>Links to this page</h3> |
| 51 |
<ul> |
| 52 |
<li><a href="_binomialP_.html"><code><font size=+1>binomialP</font></code></a> |
| 53 |
<li><a href="_invBinomialQ_.html"><code><font size=+1>invBinomialQ</font></code></a> |
| 54 |
<li><a href="Formulas_5__Mathematical_functions.html">Formulas 5. Mathematical functions</a> |
| 55 |
<li><a href="Functions.html">Functions</a> |
| 56 |
</ul> |
| 57 |
<hr> |
| 58 |
<address> |
| 59 |
<p>© Paul Boersma 2014, 2023</p> |
| 60 |
</address> |
| 61 |
</body> |
| 62 |
</html> |