Chi Square Distribution
📊 Chi-Square (χ²) Distribution in Python
Chi Square Distribution is widely used in statistics, especially for hypothesis testing, goodness-of-fit tests, and variance analysis. It describes the distribution of a sum of squared independent standard normal variables.
1. Characteristics
Continuous probability distribution
Parameter:
df→ degrees of freedom (number of squared standard normal variables summed)PDF (Probability Density Function) is right-skewed, more symmetric as
dfincreasesValues ≥ 0
Applications:
Chi-square tests
Confidence intervals for variance
Statistical inference
2. Generate Chi-Square Data Using NumPy
Output (example):
All values ≥ 0
Right-skewed distribution
3. Visualize Chi-Square Distribution
Lower
df→ more skewedHigher
df→ distribution becomes more symmetric
4. Compare Different Degrees of Freedom
As
dfincreases, distribution becomes more symmetric and bell-shaped
5. Mean and Variance
Theoretical mean =
dfTheoretical variance =
2 * df
🧠 Summary Table
| Function | Parameters | Description |
|---|---|---|
np.random.chisquare() | df, size | Generates Chi-Square random numbers |
df | Degrees of freedom | Determines shape and spread |
size | Number of samples | Output array size |
🎯 Practice Exercises
Generate 1000 Chi-Square numbers with
df=3and plot histogram with KDE.Compare Chi-Square distributions for
df=2,5,8in one plot.Compute mean and variance of generated data and compare with theoretical values.
