Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Term Entry] Chi-Square Distribution #6272

Merged
merged 5 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
Title: 'Chi-Square Distribution'
Description: 'The chi-square distribution is a continuous probability distribution used primarily in hypothesis testing and confidence interval estimation.'
Subjects:
- 'Data Science'
- 'AI'
Tags:
- 'Data Distributions'
- 'Chi-Square'
- 'Statistics'
CatalogContent:
- 'learn-data-science'
- 'paths/data-science'
---

The **chi-square distribution** is derived from the sum of squared standard normal variables. It plays a crucial role in statistical tests, such as the chi-square test for independence and goodness of fit. The shape of the distribution varies with its degrees of freedom; for lower degrees of freedom, it is skewed, while higher degrees of freedom result in a more symmetric shape.

## Example

The example below demonstrates how to generate random samples from a chi-square distribution and visualize them with a [histogram](https://www.codecademy.com/learn/statistics-histograms). In this demonstration, [SciPy](https://www.codecademy.com/resources/docs/scipy) is used to generate the samples and [Matplotlib](https://www.codecademy.com/resources/docs/matplotlib) is used for plotting:

```py
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import chi2

# Set the degrees of freedom
df = 4

# Generate 1,000 random samples from the chi-square distribution
data = chi2.rvs(df, size=1000)

# Plot the histogram
plt.hist(data, bins=30, density=True, alpha=0.6, color='skyblue', edgecolor='black')
plt.title(f"Chi-Square Distribution (df={df})")
plt.xlabel("Value")
plt.ylabel("Density")
plt.show()
```

The above code generates a histogram illustrating the chi-square distribution:

![The output for the above example](https://raw.githubusercontent.com/Codecademy/docs/main/media/chi-square-distribution.png)
2 changes: 2 additions & 0 deletions documentation/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Calendar
Catch
Characters
Charts
Chi-Square
Chatbots
Cryptocurrency
Classes
Expand Down Expand Up @@ -89,6 +90,7 @@ D3
Deployment
Dart
Data
Data Distributions
Data Parallelism
Data Structures
Data Types
Expand Down
Binary file added media/chi-square-distribution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.