Skip to content

Foundations

Hypothesis tests from summary statistics

One-sample, two-sample (pooled and Welch) and paired t tests, the z test, and chi-square and F tests of variances, with p-values, critical values and confidence intervals.

Model id
foundations.hypothesis_tests, version 1
Domain
Foundations
Evidence
standard
Cost class
instant: A closed-form calculation; a hosted run may take up to 2 seconds.

Formula

t=xˉ−μ0s/n,ν=n−1t = \frac{\bar{x} - \mu_0}{s / \sqrt{n}}, \quad \nu = n - 1t=xˉ1−xˉ2−δ0sp1/n1+1/n2,ν=n1+n2−2t = \frac{\bar{x}_1 - \bar{x}_2 - \delta_0}{s_p \sqrt{1/n_1 + 1/n_2}}, \quad \nu = n_1 + n_2 - 2t=xˉ1−xˉ2−δ0s12/n1+s22/n2,ν=(s12/n1+s22/n2)2(s12/n1)2n1−1+(s22/n2)2n2−1t = \frac{\bar{x}_1 - \bar{x}_2 - \delta_0}{\sqrt{s_1^2/n_1 + s_2^2/n_2}}, \quad \nu = \frac{(s_1^2/n_1 + s_2^2/n_2)^2}{\frac{(s_1^2/n_1)^2}{n_1 - 1} + \frac{(s_2^2/n_2)^2}{n_2 - 1}}z=xˉ−μ0σ/nz = \frac{\bar{x} - \mu_0}{\sigma / \sqrt{n}}χ2=(n−1)s2σ02,F=s12s22\chi^2 = \frac{(n - 1) s^2}{\sigma_0^2}, \quad F = \frac{s_1^2}{s_2^2}

Where

tt
The t statistic statistic
xˉ\bar{x}
Sample mean mean
μ0\mu_0
The mean under the null hypothesis hypothesized_mean
ss
Sample standard deviation sd
nn
Sample size n
ν\nu
Degrees of freedom degrees_of_freedom
xˉ1\bar{x}_1
Mean of the first sample mean1
xˉ2\bar{x}_2
Mean of the second sample mean2
δ0\delta_0
The difference in means under the null hypothesis hypothesized_difference
sps_p
Pooled standard deviation of the two samples
n1n_1
Size of the first sample n1
n2n_2
Size of the second sample n2
s1s_1
Standard deviation of the first sample sd1
s2s_2
Standard deviation of the second sample sd2
zz
The z statistic statistic
σ\sigma
The population's known standard deviation sigma
χ2\chi^2
The chi-square statistic statistic
σ0\sigma_0
The standard deviation under the null hypothesis hypothesized_sd
FF
The F statistic statistic

Each symbol's field is named beside it; the inputs and outputs, with their units and bounds, are under Variables, and the citations give each formula's source.

Variables

Rates, returns and yields are decimals: 0.05 is five percent. Bounds in brackets include their end; in parentheses they exclude it.

Inputs

