sp_validation.statistics

STATISTICS.

Name:

statistics.py

Description:

Cosmology-independent statistical helpers (jackknife resampling, jackknife patch centres, chi2/PTE, calibrated min-PTE across many null tests, covariance<->correlation, OneCovariance reshaping).

PATCH_MIN_TOP = 6

Depth of the ball-tree layers that seed the jackknife k-means.

jackknife_patch_centers(cat, npatch, seed=0, init='tree')[source]

Seeded k-means jackknife patch centres for a TreeCorr catalogue.

Seeding the k-means does not by itself fix the patches. TreeCorr starts the k-means from the top layers of a ball tree whose depth, unless min_top is given, grows with the OpenMP thread count (Field._determine_top), and Catalog(npatch=..., rng=...) offers no way to set it. Pinning that depth makes the centres a function of the catalogue’s positions, weights and seed alone, on every machine.

Parameters:
  • cat (treecorr.Catalog) – Catalogue with spherical (RA, Dec) positions.

  • npatch (int) – Number of patches.

  • seed (int, optional) – Seed for the k-means initialisation.

  • init (str, optional) – TreeCorr initialisation method. Use kmeans++ for draws that sample different seeded starting centres rather than the same tree cells.

Returns:

Patch centres, to pass as patch_centers to treecorr.Catalog.

Return type:

numpy.ndarray

jackknif_weighted_average2(data, weights, remove_size=0.1, n_realization=100)[source]

Add docstring.

…

corr_from_cov(cov)[source]

Correlation matrix from a covariance matrix.

Parameters:

cov (numpy.ndarray) – Covariance matrix.

Returns:

Correlation matrix.

Return type:

numpy.ndarray

chi2_and_pte(data_vector, cov, verbose=False)[source]

Chi-squared, reduced chi-squared and PTE for a data vector.

The data vector is assumed to be zero-mean under the null hypothesis, so chi2 = d^T C^-1 d.

Parameters:
  • data_vector (numpy.ndarray) – Data vector.

  • cov (numpy.ndarray) – Covariance matrix of the data vector.

  • verbose (bool, optional) – If True, print the statistics; default is False.

Returns:

(chi2, reduced_chi2, pte).

Return type:

tuple

cov_from_one_covariance(cov_one_cov, gaussian=True)[source]

Reshape a OneCovariance covariance_list table into a matrix.

Parameters:
  • cov_one_cov (numpy.ndarray) – Flat OneCovariance output (e.g. from covariance_list_..._Cell.dat), with one row per (i, j) element pair.

  • gaussian (bool, optional) – If True use the Gaussian-only column, otherwise the Gaussian+non-Gaussian column; default is True.

Returns:

Square covariance matrix.

Return type:

numpy.ndarray

_min_pte(ptes, two_sided)[source]

Minimum PTE across the last axis, optionally two-sided.

wilson_interval(count, n, level=0.68)[source]

Two-sided Wilson score interval for a binomial fraction count / n.

effective_number_of_tests(threshold, alpha)[source]

Number of independent tests k with 1 - (1 - threshold)^k = alpha.

For k independent uniform PTEs, the alpha-quantile of their minimum is 1 - (1 - alpha)^(1/k); inverting that for a calibrated threshold gives the effective number of independent tests it corresponds to.

class MinPTECalibration(alpha: float, two_sided: bool, mock_min_pte: ndarray, threshold: float, threshold_interval: tuple, k_eff: float, k_eff_interval: tuple, level: float)[source]

Bases: object

Global min-PTE null-test threshold calibrated on noise-only mocks.

alpha

Global false-positive rate the threshold is calibrated to.

Type:

float

two_sided

Whether each PTE p entered as 2 min(p, 1 - p).

Type:

bool

mock_min_pte

Minimum PTE across statistics for each mock, shape (n_mocks,).

Type:

numpy.ndarray

threshold

alpha-quantile of mock_min_pte: a data vector whose minimum PTE falls below it fails the global null test at level alpha.

Type:

float

threshold_interval

Distribution-free interval on threshold at confidence level.

Type:

tuple of float

k_eff

Effective number of independent tests implied by threshold.

Type:

float

k_eff_interval

k_eff mapped from threshold_interval.

Type:

tuple of float

level

Confidence level of the intervals.

Type:

float

alpha: float
two_sided: bool
mock_min_pte: ndarray
threshold: float
threshold_interval: tuple
k_eff: float
k_eff_interval: tuple
level: float
property n_mocks

Number of mocks the calibration rests on.

global_pte(data_ptes)[source]

Global p-value of a data vector’s PTEs against the mocks.

Parameters:

data_ptes (array_like) – The data’s PTE for each statistic, ordered as the mock columns.

Returns:

(p, interval): the fraction of mocks whose minimum PTE is at most the data’s, and its Wilson interval at level.

Return type:

tuple

calibrate_min_pte(mock_ptes, alpha=0.05, two_sided=False, level=0.68)[source]

Calibrate a global threshold on the minimum PTE across statistics.

Testing many correlated statistics at a fixed per-test level inflates the false-positive rate by an unknown amount. Taking the minimum PTE across statistics for each noise-only mock and reading off its alpha-quantile gives a threshold with exactly that global rate, whatever the correlations between statistics and whatever miscalibration of the individual PTEs.

Parameters:
  • mock_ptes (array_like) – PTEs of noise-only realisations, shape (n_mocks, n_stats); the columns can be any statistics, redshift-bin pairs or scale cuts.

  • alpha (float, optional) – Global false-positive rate; default is 0.05.

  • two_sided (bool, optional) – If True, test each PTE p as 2 min(p, 1 - p) so that anomalously small statistics also fail; default is False.

  • level (float, optional) – Confidence level of the reported intervals; default is 0.68.

Returns:

The threshold, its interval, the effective number of independent tests, and MinPTECalibration.global_pte() for the data.

Return type:

MinPTECalibration

Notes

The interval on the threshold uses order statistics: the number of mocks below the true alpha-quantile is Binomial(n_mocks, alpha), and the (1 -/+ level) / 2 quantiles of that count index the mocks bracketing it.