Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Advanced Confidence Interval Calculation with Python | Confidence Interval
Learning Statistics with Python
course content

Conteúdo do Curso

Learning Statistics with Python

Learning Statistics with Python

1. Basic Concepts
2. Mean, Median and Mode with Python
3. Variance and Standard Deviation
4. Covariance vs Correlation
5. Confidence Interval
6. Statistical Testing

bookAdvanced Confidence Interval Calculation with Python

If we are working with a small distribution (size less than or equal to 30) that approximates the normal distribution, we will use t-statistics.

How to calculate the confidence interval?

  • We use the t.interval() function from scipy.stats for the Student's T distribution.
  • As mentioned earlier, alpha represents the confidence level.
  • df stands for the number of degrees of freedom.
  • loc represents the mean.
  • sem represents the standard error of the sample.

Degrees of Freedom

Degrees of freedom are the number of independent information elements used to estimate a parameter.

The formula for degrees of freedom is N - 1, where N is the sample size.

Feel free to adjust the alpha parameter and observe the resulting changes.

1234567891011
import scipy.stats as st import numpy as np data = [104, 106, 106, 107, 107, 107, 108, 108, 108, 108, 108, 109, 109, 109, 110, 110, 111, 111, 112] # Calculate the confidence interval confidence = st.t.interval(alpha = 0.95, df = len(data)-1, loc = np.mean(data), scale = st.sem(data)) print(confidence)
copy

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 5. Capítulo 6
We're sorry to hear that something went wrong. What happened?
some-alt