SoFunction
Updated on 2024-12-13

python computes two-sided confidence intervals for the t-distribution

As shown below:

interval=(a,b,mean,std)

Confidence interval for the t-distribution

a: Confidence level

b: Degree of freedom of the test quantity

mean: sample mean

std:sample standard deviation

from scipy import stats
import numpy as np
x=[10.1,10,9.8,10.5,9.7,10.1,9.9,10.2,10.3,9.9]
x1=(x)
mean=()
std=()
interval=(0.95,len(x)-1,mean,std)
interval
Out[9]: (9.531674678392644, 10.568325321607357)

Addendum: Learning Analytics with Python - t-distribution

1. The t-distribution is similar in shape to the standard normal distribution

2. The t-distribution is symmetric, has a stronger dispersion than the normal distribution, and the density profile is flatter than the standard normal distribution density profile.

3. For large samples, the difference between t-values and z-values is very small

corresponds English -ity, -ism, -ization

- The t-distribution corrects for the uncertainty of the unknown true standard deviation

- The t-distribution explicitly explains the effect of sample size in estimating the overall variance, and is a suitable distribution for any sample size to use

appliance

- Estimating the mean of a normally distributed population with unknown variance from a small sample of samples

- For any kind of sample size, the true mean sampling distribution is the t-distribution, so when in doubt, the t-distribution should be used

Effect of sample size on distribution

- The t-distribution is indistinguishable from the standard normal distribution when the sample size is between 30 and 35

- When the sample size reaches 120, the t-distribution is practically identical to the standard normal distribution

The effect of degrees of freedom df on the distribution

- The sample variance uses one estimated parameter (the mean), so the degrees of freedom of the t-distribution used in the calculation of confidence intervals are n - 1

- The t-distribution has more variance (wider confidence intervals) than the standard normal distribution due to the introduction of additional parameters (degrees of freedom df)

- Compared to the standard normal distribution curve, the smaller the degrees of freedom df, the flatter the t-distribution curve, the lower the middle of the curve, and the higher the bilateral tails of the curve are.

- The larger the degree of freedom df is, the closer the t-distribution curve is to the normal distribution curve, and when the degree of freedom df = ∞, the t-distribution curve is the standard normal distribution curve.

Chart showing t distribution

Code:

# Students with different degrees of freedom t-distribution with standard normal distribution
import numpy as np
from  import norm
from  import t
import  as plt
print('Comparing the t-distribution with the standard normal distribution')
x = ( -3, 3, 100)
(x, (x,1), label='df=1')
(x, (x,2), label='df=20')
(x, (x,100), label = 'df=100')
( x[::5], (x[::5]),'kx', label='normal')
()
()

Run results:

The above is a personal experience, I hope it can give you a reference, and I hope you can support me more. If there is any mistake or something that has not been fully considered, please do not hesitate to advise me.