One-Sample T-tests
tags: #statistics/inferential/ttest/one_sample
What is a one-sample t-test?
The One Sample T-test examines whether the mean of a population is statistically different from a known or hypothesized value.
To compare the means of multiple groups to each other, use either:
- Independent Samples T-test (to compare the means of two groups)
- One-Way ANOVA (to compare the means of two or more groups).
This follows the sample assumptions and conditions as a two-sample (independent) t-test.
Hypothesis Model
The hypothesis model for a one-sample t-test for comparing the sample mean to a known or hypothesized value is:
Calculating the test statistic
For calculating the test statistic:
Running a one-sample t-test in Python
We can conduct a one-sample t-test in Python using the ttest_1samp() function from the scipy.stats library:
from scipy.stats import ttest_1samp
# conduct one-sample t-test
ttest_1samp(a, popmean, alternative="two-sided", alpha=0.05)
Parameters:
a- array-like sample of observationspopmean- hypothesized (expected) population mean (scalar)alternative- indicate whether the test should be conducted as one- or two-tailed:two-sided,less,greater
This returns the following:
(statistics, p-value)