What is Confidence Interval and how to calculate it?

Confidence Level:

The confidence level describes the uncertainty associated with a sampling method.
Suppose we used the same sampling method (say sample mean) to compute a different interval estimate for each sample. Some interval estimates would include the true population parameter and some would not.

Constructing a Confidence Interval:

Constructing a confidence interval involves 4 steps.

Step 1: Identify the sample problem. Choose the statistic (like sample mean, etc) that
you will use to estimate a population parameters.

Step 2: Select a confidence level. (Usually, it is 90%, 95% or 99%)

Step 3: Find the margin of error. (Usually given) If not given, use the following formula:-
Margin of error = Critical value * Standard deviation

Step 4: Specify the confidence interval. The uncertainty is denoted by the confidence level.
And the range of the confidence interval is defined by

where,
Sample_Statistic → Can be any kind of statistic. (eg. sample mean)
Margin_of_Error → generally, its (± 2.5)

Calculating a Confidence Interval

The calculation of CI requires two statistical parameters.

Mean (μ) — Arithmetic mean is the average of numbers. It is defined as the sum of n numbers divided by the count of numbers till n. (Eq-2)
μ = (1+2+3+…+n)/n
Standard deviation (σ) — It is the measure of how spread out the numbers are. It is defined as the summation of squared of the difference between each number and the mean. (Eq-3)
σ = √[Σ(xi - μ)^2/n]

a) Using t-distribution

We use t-distribution when the sample size n<30.

b) Using a z-distribution

We use z-distribution when the sample size n>30. Z-test is more useful when the standard deviation is known.