relistats package

Submodules

The submodules are as follows.

relistats.binomial module

Reliability Engineering Statistics for Binomial Distributions. Also known as Bernoulli Trials.

Reference: S.M. Joshi, “Computation of Reliability Statistics for Success-Failure Experiments,” arXiv:2303.03167 [stat.ME], March 2023.

relistats.binomial.assurance(n: int, f: int, tol=0.001) float | None

Assurance [0, 1], i.e., confidence = reliability. For example, 90% assurance means 90% confidence in 90% reliability (at n=22, f=0). This method uses numerical approach of Brent’s method to compute the solution within the specified tolerance.

Parameters:
  • n (int, >=0) – number of samples

  • f (int, >=0) – number of failures

  • tol (float, optional) – accuracy tolerance

Returns:

Assurance or None if it could not be computed

Return type:

float, optional

relistats.binomial.confidence(n: int, f: int, r: float) float | None

Confidence [0, 1] in reliability r using closed-form expression.

Parameters:
  • n (int, >=0) – number of samples

  • f (int, >=0) – number of failures

  • r (float, 0 < r < 1) – reliability level

Returns:

Confidence or None if it could not be computed

Return type:

float, optional

relistats.binomial.reliability(n: int, f: int, c: float) float | None

Minimum reliability at confidence level c.

Parameters:
  • n (int, >=0) – number of samples

  • f (int, >=0) – number of failures

  • c (float, [0, 1]) – confidence level

Returns:

Reliability or None if it could not be computed

Return type:

float, optional

relistats.binomial.reliability_closed(n: int, f: int, c: float) float | None

Approximate minimum reliability [0, 1] at confidence level c. The approximation is within about 5% of actual reliability and uses closed-form expression for computation called ‘Wilson Score Interval with Continuity Correction’ [Wallis, Sean A. (2013). “Binomial confidence intervals and contingency tests: mathematical fundamentals and the evaluation of alternative methods”. Journal of Quantitative Linguistics. 20 (3): 178–208].

Parameters:
  • n (int, >=0) – number of samples

  • f (int, >=0) – number of failures

  • c (float, 0 < c <1) – confidence level

Returns:

Reliability or None if it could not be computed

Return type:

float, optional

relistats.binomial.reliability_optim(n: int, f: int, c: float, tol=0.001) float | None

Minimum reliability [0, 1] at confidence level c using numerical optimization (Brent’s method). The approximation is within specified tolerance limit.

Parameters:
  • n (int, >=0) – number of samples

  • f (int, >=0) – number of failures

  • c (float, 0 < c < 1) – confidence level

  • tol (float, optional) – accuracy tolerance

Returns:

Reliability or None if it could not be computed

Return type:

float, optional

relistats.binom_fin module

Reliability Engineering Statistics for finite population sizes with Binomial Distributions.Also known as Bernoulli Trials.

Reference: S.M. Joshi, “Computation of Reliability Statistics for finite samples of Success-Failure Experiments,” arXiv:2305.16578 [cs.IT], May 2023.

relistats.binom_fin.assur_fin(n: int, f: int, m: int) tuple

Assurance [0, 1], i.e., confidence = reliability. Returns tuple of assurance and actual values of reliability and confidence used for computations.

Parameters:
  • n (int, >=0) – number of samples

  • f (int, 0 <= f <= n) – number of failures

  • m (int, >= 0) – remaining samples in population

Returns:

(Assurance, reliability, confidence)

Return type:

tuple

relistats.binom_fin.conf_fin(n: int, f: int, m: int, d: int) tuple

Confidence [0, 1] in reliability r for finite population size. Returns tuple with second value as actual reliability used for computations.

Parameters:
  • n (int, >=0) – number of samples tested

  • f (int, >=0) – number of failures in n samples

  • m (int, >= 0) – remaining samples in population

  • d (int, >=0) – maximum number of defects in remaining m samples

Returns:

Tuple of (confidence, actual reliability)

Return type:

tuple

relistats.binom_fin.reli_fin(n: int, f: int, c: float, m: int) tuple

Minimum reliability at confidence level c for finite population size. Returns tuple with second value as actual confidence used for computations.

Parameters:
  • n (int, >=0) – number of samples

  • f (int, >=0) – number of failures

  • c (float, [0, 1]) – confidence level

  • m (int, >= 0) – remaining samples in population

Returns:

(reliability, actual confidence)

relistats.intervals module

Statistical methods for confidence and tolerance intervals.

Reference: S.M. Joshi, “Confidence and Assurance of Percentiles,” arXiv:2402.19109 [stat.ME], Feb 2024.

relistats.intervals.assurance_in_interval(j_lo: int, j_hi: int, n: int, tol=0.001) float | None

Assurance level for interval [j_lo, j_hi] out of n sorted samples. Assurance level of a means a% of samples will be within this interval with a% confidence. Example: Out of 16 ordered samples, we can be 80% confident that 80% samples will be between 1st and 15th place.

Parameters:
  • j_lo (int, >0) – sample place at lower end

  • j_hi (int, n > j_hi > j_lo) – sample place at upper end

  • n (int, >=0) – number of samples

  • tol (float, optional) – accuracy tolerance

Returns:

Assurance or None if it could not be computed

Return type:

float, optional

relistats.intervals.assurance_interval(a: float, *args) tuple[Any, Any] | None

