binomialQ

A function that can be used in Formulas. The complement of the cumulative binomial distribution.

## Syntax and semantics

`binomialQ` (`p`, `k`, `n`)
  compute the probability that in `n` trials an event with probability `p` will occur at least `k` times.

## Calculator example

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.

The probability that a perfect die yields at least 211 sixes is, according to Calculator...,

`appendInfoLine: binomialQ (1/6, 211, 1000)
` `=>`
`0.0001521645728419145
`

which should be 0.000152.

## Script example

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 χ2 test.

`a = 597
` `b = 403
` `p = 7/12 ; no preference
` `writeInfoLine: “*** Binomial test ”, a, “, ”, b, “, p = ”, fixed$ (p, 6), “ ***”
` `pbin = binomialQ (p, a, a+b)
` `appendInfoLine: “P (binomial) = ”, fixed$ (pbin, 6)
` `# Chi-square test with Yates correction:
` `x2 = (a - 1/2 - p * (a+b)) ^ 2 / ( p * (a+b)) +
` `... (b + 1/2 - (1-p) * (a+b)) ^ 2 / ((1-p) * (a+b))
` `px2 = chiSquareQ (x2, 1)
` `appendInfoLine: “P (chi-square) = ”, fixed$ (px2, 6)
` `=>`
`*** Binomial test 597, 403, p = 0.583333 ***
` `P (binomial) = 0.199330
` `P (chi-square) = 0.398365
`

The result is:

`*** Binomial test 597, 403, p = 0.583333 ***
` `P (binomial) = 0.199330
` `P (chi-square) = 0.398365
`

The χ2 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.

We cannot conclude from this test that people have a preference for the white keys. Of course, we cannot conclude either that people don’t have such a preference.

### Links to this page

- `binomialP`
- `invBinomialQ`
- Formulas 5. Mathematical functions
- Functions