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 df increases

  • Values ≥ 0

Applications:

  • Chi-square tests

  • Confidence intervals for variance

  • Statistical inference


 2. Generate Chi-Square Data Using NumPy


 

Output (example):

[2.45, 3.78, 1.23, 5.67, 4.12, 2.34, 0.98, 3.45, 2.67, 4.89]
  • All values ≥ 0

  • Right-skewed distribution


 3. Visualize Chi-Square Distribution


 

  • Lower df → more skewed

  • Higher df → distribution becomes more symmetric


 4. Compare Different Degrees of Freedom


 

  • As df increases, distribution becomes more symmetric and bell-shaped


 5. Mean and Variance


  • Theoretical mean = df

  • Theoretical variance = 2 * df


🧠 Summary Table

FunctionParametersDescription
np.random.chisquare()df, sizeGenerates Chi-Square random numbers
dfDegrees of freedomDetermines shape and spread
sizeNumber of samplesOutput array size

🎯 Practice Exercises

  1. Generate 1000 Chi-Square numbers with df=3 and plot histogram with KDE.

  2. Compare Chi-Square distributions for df=2,5,8 in one plot.

  3. Compute mean and variance of generated data and compare with theoretical values.

You may also like...