Beta tail and an upper bound on a rate ​
This page defines two functions that the statistics package (statistics) does not have yet: the upper tail of a Beta distribution and the exact upper bound on a failure rate after trials without a failure. The conventions of statistics capabilities hold for both: the RangeError rules, the accuracy of a relative 1e-11, and the quantile z passed in as an argument.
Status: partly built. ruleOfThreeUpperBound and betaTailProbability exist in @agent-nexus/driftbench-stats; the other functions are planned.
Beta tail ​
The function of this section is defined in packages/stats/src/bayes.ts.
betaTailProbability ​
ts
betaTailProbability(a: number, b: number, x: number): number- Definition.
P(X > x)forXwith aBeta(a, b)distribution,aandbinteger. WithN = a + b - 1the result is the finite sumsum over j = 0 to a - 1 of C(N, j) x^j (1 - x)^(N - j). The sum is the probability that a Binomial withNtrials and ratexgives at mosta - 1successes. In the termj = 0the factorx^0is 1 for everyx, includingx = 0. All terms are non-negative, so the sum is stable. - Returns. A number in [0, 1]. It is 1 for
x = 0and 0 forx = 1. - Throws. A
RangeErrorwhenxis outside [0, 1]. ARangeErrorwhenaorbis not a whole number of at least 1. - Example.
betaTailProbability(2, 3, 0.5)is 5/16, which is 0.3125.betaTailProbability(1, 5, 0.1)is0.9^5, about 0.59049.betaTailProbability(10, 30, 0.2)is about 0.758641. - File.
packages/stats/src/bayes.ts.
Upper bound on a rate ​
The function of this section is defined in packages/stats/src/intervals.ts.
ruleOfThreeUpperBound ​
ts
ruleOfThreeUpperBound(n: number, confidence: number): number- Definition. The exact one-sided upper bound on a failure rate after
ntrials with no failure:1 - (1 - confidence)^(1/n). It is the rateUwith(1 - U)^n = 1 - confidence. The rule of three,3 / n, approximates it for a confidence of 0.95. Compute it as-expm1(log1p(-confidence) / n)so that a largendoes not lose digits to the subtraction. Forn = 1the result isconfidence. - Returns. A number in (0, 1).
- Throws. A
RangeErrorwhennis 0. ARangeErrorwhenconfidenceis not strictly between 0 and 1. - Example.
ruleOfThreeUpperBound(59, 0.95)is about 0.0495076.ruleOfThreeUpperBound(1, 0.95)is 0.95.ruleOfThreeUpperBound(1000, 0.95)is about 0.00299125. - File.
packages/stats/src/intervals.ts.