lenspack.stats module

STATS MODULE

This module contains some common statistical measures useful in weak-lensing studies. For example, the higher-order moments of filtered convergence maps can be used to constrain cosmological parameters.

lenspack.stats.mad(x)[source]

Compute median absolute deviation (MAD) of an array.

Parameters

x (array_like) – Input array.

Returns

The MAD of x.

Return type

float

lenspack.stats.skew(x)[source]

Compute the skewness of an array as the third standardized moment.

Parameters

x (array_like) – Input array. If x is multidimensional, skewness is automatically computed over all elements in the array, not just along one axis.

Returns

Skewness of x.

Return type

float

Notes

For array x, the calculation is carried out as E[((x - mu) / sigma)^3], where E() is the expectation value, mu is the mean of x, and sigma is the uncorrected sample standard deviation.

This is equivalent to
>>> n = len(x)
>>> numer = np.power(x - mu, 3).sum() / n
>>> denom = np.power(np.power(x - mu, 2).sum() / (n - 1), 3 / 2)
>>> skew = numer / denom
and to the normalized 3rd-order central moment
>>> mu_n(x, 3, normed=True)

This function’s output matches that of scipy.stats.skew exactly, but the latter is typically faster.

lenspack.stats.kurt(x, fisher=True)[source]

Compute the kurtosis of an array as the fourth standardized moment.

Parameters
  • x (array_like) – Input array. If x is multidimensional, kurtosis is automatically computed over all elements in the array, not just along one axis.

  • fisher (bool, optional) – If True, use Fisher’s normalization, i.e. subtract 3 from the result.

Returns

Kurtosis of x.

Return type

float

Notes

For array x, the calculation is carried out as E[((x - mu) / sigma)^4], where E() is the expectation value, mu is the mean of x, and sigma is the uncorrected sample standard deviation.

This is equivalent to the normalized 4th-order central moment
>>> mu_n(x, 4, normed=True) - 3

This function’s output matches that of scipy.stats.kurtosis very well, but the latter is typically faster.

lenspack.stats.mu_n(x, order, normed=False)[source]

Compute the (normalized) nth-order central moment of a distribution.

Parameters
  • x (array_like) – Input array. If x is multidimensional, the moment is automatically computed over all elements in the array, not just along one axis.

  • order (int (positive)) – Order of the moment.

  • normed (bool, optional) – If True, normalize the result by sigma^order, where sigma is the corrected sample standard deviation of x. Default is False.

Returns

Nth-order moment of x.

Return type

float

Notes

This function’s output matches that of scipy.stats.moment very well, but the latter is typically faster.

lenspack.stats.kappa_n(x, order)[source]

Compute the nth-order cumulant of a distribution.

Parameters
  • x (array_like) – Input array. If x is multidimensional, the cumulant is automatically computed over all elements in the array, not just along one axis.

  • order (int between 2 and 6, inclusive) – Order of the cumulant.

Returns

Nth-order cumulant of x.

Return type

float

Notes

This function’s output matches that of scipy.stats.kstat very well, but the latter is typically faster.

lenspack.stats.fdr(x, tail, alpha=0.05, kde=False, n_samples=10000, debug=False)[source]

Compute the false discovery rate (FDR) threshold of a distribution.

Parameters
  • x (array_like) – Samples of the distribution. If x is multidimentional, it will first be flattened.

  • tail ({'left', 'right'}) – Side of the distribution for which to compute the threshold.

  • alpha (float, optional) – Maximum average false discovery rate. Default is 0.05.

  • kde (bool, optional) – If True, compute p-values from the distribution smoothed by kernel density estimation. Not recommended for large x. Default is False.

  • n_samples (int, optional) – Number of samples to draw if using KDE. Default is 10000.

  • debug (bool, optional) – If True, print the number of detections and the final p-value. Default is False.

Returns

FDR threshold.

Return type

float

Examples

lenspack.stats.hc(x, kind=1)[source]

Compute a higher criticism statistic of a distribution.

Parameters
  • x (array_like) – Samples of the distribution. If x is multidimentional, it will first be flattened.

  • kind (int, optional) – Either 1 (HC^*) or 2 (HC^+). Default is 1.

Returns

Higher criticism of the first (*) or second (+) kind.

Return type

float

References

  • Donoho & Jin, The Annals of Statistics 32, 962 (2004)

  • Pires, Starck, Amara, et al., A&A 505, 969 (2009)

Examples