pyyeti.stats.kdouble

pyyeti.stats.kdouble(p, c, n, tol=1e-12)[source]

Compute statistical k-factor for a double-sided tolerance interval.

Parameters:
  • p (scalar or array_like; real) – Portion of population to bound; 0 < p < 1

  • c (scalar or array_like; real) – Probability level (confidence); 0 < c < 1

  • n (scalar or array_like; integer) – Number of observations in sample; n > 1

  • tol (scalar; optional) – Error tolerance to pass to the _getr() routine

Returns:

k (scalar or ndarray; real) – The statistical k-factor for a double-sided tolerance interval.

Notes

The inputs p, c, and n must be broadcast-compatible.

The k-factor allows the computation of a tolerance interval that has the probability c of containing at least the proportion p of the population. The statistics are based on having a sample of a normally distributed population; n is the number of observations in the sample.

The bounds of the tolerance interval are calculated by:

lower = m - k std
upper = m + k std

where m is the sample mean and std is the sample standard deviation.

See references [1], [2], and [3] for the mathematical background on these tolerance limits.

References

See also

ksingle()

Examples

Assume we have 21 samples. Determine the k-factor to have a 90% probability of the interval containing 99% of the population. In other words, we need the ‘P99/90’ double-sided k-factor for N = 21. (From table: N = 21, k = 3.340)

>>> from pyyeti.stats import kdouble
>>> kdouble(.99, .90, 21)
3.3404115111514...

Make a table of double-sided k-factors using 50% confidence. The probabilities p will be: 95%, 97.725%, 99% and 99.865%. Number of samples n will be: 2-10, 1000000. Have n define the rows and p define the columns:

>>> import numpy as np
>>> from pandas import DataFrame
>>> n = [[i] for i in range(2, 11)]  # create list of lists
>>> n.append([1000000])
>>> p = [.95, .9545, .99, .9973]
>>> table = kdouble(p, .50, n)
>>> DataFrame(table, index=[i[0] for i in n], columns=p)
           0.9500    0.9545    0.9900    0.9973
2        3.502564  3.568593  4.502465  5.175585
3        2.697379  2.750060  3.498689  4.041051
4        2.456441  2.505211  3.200478  3.706120
5        2.336939  2.383750  3.052519  3.540237
6        2.264675  2.310279  2.962781  3.439587
7        2.215998  2.260775  2.902111  3.371448
8        2.180884  2.225054  2.858183  3.322030
9        2.154316  2.198021  2.824834  3.284445
10       2.133494  2.176829  2.798616  3.254847
1000000  1.959966  2.000004  2.575831  2.999979