uvex_transients.utils.stat_utils.tolerance_rank#

uvex_transients.utils.stat_utils.tolerance_rank(n_samples: int, confidence: float, tolerance: float) → int[source]#

Find the rank of the sample value that is the tightest valid upper tolerance limit (Wilks 1941).

The r-th largest of M samples leaves at most a fraction \(\delta\) of the population above it with confidence \(P[\mathrm{Binomial}(M, \delta)\geq r]\). This returns the largest r for which that still reaches the required confidence.

Parameters:
  • n_samples (int) – Number of samples, M.

  • confidence (float) – Required confidence, in (0, 1).

  • tolerance (float) – Largest allowed fraction of the population beyond the limit, in (0, 1).

Returns:

The rank r >= 1, counted from the largest sample.

Return type:

int

Raises:

ValueError – If n_samples is below tolerance_min_samples.