Introduction
Sometimes the raw data never reaches you — only a published mean, standard deviation, and sample size from a report or paper. TTestOfMeanFromStats lets you test that summarized mean against a hypothesized value without needing the underlying observations: it automatically picks a t-test for small samples (n < 30) or a z-test for larger ones, computes the test statistic and p-value, and plots the simulated sampling distribution against the hypothesized mean so the result is visually as well as numerically clear.
Teaching Note
A hypothesis test of a mean from statistics is essential for:
- Validating experimental results from summarized research papers
- Testing quality control standards when only summary data is available
- High-level benchmarking against industry or historical averages
- Financial auditing and anomaly detection in aggregate data
- Performance evaluation based on reported mean metrics
- Scenario planning and sensitivity analysis for projected means
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
sample_meanrequired | | — | The mean value calculated from the sample data. |
sample_sdrequired | | — | The standard deviation of the sample data. |
sample_sizerequired | | — | The number of observations in the sample (n). If n < 30, a t-distribution is used; otherwise, a normal distribution is assumed. |
hypothesized_meanrequired | | — | The population mean value to test against (null hypothesis value). |
alternative_hypothesis | | 'two-sided' | Defines the alternative hypothesis for the test. Must be one of 'two-sided', 'less', or 'greater'. Defaults to 'two-sided'. |
confidence_interval | | 0.95 | The confidence level used to determine statistical significance (e.g., 0.95 for a 5% significance level). Defaults to 0.95. |
plot_sample_distribution | | True | If True, displays a histogram showing the distribution of simulated sample means relative to the hypothesized value. Defaults to True. |
value_name | | 'Value' | Descriptive name for the value being tested, used as the x-axis label in the visualization. Defaults to 'Value'. |
fill_color | | '#999999' | Hex color code or name for the distribution plot bars. Defaults to '#999999'. |
fill_transparency | | 0.6 | Transparency level (alpha) for the plot bars, ranging from 0 to 1. Defaults to 0.6. |
title_for_plot | | 'Hypothesis Test of a Mean' | Main title text to display at the top of the plot. Defaults to 'Hypothesis Test of a Mean'. |
subtitle_for_plot | | 'Shows the distribution of the sample mean and the hypothesized mean.' | Subtitle text to display below the main title. |
caption_for_plot | | None | Caption text displayed at the bottom of the plot. Defaults to None. |
data_source_for_plot | | None | Optional text identifying the data source, displayed in the caption area. Defaults to None. |
show_y_axis | | False | If True, displays the y-axis (frequency scale) on the distribution plot. Defaults to False. |
title_y_indent | | 1.1 | Vertical position for the main title relative to the axes. Defaults to 1.10. |
subtitle_y_indent | | 1.05 | Vertical position for the subtitle relative to the axes. Defaults to 1.05. |
caption_y_indent | | -0.15 | Vertical position for the caption relative to the axes. Defaults to -0.15. |
figure_size | | (8, 6) | Tuple specifying the (width, height) of the figure in inches. Defaults to (8, 6). |
Returns
A float — the calculated test statistic (t-score or z-score, depending on sample size).
Example
python
from analysistoolbox.hypothesis_testing import TTestOfMeanFromStats
# Test if a reported sample mean of 52 differs from a hypothesized 50
test_stat = TTestOfMeanFromStats(
sample_mean=52.0,
sample_sd=5.0,
sample_size=35,
hypothesized_mean=50.0
)