mds_2025_helper_functions.htv
Functions
|
Visualize Type I (α) and Type II (β) errors in hypothesis testing. |
Module Contents
- mds_2025_helper_functions.htv.htv(test_output, test_type='z', alpha=0.05, tail='two-tailed')[source]
Visualize Type I (α) and Type II (β) errors in hypothesis testing.
- Parameters:
test_output (dict) – Dictionary containing hypothesis test parameters: - ‘mu0’: Mean under the null hypothesis (H0) - ‘mu1’: Mean under the alternative hypothesis (H1) - ‘sigma’: Standard deviation (for z or t tests) - ‘sample_size’: Sample size (for z and t tests) - ‘df1’: Degrees of freedom 1 (for F tests, optional) - ‘df2’: Degrees of freedom 2 (for F tests, optional) - ‘df’: Degrees of freedom (for t and chi-squared tests, optional)
test_type (str) – Type of test (‘z’, ‘t’, ‘chi2’, ‘anova’).
alpha (float) – Significance level (Type I error rate).
tail (str) – One-tailed or two-tailed test (“one-tailed” or “two-tailed”).
- Returns:
(fig, ax) Matplotlib figure and axes objects.
- Return type:
tuple
Example
>>> import numpy as np >>> from mds_2025_helper_functions.htv import htv >>> >>> # Example: Visualizing a two-tailed z-test >>> test_params = { ... 'mu0': 100, # Null hypothesis mean ... 'mu1': 105, # Alternative mean ... 'sigma': 15, # Standard deviation ... 'sample_size': 30 # Sample size ... } >>> fig, ax = htv(test_params, test_type="z", alpha=0.05, tail="two-tailed") >>> plt.show()
# This will plot the null and alternative hypothesis distributions with # shaded regions for Type I and Type II errors, and mark the critical values.
>>> # Example: One-tailed t-test with degrees of freedom >>> test_params_t = { ... 'mu0': 0, ... 'mu1': 1.5, ... 'sigma': 1, ... 'sample_size': 25 ... } >>> fig, ax = htv(test_params_t, test_type="t", alpha=0.01, tail="one-tailed") >>> plt.show()
# This will plot a one-tailed t-test diagram with appropriate critical regions.