One-sample t test of a mean (one_sample_t): 7 inputs
Inputs of the calculation one_sample_t
NameDescription
AlternativealternativetextThe alternative hypothesis
Alphaalphaprobability · [0.0001, 0.5]Significance level
CalculationcalculationtextOne-sample t test of a mean
Nncount · [2, 1e+06]Sample size
Meanmeanratio · [-1e+09, 1e+09]Sample mean
Sdsdratio · [0.0001, 10000]Sample standard deviation (n - 1)
Hypothesized meanhypothesized_meanratio · [-1e+09, 1e+09]Mean under the null hypothesis
Two-sample t test of a difference in means (two_sample_t): 11 inputs
Inputs of the calculation two_sample_t
NameDescription
AlternativealternativetextThe alternative hypothesis
Alphaalphaprobability · [0.0001, 0.5]Significance level
CalculationcalculationtextTwo-sample t test of a difference in means
N1n1count · [2, 1e+06]First sample size
Mean1mean1ratio · [-1e+09, 1e+09]First sample mean
Sd1sd1ratio · [0.0001, 10000]First sample standard deviation (n - 1)
N2n2count · [2, 1e+06]Second sample size
Mean2mean2ratio · [-1e+09, 1e+09]Second sample mean
Sd2sd2ratio · [0.0001, 10000]Second sample standard deviation (n - 1)
Equal variancesequal_variancesflagPool the variances (Student); false for Welch's test
Hypothesized differencehypothesized_differenceratio · [-1e+09, 1e+09]mean1 - mean2 under the null hypothesis
Paired t test of a mean difference (paired_t): 7 inputs
Inputs of the calculation paired_t
NameDescription
AlternativealternativetextThe alternative hypothesis
Alphaalphaprobability · [0.0001, 0.5]Significance level
CalculationcalculationtextPaired t test of a mean difference
Nncount · [2, 1e+06]Number of pairs
Mean differencemean_differenceratio · [-1e+09, 1e+09]Mean of the differences
Sd differencesd_differenceratio · [0.0001, 10000]Standard deviation of the differences (n - 1)
Hypothesized differencehypothesized_differenceratio · [-1e+09, 1e+09]Mean difference under the null hypothesis
z test of a mean with known sigma (z_mean): 7 inputs
Inputs of the calculation z_mean
NameDescription
AlternativealternativetextThe alternative hypothesis
Alphaalphaprobability · [0.0001, 0.5]Significance level
Calculationcalculationtextz test of a mean with known sigma
Nncount · [1, 1e+06]Sample size
Meanmeanratio · [-1e+09, 1e+09]Sample mean
Sigmasigmaratio · [0.0001, 10000]Known population standard deviation
Hypothesized meanhypothesized_meanratio · [-1e+09, 1e+09]Mean under the null hypothesis
Chi-square test of a variance (chi_square_variance): 6 inputs
Inputs of the calculation chi_square_variance
NameDescription
AlternativealternativetextThe alternative hypothesis
Alphaalphaprobability · [0.0001, 0.5]Significance level
CalculationcalculationtextChi-square test of a variance
Nncount · [2, 1e+06]Sample size
Sdsdratio · [0.0001, 10000]Sample standard deviation (n - 1)
Hypothesized sdhypothesized_sdratio · [0.0001, 10000]Standard deviation under the null hypothesis
F test of the ratio of two variances (f_variances): 7 inputs
Inputs of the calculation f_variances
NameDescription
AlternativealternativetextThe alternative hypothesis
Alphaalphaprobability · [0.0001, 0.5]Significance level
CalculationcalculationtextF test of the ratio of two variances
N1n1count · [2, 1e+06]First sample size
Sd1sd1ratio · [0.0001, 10000]First sample standard deviation (n - 1)
N2n2count · [2, 1e+06]Second sample size
Sd2sd2ratio · [0.0001, 10000]Second sample standard deviation (n - 1)

Outputs

