Confidence Intervals - Confidence Level

# How to calculate confidence interval

## What is confidence interval

Let's continue with the example we talked about in this previous post.

Let's say you manufacture tablets (the medicine and not the electronic device, mind you.)
There is a chemical (let's call it X) in the tablet. Ideally, in each tablet, the chemical X should be 10 mg.
Every day, your plant produces 1 Lakh such tablets. So, in a month (30 days) 30 Lakh tablets have been produced.

Now, a Drug Inspector comes to your plant and asks you what is the mean or average amount of Chemical X in the entire batch of 30 Lakh tablets that was produced.

Well, you would first take some sample out of the entire batch and do some analysis on it. You can calculate the mean, standard deviation and the size of the sample.
Let's say you took a sample of 100 tablets and the mean chemical X of this 100 samples came out as 9.8 And the standard deviation came out as 2.8 Based on this analysis you would Infer about the mean of the entire population. Hence the term Inferential Statistics.
The important point to note is that you CANNOT calculate the exact mean of the entire batch (30 Lakh tablets).
It is practically not feasible to find the amount of chemical X in each of the 30 Lakh tablets and then calculating it's mean.
Hence you would answer in terms of an interval. For example, you could say to the inspecter that the population mean lies between 9.5 to 10.5 by doing some analysis on the sample taken. This interval is known as Confidence Interval.
We will see how this interval is calculated.

Even the inspector knows that calculating the exact population mean is not possible. Thus he will allow you some Margin of Error. ie. some amount of error would be acceptable to him.
Let's first see how this Margin of Error is calculated:

Margin of Error (MOE) = Z* * Sigma / Sqrt(n)
Where Sigma is the Standard Deviation, n is the sample size and Z* is the value corresponding to a particular confidence level.

Now, the Standard Deviation and n is known to you as 2.8 and 100 respectively. (You had calculated them when you took the sample of 100 tablets)

Only thing we need is Z*. So what is this Z*?

When we would be giving our answer (to the inspector) in terms of interval, we would need to specify some amout of confidence in that claim.
For example, we could say that we are 95% confident that the population mean (mean of 30 Lakh tablets) lies within the interval 9.5 to 10.5.
This 95% is our confidence level and the Z value associated with this level is your Z*.
In the next post we will see how this Z* is calculated for a given confidence level, but for now, keep in mind the following 3 frequently used Z* values for the corresponding confidence levels.

90% - 1.65
95% - 1.96
99% - 2.58

Now that we know Z*, we can find the Margin of Error by simply putting the values to the formula.
Hence, we get
1.96 * 2.8 / Sqrt(100)
= 1.96 * 0.28
= 0.54
Therefore, our Margin of Error is 0.54

Finally, the Confidence Interval is calculated as:
Sample Mean +- Margin of Error
Or,
Confidence Interval = (Sample Mean - MOE, Sample Mean + MOE)

If you recall, the sample mean (mean of the 100 tablets we took) came out as 9.8
Thus, our Confidence Interval would be
= (9.8 - 0.54, 9.8 + 0.54)
= (9.26 , 10.34)

Thus, you could answer to the inspector that the mean/average value of Chemical X in the entire population of 30 Lakh tablets lies within the range 9.26 to 10.34 and we say this with 95% confidence.