Assurance interval for middle a fraction of samples, if possible. Same as tolerance interval for fraction a with confidence a.

Use this method if you data is not sorted already, else you can use relistats.intervals.assurance_interval_locs().

Parameters:
  • a (float, 0 < a < 1) – assurance level

  • args (array_like of type that supports computation of mean) – array of values

Returns:

assurance interval

Return type:

tuple of same type as args

relistats.intervals.assurance_interval_locs(n: int, a: float) tuple[int, int] | None

Assurance interval locations. Out of n sorted samples a fraction of a samples are expected to be within these two locations, with a probability of at least a.

Returns None if such tuple cannot be calculated. If that happens, try to increase n, or reduce a.

Parameters:
  • n (int) – number of samples

  • a (float, 0 < a < 1) – assurance level

Returns:

assurance interval locations (1-based)

Return type:

tuple of int of None

relistats.intervals.confidence_interval_of_mean(c: float, *args) tuple[Any, Any]

Confidence interval of mean of args at confidence level c.

Parameters:
  • c (float, 0 < c < 1) – confidence level

  • args (array_like of type that supports computation of mean) – array of values

Returns:

confidence interval

Return type:

tuple of same type as args

relistats.intervals.confidence_interval_of_median(c: float, *args) tuple[Any, Any] | None

Confidence interval of median of args at confidence level c.

Parameters:
  • c (float, 0 < c < 1) – confidence level

  • args (array_like of type that supports computation of mean) – array of values

Returns:

confidence interval or None

Return type:

tuple of same type as args or None

relistats.intervals.confidence_interval_of_percentile(p: float, c: float, *args) tuple[Any, Any] | None

p’th percentile/quantile interval of args at confidence level c.

Use this method if you data is not sorted already, else you can use relistats.intervals.percentile_interval_locs().

Parameters:
  • p (float, 0 < p < 1) – percentile/quantile level

  • c (float, 0 < c < 1) – confidence level

  • args (array_like of type that supports computation of mean) – array of values

Returns:

confidence interval

Return type:

tuple of same type as args

relistats.intervals.percentile_interval_locs(n: int, p: float, c: float) tuple[int, int] | None

Tuple of two locations (1…n) such that percentile/quantile p lies within these two locations of n sorted samples with confidence of at least c. Return None if such a tuple cannot be computed. If that happens, try to increase n, reduce p, or reduce c.

Note that the locations are indexed at 1 and not zero!

Use this method if you plan to sort samples yourself or you need only the locations. If your array is sorted already, you can use relistats.intervals.confidence_interval_of_percentile().

Parameters:
  • n (int) – number of samples

  • p (float, 0 < p < 1) – percentile/quantile level

  • c (float, 0 < c < 1) – confidence level

Returns:

percentile interval locations (1-based)

Return type:

tuple of int of None

relistats.intervals.tolerance_interval(t: float, c: float, *args) tuple[Any, Any] | None

Tolerance interval for middle t fraction of samples, with confidence c.

Use this method if you data is not sorted already, else you can use relistats.intervals.tolerance_interval_locs().

Parameters:
  • t (float, 0 < t < 1) – tolerance level

  • c (float, 0 < c < 1) – confidence level

  • args (array_like of type that supports computation of mean) – array of values

Returns:

tolerance interval

Return type:

tuple of same type as args

relistats.intervals.tolerance_interval_locs(n: int, t: float, c: float) tuple[int, int] | None

Tolerance interval locations. Out of n sorted samples, a fraction of t samples are expected to be within these two places, with a probability of at least c.

Returns None if such tuple cannot be calculated. If that happens, try to increase n, reduce t, or reduce c.

Parameters:
  • n (int) – number of samples

  • t (float, 0 < t < 1) – tolerance interval level

  • c (float, 0 < c < 1) – confidence level

Returns:

tolerance interval locations (1-based)

Return type:

tuple of int of None

relistats.percentile module

Statistical methods for percentiles or quantiles and tolerance interval.

Reference: S.M. Joshi, “Confidence and Assurance of Percentiles,” arXiv:2402.19109 [stat.ME], Feb 2024.

relistats.percentile.assurance_in_percentile(j: int, n: int, tol=0.001) float | None

Assurance level at j’th index out of n sorted samples. The confidence is at least the percentile/quantile level.

Parameters:
  • j (int, 1 <= j <= n) – sample index

  • n (int, >=0) – number of samples

  • tol (float, optional) – accuracy tolerance

Returns:

Assurance (0 <= a <= 1) or None if it could not be computed

Return type:

float, optional

relistats.percentile.confidence_in_percentile(j: int, n: int, p: float) float

Returns confidence (probability) that in a population of n samples, p’th percentile/quantile is greater than j samples.

From https://online.stat.psu.edu/stat415/lesson/19/19.2

\[c = \sum_{k=0}^{j-1} {n\choose k} p^k (1-p)^{n-k}\]

This is same as cumulative density function for a binomial distribution, evaluated at j-1 out of n samples.

Note that \(j=n+1\) will return 1.

Parameters:
  • j (int, 1 <= j <= n) – sample index

  • n (int, >=0) – number of samples

  • p (float 0 < p < 1) – percentile/quantile

Returns:

Confidence (0 <= c <= 1)

Return type:

float

Module contents

See submodules