Binomial confidence
Run a JavaScript program

Table of other contents

Introduction
Which browsers?
          Coin-toss
          McNemar’s test
Confidence interval versus p-value
Bibliography
License, revision date, and e-mail address

Introduction

The p-value used to be nearly the only form of frequentist inference used by researchers in the sciences. The confidence interval is now beginning to replace it. The present page is a calculator to calculate a two-sided confidence interval for the chance of throwing heads with a possibly unbalanced coin. This is applied to McNemar’s test.

In the following paragraphs are some examples showing use of the program. The user is respectfully invited to try out these examples or to use any others. The only thing to remember is: follow the grammatical rules of JavaScript. (This is because the “eval” method of JavaScript is used in picking up the data from the upper text area.) In particular, the user is respectfully reminded that integers beginning with a zero digit may be understood to be in base eight.

To top.

Which browsers?

Any modern Web browser can do this page, just so its JavaScript is turned on. If yours seems to be turned off, please ask for help from your classmates, children, spouse, or teacher.

To top.

Binomial confidence

          Coin-toss

Suppose that we have thrown a coin 100 times and seen 60 heads. What population probabilities of heads are not rejected using alpha equal to five percent? Please consider the following four equations:

alpha=.05;
small=1e-6;
n=100;
x=60;
I respectfully suggest that the reader select them with the mouse, copy to the clipboard, move to the upper text area, click on the “Clear” button if necessary, paste down into the upper text area, and click with the mouse on the “Binomial confidence” button. Then the lower text area will contain
From  0.4972091317176818  to  0.6967052459716796
These are the left and right boundaries of the two-sided 95% confidence interval. When I say “two-sided 95%” I mean that each boundary is a one-sided 97.5% confidence boundary. I ought to explain the “small” number. It is used by the bisection algorithm, and usually the user will not change it. The four equations may be in any of the 24 possible orders. They must obey the grammatical laws of JavaScript. Blank lines are permitted, and they have no meaning.

The reader sees that the number 0.5 is inside the confidence interval, so the coin might be equally balanced for heads and tails, but it is a close thing. Suppose now that the number of heads had been 61 instead of 60. Here are the four equations which the reader may perhaps use:

alpha=.05;
small=1e-6;
n=100;
x=61;
The answer this time will be
From  0.5073144739866258  to  0.7059896034002304
Now it looks as though the coin is not equally balanced, but again it is a close thing.

          McNemar’s test

Suppose that Smith and Johnson are running against each other to be elected governor of New Ames in the November election, and the statisticians are trying to guess who will win. Perhaps in April a random sample of ten thousand registered voters is chosen, and each is asked her/his preference, and the preference and voter’s name and address are written down with care. Then maybe in May the exact same registered voters are asked again for their preferences, and these are written down with care. Let the number of voters switching from Smith to Johnson be 290 and the number of voters switching from Johnson to Smith be 174. (We and McNemar ignore the voters who do not switch.) Then we clear out the upper text area and type into it

alpha=.05;
small=1e-6;
x=290;
n=174+290;
and click with the mouse on the “Binomial confidence” button. The program prints in the lower text area
From  0.5791876837611198  to  0.6692079789936543
and we see that 0.5 is not included in the confidence interval. We conclude that the net motion of voters really does seem to be from Smith to Johnson, with 95% confidence.

The manner of this inference was first published in McNemar (1947), which I have not seen.

To top.

Run a JavaScript program

While building this page I needed a way to run little JavaScript programs, so I constructed the “Run a JavaScript program” button. When I was done I left the button so users could practice JavaScript programming with it. If a grammatically correct JavaScript program is in the upper text area, the button will run it. Here is a trivial example:
var x=[];
for(var j=0;j<10;j++)x[j]=j;
x;
The user is respectfully invited to use the “Run a JavaScript program” button on this. The answer will be
0,1,2,3,4,5,6,7,8,9
To top.

Confidence interval versus p-value

Suppose that we toss a coin 100 times and it falls heads 100 times. We easily find the confidence interval using
alpha=.05;
small=1e-6;
n=100;
x=100;
and clicking the “Binomial confidence” button, and the answer is
From  0.9637832939624786  to  1
That looks plausible, but not especially exciting. Now let a null hypothesis say that the coin is equally balanced, heads and tails each having fifty percent probability. To find the two-sided p-value we just use
2*Math.pow( .5,100 )
and click the “Run a JavaScript program” button, and the answer is
1.5777218104420236e-30
My goodness, that looks tiny. Yet, the two inferences use the same sample. I respectfully suggest that we are being taken in by a psychological trick. We tend to think that when the p-value is divided by ten, then the strength of the inference is multiplied by ten. I would like to know the average value of 1/p assuming that the null hypothesis is true. Let us use calculus and suppose that p is distributed uniformly from zero to one. (This is not really true for coin tossing.) Let us take the integral of dp/p from p=0 to p=1. The answer is infinity.

To top.

Bibliography

McNemar, Quinn (1947). “Note on the sampling error of the difference between correlated proportions or percentages.” Psychometrika, Volume 12, pages 153-157.

To top.

License, revision date, and e-mail address

The paper by McNemar is copyrighted by the Psychometric Society. The present file, including the program, is in the public domain. The date of this revision is 6 March 2012. Criticism both constructive and destructive comes to me, Harold Kaplan,
       at     dot        
smtw2gh  gmail   com
Harold Kaplan’s statistics.htm
John C. Pezzullo’s page


To top.