One-sample t test of a mean (one_sample_t): 10 outputs
Outputs of the calculation one_sample_t
NameDescription
Statisticstatisticratio · [-1e+30, 1e+30]The test statistic
P valuep_valueprobability · [0, 1]p-value for the chosen alternative
Critical valuescritical_valuesratio (array) · length min 1, max 2; each [-1e+30, 1e+30]Bounds of the rejection region: lower and upper for a two-sided test, the one bound for a one-sided test
RejectrejectflagWhether the null hypothesis is rejected at alpha
Estimateestimateratio · [-1e+30, 1e+30]Point estimate of the quantity tested
Ci lowerci_lowerratio · [-1e+30, 1e+30]Lower end of the two-sided 1 - alpha confidence interval
Ci upperci_upperratio · [-1e+30, 1e+30]Upper end of the two-sided 1 - alpha confidence interval
Standard errorstandard_errorratio · [0, 100000]Standard error of the estimate
CalculationcalculationtextOne-sample t test of a mean
Degrees of freedomdegrees_of_freedomratio · [0, 2e+06]n - 1
Two-sample t test of a difference in means (two_sample_t): 10 outputs
Outputs of the calculation two_sample_t
NameDescription
Statisticstatisticratio · [-1e+30, 1e+30]The test statistic
P valuep_valueprobability · [0, 1]p-value for the chosen alternative
Critical valuescritical_valuesratio (array) · length min 1, max 2; each [-1e+30, 1e+30]Bounds of the rejection region: lower and upper for a two-sided test, the one bound for a one-sided test
RejectrejectflagWhether the null hypothesis is rejected at alpha
Estimateestimateratio · [-1e+30, 1e+30]Point estimate of the quantity tested
Ci lowerci_lowerratio · [-1e+30, 1e+30]Lower end of the two-sided 1 - alpha confidence interval
Ci upperci_upperratio · [-1e+30, 1e+30]Upper end of the two-sided 1 - alpha confidence interval
Standard errorstandard_errorratio · [0, 100000]Standard error of the estimate
CalculationcalculationtextTwo-sample t test of a difference in means
Degrees of freedomdegrees_of_freedomratio · [0, 2e+06]n1 + n2 - 2 when pooled; Welch-Satterthwaite otherwise
Paired t test of a mean difference (paired_t): 10 outputs
Outputs of the calculation paired_t
NameDescription
Statisticstatisticratio · [-1e+30, 1e+30]The test statistic
P valuep_valueprobability · [0, 1]p-value for the chosen alternative
Critical valuescritical_valuesratio (array) · length min 1, max 2; each [-1e+30, 1e+30]Bounds of the rejection region: lower and upper for a two-sided test, the one bound for a one-sided test
RejectrejectflagWhether the null hypothesis is rejected at alpha
Estimateestimateratio · [-1e+30, 1e+30]Point estimate of the quantity tested
Ci lowerci_lowerratio · [-1e+30, 1e+30]Lower end of the two-sided 1 - alpha confidence interval
Ci upperci_upperratio · [-1e+30, 1e+30]Upper end of the two-sided 1 - alpha confidence interval
Standard errorstandard_errorratio · [0, 100000]Standard error of the estimate
CalculationcalculationtextPaired t test of a mean difference
Degrees of freedomdegrees_of_freedomratio · [0, 2e+06]n - 1
z test of a mean with known sigma (z_mean): 9 outputs
Outputs of the calculation z_mean
NameDescription
Statisticstatisticratio · [-1e+30, 1e+30]The test statistic
P valuep_valueprobability · [0, 1]p-value for the chosen alternative
Critical valuescritical_valuesratio (array) · length min 1, max 2; each [-1e+30, 1e+30]Bounds of the rejection region: lower and upper for a two-sided test, the one bound for a one-sided test
RejectrejectflagWhether the null hypothesis is rejected at alpha
Estimateestimateratio · [-1e+30, 1e+30]Point estimate of the quantity tested
Ci lowerci_lowerratio · [-1e+30, 1e+30]Lower end of the two-sided 1 - alpha confidence interval
Ci upperci_upperratio · [-1e+30, 1e+30]Upper end of the two-sided 1 - alpha confidence interval
Standard errorstandard_errorratio · [0, 100000]Standard error of the estimate
Calculationcalculationtextz test of a mean with known sigma
Chi-square test of a variance (chi_square_variance): 9 outputs
Outputs of the calculation chi_square_variance
NameDescription
Statisticstatisticratio · [-1e+30, 1e+30]The test statistic
P valuep_valueprobability · [0, 1]p-value for the chosen alternative
Critical valuescritical_valuesratio (array) · length min 1, max 2; each [-1e+30, 1e+30]Bounds of the rejection region: lower and upper for a two-sided test, the one bound for a one-sided test
RejectrejectflagWhether the null hypothesis is rejected at alpha
Estimateestimateratio · [-1e+30, 1e+30]Point estimate of the quantity tested
Ci lowerci_lowerratio · [-1e+30, 1e+30]Lower end of the two-sided 1 - alpha confidence interval
Ci upperci_upperratio · [-1e+30, 1e+30]Upper end of the two-sided 1 - alpha confidence interval
CalculationcalculationtextChi-square test of a variance
Degrees of freedomdegrees_of_freedomratio · [0, 2e+06]n - 1
F test of the ratio of two variances (f_variances): 10 outputs
Outputs of the calculation f_variances
NameDescription
Statisticstatisticratio · [-1e+30, 1e+30]The test statistic
P valuep_valueprobability · [0, 1]p-value for the chosen alternative
Critical valuescritical_valuesratio (array) · length min 1, max 2; each [-1e+30, 1e+30]Bounds of the rejection region: lower and upper for a two-sided test, the one bound for a one-sided test
RejectrejectflagWhether the null hypothesis is rejected at alpha
Estimateestimateratio · [-1e+30, 1e+30]Point estimate of the quantity tested
Ci lowerci_lowerratio · [-1e+30, 1e+30]Lower end of the two-sided 1 - alpha confidence interval
Ci upperci_upperratio · [-1e+30, 1e+30]Upper end of the two-sided 1 - alpha confidence interval
CalculationcalculationtextF test of the ratio of two variances
Df numeratordf_numeratorratio · [0, 2e+06]n1 - 1
Df denominatordf_denominatorratio · [0, 2e+06]n2 - 1

