Quick reference

- Click [Simulate...] to simulate a number of faults (x)

- Drag the slide handle to the left and let the 'Right tail area' becomes approx. 0.025 and click 'Set slider value...'.

- Drag the slide handle to the right and let the 'left tail area' becomes approx. 0.025 and click 'Set slider value...'

Now a 95%-confident interval is created consisting of the two 'slider value' shown to the left.

Created confidence interval:

Correct the input!

Left tail area:

Slider value:

Set slider value as 'Upper limit'

Right tail area:

Slider value:

Set slider value as 'Lower limit'

Info, referenser, m.m...

*p*:

*n*:

*x*:

*p-hat*:

0 <

< 1

10 ≤

≤ 500

▼

▲

*p* (fault rate)

- The two red triangles on the slide indicate the true (but in reality) unknown value.

- The number over the slide handle is the calculated fault rate (x/n).

- Drag the slider to construct a double sided confidence interval for *p* (the 'fault rate').

(See also the 'Quick reference' and the various 'info'-buttons.)

14. 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 viewed as 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*
(but the rest (< 4.5% or > 13.5%) is regarded as impossible values of *p*)".

More info.
The other pages contain several concepts can be studied in more detail (use the blue 'back arrow' in upper left corner).

••••

Exercise 1 – repeated clicks on [Simulate a batch]

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 a batch] 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 a batch] 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).

(Note that the slider changes in steps of 0.0001 and therefore there can be a slight difference in the results displayed.)
Now move the slider to the right until the value "Left tail area: 0.025" is shown (use the 'right arrow'-key for the finer moves), then
click "Set slider value as 'Upper limit'". Then move the slider to the left until the value "Right tail area: 0.025" appears again but now for the
right tail. Click "Set slider value as 'Lower limit'".

The two horisontal red bars end at at the two points 0.030 and 0.166, as the calculated
interval above. The distance over the two bars thus constitutes the 95% confidence interval.
Because of this being a simulation we know the true p-value (0.10) but we hope that the interval embraces this value.

Exercise 3 – a small *p*-value

Set the *p*-value to 0.01 and *n* to 150. Click [Simulate simulate] repeatedly until *x* = 0. Then drag the slider to the right
until the left tailarea is 0.05. Click the checkbox which will show '95 %'.

Note that this time the 5 % is on one side only.

(The upper end of a 95%-confidence interval for *p* can be approximated by 3/*n*. This will here be 3/150 = 0.02 which is a very
good approximation to the result found here. A detailed explanation is 'A fairy tale' on http://www.ing-stat.se/art1.php)

**More information**

The blue arrow in upper left corner leads
to 'Ett antal fördelningar' discussing the binomial distribution in more detail.

••••

Left

When the slider is moved to the right, the 'Left tail area' becomes smaller. This area is the sum of the blue bars to the left of
the red 'x ='-value. Simultaneously the slider value is shown as the 'Slider value'.
By clicking the checkbox these values are locked.

Right

When the slider is moved to the left, the 'Right tail area' becomes smaller. This area is the sum of the blue bars to the right of
the red 'x ='-value. Simultaneously the slider value is shown as the 'Slider value'.
By clicking the checkbox these values are locked.

Confidence interval

When both checkboxes are ticked, the resulting confidence interval is calculated as

100 - (left tail area + right tail area)

This result is shown in red below. The confidence interval consitutes all possible values of the true but unknown value of the *p*-value.

••••

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 a batch] 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 a batch] 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 slider below.

See [Instructions] and [Exercises] for more info.

••••

1.
Click [Simulate a batch] 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 slider value as 'upper limit'" indicating that the value of the slider will be an upper limit of an interval.
The right part of the red interval will lock at this value.

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 slider value as 'lower limit'" indicating that the value of the slider will be a lower limit of an interval.
The left part of the red interval will lock at this value.

The red interval is called a *confidence interval* for the
unknow parameter *p* and hopefully it will enclose the true value, shown as two triangles on the slider.
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 are '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.

(Note: for *p*-values close to the extremes (0 or 1), the distribution contains fewer bars and thus the bars
are higher. However, for practical reasons, all distributions are shown equally high, even if this is incorrect.)

**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.

**The X-axis. **Note that the

In computer programs or text books

The grey distribution is based on using the simulated

••••

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

The slider is used to shift the distribution to represent possible other distributions that might have given
the simulated *x*-value.

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

The true *p*-value, used for the simulation, is shown on the screen (upper left corner) and also indicated on the slider
by two pointing small grey triangles.

When the slider is changed, a red bar follows the slider-handle. This red bar can be locked
into position using the check boxes to the left.

See also the [Instructions]-button.

••••