p:

n:

x:

p-hat:

0 <

< 1

10 ≤

≤ 500 p (fault rate)

Set as 'Lower limit'

Set as 'Upper limit'        Confidence interval for p – an animation

General.   This animation makes it possible to study how a so-called confidence interval is interpreted. Such an interval is commonly used in connection to analysis of data. It encompassed the true value of an unknown parameter, here the p-value.

Calculating the interval.   Most statistical softwares calculate routinely the endpoints of a confidence interval. Astonishingly, this is rather complicated for a p-value (considering that percentages are considered easy to handle). This animation does not show how an interval is calculated but concentrates on the interpretation.

Interpreting the interval.   Even if an interval is simply stated as e.g. "0.045 - 0.135" (i.e. 'the interval for p is 4.5 to 13.5%') the meaning is that "the range of p-values 0.045-0.135 cannot be ruled out as possible values of p".

••••

Exercise 1 – repeated clicks on [Simulate]
The initial parameter values are p = 0.125 and n = 200. The expected number of faulty items is thus 0.125 x 200 = 25. Repeated clicks on [Simulate] will then produce x-values around 25. (NB that the expected number needs not be an integer but the value on the X-axis is the number found, which of course is an integer.)

Exercise 2 – deriving a confidence interval
Set the two parameter values to p = 0.10 and n = 75. Click [Simulate] until x = 6 is found. When entered in a statistical software these values (x = 6 and n = 75) gives a 95% confidence interval (0.0299, 0.1660).

Now move the slide to the right until the value 'Tail area: 0.025" is shown (use the 'right arrow'-key for the finer moves), then click "Set as 'Upper limit'". Then move the slide to the left until the value 'Tail area: 0.025' appears again but now for the right tail. Click "Set as 'Lower limit'".

The two vertical arrows point at the two points 0.03 and 0.166, exactly as the calculated interval above. The distance between the two arrows thus constitutes the confidence interval. Because of this being a simulation we know the true p-value (0.10) but we see that the interval embraces this value.

www.indstat.se/simuleringar/simuleringar.php leads to 'Ett antal fördelningar' discussing the binomial distribution in more detail.

••••

There are four fields in the simulation frame – p, n, x, and p-hat. Each one is commented below. Each change of input creates a new simulation and thus a redraw of the distribution.

p:   Here you enter the p-value representing the process from which you draw data.

n:   Here you enter the number (n) of items to be inspected.

x:   After clicking [Simulate] you get x faulty items from your inspection of the batch.

p-hat:   The routine calculates this value as x/n and this is of course an estimate of the true p-value.

Each click on [Simulate] will generate a new distribution that is drawn below as a grey distribution. This is exactly as with real data – usually there is only one batch of data and you are supposed to draw conclusions about the true value of p. This is done by the slide below.

••••

1.   Click [Simulate] once. This gives x incorrect items in a batch of n items. The grey distribution is a binomial distribution with the parameters n and p-hat.

What other distributions can have given the same x-result?

2.  Pull the slider to the right creating new binomial distributions. Continue until the left tail area is, say, 0.025 (the size of the tail area is shown to the left).

3.   Click the checkbox 'Set as upper limit' indicating that the value of the slider will be an upper limit of an interval. A red arrow will point out the upper limit on the slider.

4.   Now pull the slider to the left creating even more possible binomial distributions. Continue until the right tail area also is 0.025.

5.   Click the checkbox 'Set as lower limit' indicating that the value of the slider will be a lower limit of an interval. A red arrow will point out the lower limit on the slider.

The interval between the two red arrows is called a confidence interval for the unknow parameter p. If the two tail areas are 2.5% the interval has 95% confidence of including the true value of p.

The interval thus consists of all possible distributions that could have given the x-value on the X-axis.

••••

The distribution.  The binomial distribution is a very common model. Often, but not always, it is described in 'quality terms' i.e. "number of incorrect items in a batch of n items" but this is of course not the only application. (Note that the measurements is 'number of' i.e. an integer and not a percentage or anything else.)

If you study something that can be classified in two groups like 'OK/notOK' or 'man/woman' or 'survived more than two years/not survived more than two years' then there is a ground for considering the binomial distribution as a useful model.

The parameters.  The distribution has two parameters, p and n. In quality work these are often called the fault rate and batch size.
Every grey vertical line on the X-axis shows the probability of getting just that number of faults (designated as x) in the batch. There are thus n vertical lines in the distribution. Some lines are very short and cannot be drawn.

In computer programs or text books p is often called 'success rate' and n 'number of trials'. The reason is of course that the program is neutral regarding what being analyzed and each item can be considered a 'trial'.

The grey distribution shows the simulated result (p-hat is used for drawing the distribution). When the slide is moved corresponding distributions are drawn.

••••

The slide shows p-values ('fault rates') and thus the range is 0 < p < 1.

The slide is used to shift the distribution to represent possible other distributions that might have given the x-value at hand.

This range of possible other distribution will be the confidence interval for the unknown true p-value.