Calculator

Run the model on your own inputs, starting from its example. Rates are decimals: 0.05 is five percent. The run goes to the pyeconomics API on this site: your values travel only in the request, and nothing is stored.

Loading the calculator…

Worked example

Example mean_against_five. Inputs:

{
  "alpha": 0.05,
  "alternative": "two_sided",
  "calculation": "one_sample_t",
  "hypothesized_mean": 5,
  "mean": 9.26146,
  "n": 195,
  "sd": 0.022789
}

Outputs:

{
  "calculation": "one_sample_t",
  "ci_lower": 9.258241349743406,
  "ci_upper": 9.264678650256593,
  "critical_values": [-1.9722675325821355, 1.9722675325821355],
  "degrees_of_freedom": 194,
  "estimate": 9.26146,
  "p_value": 0,
  "reject": true,
  "standard_error": 0.0016319541864484636,
  "statistic": 2611.2620289139318
}

Assumptions

  • Samples are independent random samples; the t and z tests assume normal means, and the chi-square and F tests normal data.
  • Standard deviations are sample standard deviations with n - 1 in the denominator; sigma in the z test is known.
  • The confidence interval is always two-sided at 1 - alpha, whatever the alternative.

Limitations

  • The chi-square and F tests are sensitive to non-normal data; summary statistics cannot reveal it.
  • Welch's degrees of freedom are an approximation.
  • No correction is made for multiple comparisons.

Evidence

Status: standard. Textbook consensus, such as bond duration or the CAPM formula.

Every model declares one status: standard (textbook consensus), practitioner (a widely used convention), contested (under active debate), rejected (failed out of sample) or historical (a superseded methodology).

Syllabus

The 2027 CFA® Program's topic areas this model relates to, as factual tags. Each links to CFA Institute's page for its level; pyeconomics holds none of the curriculum's text.

Citations

  1. NIST/SEMATECH (2012). e-Handbook of Statistical Methods, section 1.3.5.2, Confidence Limits for the Mean. https://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm (Section 1.3.5.2)
  2. NIST/SEMATECH (2012). e-Handbook of Statistical Methods, section 1.3.5.3, Two-Sample t-Test for Equal Means. https://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm (Section 1.3.5.3)
  3. NIST/SEMATECH (2012). e-Handbook of Statistical Methods, section 1.3.5.8, Chi-Square Test for the Variance. https://www.itl.nist.gov/div898/handbook/eda/section3/eda358.htm (Section 1.3.5.8)
  4. NIST/SEMATECH (2012). e-Handbook of Statistical Methods, section 1.3.5.9, F-Test for Equality of Two Variances. https://www.itl.nist.gov/div898/handbook/eda/section3/eda359.htm (Section 1.3.5.9)
  5. Student (1908). The probable error of a mean. Biometrika, 6(1), 1-25. doi:10.1093/biomet/6.1.1 (The distribution of the mean over its estimated standard deviation)
  6. Welch, B. L. (1947). The generalization of 'Student's' problem when several different population variances are involved. Biometrika, 34(1-2), 28-35. doi:10.1093/biomet/34.1-2.28 (The approximate degrees of freedom of the difference of two means)

Changelog

  • Version 1: First version.

Use it elsewhere

Documentation
The model's reference page
REST API
GET or POST /v1/models/foundations.hypothesis_tests/run
MCP tool
run_model with the model's id, foundations.hypothesis_tests. Connect an assistant
Command line
pyeconomics models run foundations.hypothesis_tests --help

The worked example, from Python and from the command line:

Python
import pyeconomics

inputs = {
    "alpha": 0.05,
    "alternative": "two_sided",
    "calculation": "one_sample_t",
    "hypothesized_mean": 5,
    "mean": 9.26146,
    "n": 195,
    "sd": 0.022789,
}
result = pyeconomics.run("foundations.hypothesis_tests", inputs)
print(result.to_json())
Command line
pyeconomics models run foundations.hypothesis_tests --inputs - <<'JSON'
{
  "alpha": 0.05,
  "alternative": "two_sided",
  "calculation": "one_sample_t",
  "hypothesized_mean": 5,
  "mean": 9.26146,
  "n": 195,
  "sd": 0.022789
}
JSON