File:Chi-square distribution — test statistic below critical value.svg

Summary

Description
Polski: Rozkład χ² z zaznaczonym obszarem krytycznym (α) i statystyką testową. Statystyka (χ²_emp) leży na lewo od wartości krytycznej (c_α), poza obszarem odrzucenia. Czerwone: poziom α; niebieskie: p-value.
English: Chi-squared distribution with critical region (α) and test statistic marked. The statistic (χ²_emp) is left of the critical value (c_α), outside the rejection region. Red: α level; blue: p-value.
Date
Source Own work
Author Tomasz59

Python Code

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

# More "paper-like" style
plt.rcParams.update({
    'font.size': 18,
    'axes.titlesize': 18,
    'axes.labelsize': 16,
    'legend.fontsize': 14
})

# Parameters
alpha = 0.05
df = 10
chi2_emp = 12.1

chi2_crit = chi2.ppf(1 - alpha, df)
p_value = 1 - chi2.cdf(chi2_emp, df)

x = np.linspace(0, 30, 500)
y = chi2.pdf(x, df)

# Create figure and axes (better control than plt.figure)
fig, ax = plt.subplots(figsize=(6, 5))

# Plot
ax.plot(x, y, color='black', label=r'$\chi^2$ distribution')

# Critical region
x_alpha = x[x >= chi2_crit]
ax.fill_between(x_alpha, chi2.pdf(x_alpha, df),
                color='red', alpha=0.3, hatch='///',
                label=r'$\alpha$ (critical region)')

# p-value region
x_p = x[x >= chi2_emp]
ax.fill_between(x_p, chi2.pdf(x_p, df),
                color='blue', alpha=0.3, hatch='\\\\',
                label='p-value')

# Vertical lines
ax.axvline(chi2_crit, color='red', linestyle='--',
           label=rf'$c_{{\alpha}} = {chi2_crit:.2f}$')

ax.axvline(chi2_emp, color='blue', linestyle='--',
           label=rf'$\chi^2_{{emp}} = {chi2_emp}$')

# Title
ax.set_title(
    rf'$\chi^2$ distribution (df={df})'
    f'\n$\\alpha = {alpha}$, p-value = {p_value:.4f}'
)

# Axis labels
ax.set_xlabel(r'$\chi^2$ value')
ax.set_ylabel('Probability density')

# Legend and grid
ax.legend(loc='upper right')
ax.grid(True)

# MANUAL margins
fig.subplots_adjust(
    left=0.12,
    right=0.98,
    bottom=0.18,
    top=0.88
)

# Save as clean SVG
fig.savefig(
    "Chi-square distribution — test statistic below critical value.svg",
    format="svg",
    bbox_inches='tight',
    pad_inches=0.1
)

plt.show()
plt.close(fig)

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Category:Creative Commons Attribution-Share Alike missing SDC copyright status Category:CC-BY-SA-4.0#Chi-square%20distribution%20—%20test%20statistic%20below%20critical%20value.svg Category:Creative Commons Attribution-Share Alike 4.0 missing SDC copyright licenseCategory:Self-published workCategory:Self-published work missing SDC copyright license
Category:Chi-square distribution

[[Category:Category:Images with Python source code]]

Category:CC-BY-SA-4.0 Category:Chi-square distribution Category:Creative Commons Attribution-Share Alike 4.0 missing SDC copyright license Category:Creative Commons Attribution-Share Alike missing SDC copyright status Category:Images with Python source code Category:Self-published work Category:Self-published work missing SDC copyright license