dists#

Test statistic distributions models.

Classes:

TSD(values[, n_zero])

Trials-based representation of a test statistic distribution.

Chi2TSD(values[, n_zero, threshold])

\(\chi^2\)-fit representation of a test statistic distribution.

BinnedTSD(values[, n_zero])

Histogram-based representation of a test statistic distribution.

Functions:

ts_to_p(bg, key, ts[, fit])

Convert TS to p-values, interpolating over the background grid.

class csky.dists.TSD(values, n_zero=0, **kw)[source]#

Bases: object

Trials-based representation of a test statistic distribution.

Several methods are in the spirit of scipy.stats distribution objects, but note that at least currently, the interface is not a perfect match.

Methods:

__init__(values[, n_zero])

Construct a Chi2TSD.

sf(x[, fit])

The survival function, similar to scipy.stats distributions.

sf_nsigma(x, **kw)

The survival function, but returning a value in terms of number of sigmas.

cdf(x)

The cumulative distribution function, similar to scipy.stats distributions.

isf(p[, fit])

The inverse survival function, similar to scipy.stats distributions.

median()

The median TS value.

get_hist(**kw)

Get a histlite.Hist representation of the distribution.

__init__(values, n_zero=0, **kw)[source]#

Construct a Chi2TSD.

Parameters:
  • values (array of float or utis.Arrays) – the test statistic values

  • n_zero (int) – number of trials not contained by values for which TS=0

  • kw (mapping) – additional arguments for scipy.stats.chi2.fit. By default, if loc and floc are not set, then floc=0 will be used; if scale and fscale are not set, then fscale=1 will be used.

sf(x, fit=False)[source]#

The survival function, similar to scipy.stats distributions.

sf_nsigma(x, **kw)[source]#

The survival function, but returning a value in terms of number of sigmas.

cdf(x)[source]#

The cumulative distribution function, similar to scipy.stats distributions.

isf(p, fit=False)[source]#

The inverse survival function, similar to scipy.stats distributions.

median()[source]#

The median TS value.

get_hist(**kw)[source]#

Get a histlite.Hist representation of the distribution.

class csky.dists.Chi2TSD(values, n_zero=0, threshold=0, **kw)[source]#

Bases: TSD

\(\chi^2\)-fit representation of a test statistic distribution.

Information about trials is retained, and a chi2 fit is applied to the region TS > 0.

Methods:

__init__(values[, n_zero, threshold])

Construct a Chi2TSD.

sf(x[, fit])

The survival function, similar to scipy.stats distributions.

cdf(x[, fit])

The cumulative distribution function, similar to scipy.stats distributions.

isf(p[, fit])

The inverse survival function, similar to scipy.stats distributions.

median([fit])

The median TS value.

get_hist(**kw)

Get a histlite.Hist representation of the distribution.

sf_nsigma(x, **kw)

The survival function, but returning a value in terms of number of sigmas.

Attributes:

chi2

The fitted scipy.stats.chi2 object.

__init__(values, n_zero=0, threshold=0, **kw)[source]#

Construct a Chi2TSD.

Parameters:
  • values (array of float or utis.Arrays) – the test statistic values

  • n_zero (int) – number of trials not contained by values for which TS=0

  • kw (mapping) – additional arguments for scipy.stats.chi2.fit. By default, if loc and floc are not set, then floc=0 will be used; if scale and fscale are not set, then fscale=1 will be used.

property chi2#

The fitted scipy.stats.chi2 object.

sf(x, fit=True)[source]#

The survival function, similar to scipy.stats distributions.

cdf(x, fit=True)[source]#

The cumulative distribution function, similar to scipy.stats distributions.

isf(p, fit=True)[source]#

The inverse survival function, similar to scipy.stats distributions.

median(fit=False)[source]#

The median TS value.

get_hist(**kw)#

Get a histlite.Hist representation of the distribution.

sf_nsigma(x, **kw)#

The survival function, but returning a value in terms of number of sigmas.

class csky.dists.BinnedTSD(values, n_zero=0, **kw)[source]#

Bases: TSD

Histogram-based representation of a test statistic distribution.

This class tries to reproduce the behavior of TSD without storing information about every single trial, thereby reducing RAM and disk space requirements.

Methods:

__init__(values[, n_zero])

Construct a Chi2TSD.

median()

The median TS value.

sf(x[, fit])

The survival function, similar to scipy.stats distributions.

cdf(x[, fit])

The cumulative distribution function, similar to scipy.stats distributions.

get_hist(**kw)

Get a histlite.Hist representation of the distribution.

isf(p[, fit])

The inverse survival function, similar to scipy.stats distributions.

sf_nsigma(x, **kw)

The survival function, but returning a value in terms of number of sigmas.

__init__(values, n_zero=0, **kw)[source]#

Construct a Chi2TSD.

Parameters:
  • values (array of float or utis.Arrays) – the test statistic values

  • n_zero (int) – number of trials not contained by values for which TS=0

  • kw (mapping) – additional arguments for scipy.stats.chi2.fit. By default, if loc and floc are not set, then floc=0 will be used; if scale and fscale are not set, then fscale=1 will be used.

median()[source]#

The median TS value.

sf(x, fit=True)[source]#

The survival function, similar to scipy.stats distributions.

cdf(x, fit=True)[source]#

The cumulative distribution function, similar to scipy.stats distributions.

get_hist(**kw)#

Get a histlite.Hist representation of the distribution.

isf(p, fit=True)[source]#

The inverse survival function, similar to scipy.stats distributions.

sf_nsigma(x, **kw)#

The survival function, but returning a value in terms of number of sigmas.

csky.dists.ts_to_p(bg, key, ts, fit=True)[source]#

Convert TS to p-values, interpolating over the background grid.

Parameters:
  • bg (dict) – the background distributions

  • key (array of float) – the values that indicate where along the background parameterization each TS value originates from

  • fit (bool) – whether to request sf(ts_value, fit=True)