P-Values, Significance, Type I/II Errors, and Power
Install and import#
npm install fintech-algorithmsimport { pValuesSignificanceTypeIIiErrorsAndPower } from "fintech-algorithms/foundations/sampling-estimation-and-statistical-inference/p-values-significance-type-i-ii-errors-and-power";Signature#
pValuesSignificanceTypeIIiErrorsAndPower(input)Turns the two-sided z statistic for input.sample against input.nullMean into a p-value, compares it with alpha, and approximates the test's power at input.alternativeMean.
Parameters#
| Name | Type | Notes |
|---|---|---|
input | D00Input | One record. sample is the observed data, nullMean is the value under the null, alternativeMean is the value power is evaluated at, and alpha is the type I error rate. estimates is validated for the whole family before dispatch.sample: non-empty list of finite numbers, at least two of them · estimates: non-empty list of finite numbers · alpha: strictly between 0 and 1 |
Returns#
D00Output
An object with pValue (two-sided, from a normal approximation), significant (true when pValue is below alpha), typeIErrorRate (echoes alpha) and powerApproximation (normal-approximation power against alternativeMean).
Errors#
- When sample or estimates is missing, empty, or contains a non-finite number — both are parsed for every topic in the family, whether or not the topic uses them — throws RangeError
- When sample holds fewer than two observations — throws RangeError
- When alpha is not strictly between zero and one — throws RangeError
Complexity: time O(n + m),
space O(n + m).
Worked example#
verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.
Input#
{
"sample": [2, 3, 4, 3, 4],
"estimates": [3, 3.1, 3.2, 3.3, 3.4],
"populationMean": 3.2,
"alpha": 0.05,
"mseBenchmark": 0.1,
"nullMean": 3,
"alternativeMean": 3.5,
"practicalThreshold": 0.1,
"comparisons": 5
}Call#
pValuesSignificanceTypeIIiErrorsAndPower(input)Returns#
object with 2 fields: pValue, significant
{
"pValue": 0.5929800980174265,
"significant": false
}Diagrams#
How it works#
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References#
- Product and Process Comparisons — NIST/SEMATECH e-Handbook
- Confidence Intervals — NIST/SEMATECH e-Handbook
- Historical-example decision