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_topis given, grows with the OpenMP thread count (Field._determine_top), andCatalog(npatch=..., rng=...)offers no way to set it. Pinning that depth makes the centres a function of the catalogue’s positions, weights andseedalone, 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_centerstotreecorr.Catalog.- Return type:
- 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:
- 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 isFalse.
- Returns:
(chi2, reduced_chi2, pte).- Return type:
- cov_from_one_covariance(cov_one_cov, gaussian=True)[source]¶
Reshape a OneCovariance
covariance_listtable 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
Trueuse the Gaussian-only column, otherwise the Gaussian+non-Gaussian column; default isTrue.
- Returns:
Square covariance matrix.
- Return type:
- 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
kwith1 - (1 - threshold)^k = alpha.For
kindependent uniform PTEs, thealpha-quantile of their minimum is1 - (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:
objectGlobal min-PTE null-test threshold calibrated on noise-only mocks.
- mock_min_pte¶
Minimum PTE across statistics for each mock, shape
(n_mocks,).- Type:
- threshold¶
alpha-quantile ofmock_min_pte: a data vector whose minimum PTE falls below it fails the global null test at levelalpha.- Type:
- threshold_interval¶
Distribution-free interval on
thresholdat confidencelevel.
- 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 atlevel.- Return type:
- 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 PTEpas2 min(p, 1 - p)so that anomalously small statistics also fail; default isFalse.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:
Notes
The interval on the threshold uses order statistics: the number of mocks below the true
alpha-quantile isBinomial(n_mocks, alpha), and the(1 -/+ level) / 2quantiles of that count index the mocks bracketing it.