Created:November 5, 2024
Last Updated:March 15, 2025
This calculator helps you compute the probabilities of a Chi-Square distribution given the degrees of freedom (df) and values of interest. You can find probabilities for specific ranges of the Chi-Square statistic, which is commonly used in hypothesis testing and confidence interval construction. The distribution chart shows the probability density function (PDF) of the Chi-Square distribution.
Calculator
Parameters
Interactive Distribution Chart
Click Calculate to view the distribution chart
Learn More
Chi-Square Distribution: Definition, Formula, and Applications
Chi-Square Distribution
Definition: The chi-square distribution is a probability distribution of a sum of squared standard normal random variables. It is widely used in statistical inference, particularly for tests of independence and goodness-of-fit tests.
Formula:The probability density function (PDF) is given by:
Where:
Where:
- is the degrees of freedom (shape parameter)
- is the value of the chi-square statistic
Properties
- Mean: (equals degrees of freedom)
- Variance:
- Mode:
- Support:
- Special cases:
- The sum of standard normal variables squared
- is the square of a standard normal
- For large , approaches normal distribution
How to Calculate Chi-Square Distribution in R
R
library(tidyverse)
df <- 5
# P(X < 7.5)
x_value <- 7.5
p_less_than <- pchisq(x_value, df) #0.814
print(str_glue("P(X < {x_value}) = {round(p_less_than, 4)}"))
# P(X > 7.5)
p_greater_than <- 1 - pchisq(x_value, df) #0.186
print(str_glue("P(X > {x_value}) = {round(p_greater_than, 4)}"))
# P(3 < X < 10)
a <- 3
b <- 10
p_between <- pchisq(b, df) - pchisq(a, df) # 0.6248
print(str_glue("P({a} < X < {b}) = {round(p_between, 4)}"))
# plot the chi-square distribution
x <- seq(0, 20, length.out = 1000)
chi_density <- dchisq(x, df)
plot_data <- tibble(x = x, density = chi_density)
ggplot(plot_data, aes(x = x, y = density)) +
geom_line(color = "blue") +
geom_vline(xintercept = a, linetype = "dotted", color = "darkgreen") +
geom_vline(xintercept = b, linetype = "dotted", color = "darkgreen") +
geom_vline(xintercept = x_value, linetype = "dashed", color = "blue") +
annotate("text", x = 1.5, y = max(plot_data$density) * 0.9,
label = str_glue("P(X < {x_value}) = {round(p_less_than, 4)}"), color = "blue") +
annotate("text", x = 5.5, y = max(plot_data$density) * 0.7,
label = str_glue("P({a} < X < {b}) = {round(p_between, 4)}"), color = "darkgreen") +
annotate("text", x = critical_value + 1, y = max(plot_data$density) * 0.3,
label = str_glue("Critical value = {round(critical_value, 4)}"), hjust = 0) +
labs(title = str_glue("Chi-Square Distribution (df = {df})"),
subtitle = "Probability Calculations and Critical Value",
x = "x",
y = "Probability Density") +
theme_minimal()
How to Calculate Chi-Square Distribution in Python
Python
import numpy as np
import scipy.stats as stats
import matplotlib.pyplot as plt
import pandas as pd
df = 5
# P(X < 7.5)
x_value = 7.5
p_less_than = stats.chi2.cdf(x_value, df)
print(f"P(X < {x_value}) = {p_less_than:.4f}")
# P(X > 7.5)
p_greater_than = 1 - stats.chi2.cdf(x_value, df)
print(f"P(X > {x_value}) = {p_greater_than:.4f}")
# P(3 < X < 10)
a = 3
b = 10
p_between = stats.chi2.cdf(b, df) - stats.chi2.cdf(a, df)
print(f"P({a} < X < {b}) = {p_between:.4f}")
# plot the chi-square distribution
x = np.linspace(0, 20, 1000)
chi_density = stats.chi2.pdf(x, df)
plt.figure(figsize=(12, 8))
plt.plot(x, chi_density, color="blue")
plt.axvline(x=x_value, color='blue', linestyle='--', alpha=0.7, label=f"x = {x_value}")
plt.axvline(x=a, color='green', linestyle=':', alpha=0.7, label=f"a = {a}")
plt.axvline(x=b, color='green', linestyle=':', alpha=0.7, label=f"b = {b}")
plt.annotate(f"P(X < {x_value}) = {p_less_than:.4f}",
xy=(2, max(chi_density) * 0.9),
color="blue")
plt.annotate(f"P({a} < X < {b}) = {p_between:.4f}",
xy=(5.5, max(chi_density) * 0.7),
color="green")
plt.annotate(f"P(X > {x_value}) = {p_greater_than:.4f}",
xy=(15, max(chi_density) * 0.5),
color="red")
plt.title(f"Chi-Square Distribution (df = {df}): Probability Calculations", fontsize=14)
plt.xlabel("x", fontsize=12)
plt.ylabel("Probability Density", fontsize=12)
plt.grid(True, alpha=0.3)
plt.legend(loc='upper right')
plt.tight_layout()
plt.show()