stats - Statistics¶
Introduction¶
gammapy.stats
holds statistical estimators, fit statistics and algorithms
commonly used in gamma-ray astronomy.
It is mostly concerned with the evaluation of one or several observations that count events in a given region and time window, i.e. with Poisson-distributed counts measurements.
For on-off methods we will use the following variable names following the notation in [Cousins2007]:
Variable |
Dataset attribute name |
Definition |
---|---|---|
|
|
Total observed counts in the on region |
|
|
Total observed counts in the off region |
|
|
Total expected counts in the on region |
|
|
Total expected counts in the off region |
|
|
Signal expected counts in the on region |
|
|
Background expected counts in the on region |
|
|
Relative background exposure in the on region |
|
|
Relative background exposure in the off region |
|
|
Background efficiency ratio |
|
|
Background estimate in the on region |
The following formulae show how an on-off measurement \((n_{on}, n_{off})\) is related to the quantities in the above table:
With the background estimate in the on region
the maximum likelihood estimate of a signal excess is
When the background is known and there is only an “on” region (sometimes also
called “source region”), we use the variable names n_on
, mu_on
,
mu_sig
and mu_bkg
.
These are references describing the available methods: [LiMa1983], [Cash1979], [Stewart2009], [Rolke2005], [Feldman1998], [Cousins2007].
Getting Started¶
Li & Ma Significance¶
[LiMa1983] (see equation 17)
As an example, assume you measured \(n_{on} = 18\) counts in a region where you suspect a source might be present and \(n_{off} = 97\) counts in a background control region where you assume no source is present and that is \(a_{off}/a_{on}=10\) times larger than the on-region.
Here’s how you compute the statistical significance of your detection with the Li & Ma formula:
>>> from gammapy.stats import significance_on_off
>>> significance_on_off(n_on=18, n_off=97, alpha=1. / 10, method='lima')
2.2421704424844875
Confidence Intervals¶
Assume you measured 6 counts in a Poissonian counting experiment with an expected background \(b = 3\). Here’s how you compute the 90% upper limit on the signal strength \(\mu\):
import numpy as np
from scipy import stats
import gammapy.stats as gstats
x_bins = np.arange(0, 100)
mu_bins = np.linspace(0, 50, 50 / 0.005 + 1, endpoint=True)
matrix = [stats.poisson(mu + 3).pmf(x_bins) for mu in mu_bins]
acceptance_intervals = gstats.fc_construct_acceptance_intervals_pdfs(matrix, 0.9)
LowerLimitNum, UpperLimitNum, _ = gstats.fc_get_limits(mu_bins, x_bins, acceptance_intervals)
mu_upper_limit = gstats.fc_find_limit(6, UpperLimitNum, mu_bins)
The result is mu_upper_limit == 8.465
.
Reference/API¶
gammapy.stats Package¶
Statistics.
Functions¶
|
Estimate background in the on-region from an off-region observation. |
|
Estimate standard error on background in the on region from an off-region observation. |
|
Cash statistic, for Poisson data. |
Summed cash fit statistics. |
|
|
C statistic, for Poisson data. |
|
Estimate excess in the on region for an on-off observation. |
|
Estimate error on excess for an on-off measurement. |
|
Compute excess matching a given significance. |
|
Compute sensitivity of an on-off observation. |
|
Compute excess upper limit using the Helene method. |
Convenience function that calculates the PDF for the user. |
|
Numerically choose bins a la Feldman Cousins ordering principle. |
|
|
Analytical acceptance interval for Gaussian with boundary at the origin. |
Analytical acceptance interval for Poisson process with background. |
|
|
Calculate the average upper limit for a confidence belt. |
|
Find the limit for a given x measurement. |
|
Push limits outwards as described in the FC paper. |
|
Find lower and upper limit from acceptance intervals. |
|
Goodness of fit terms for WSTAT. |
|
Background estimate |
|
Convert one-sided tail probability to significance. |
Tail probability to significance in small probability limit. |
|
|
Compute significance for an observed number of counts and known background. |
|
Compute significance of an on-off observation. |
|
Convert significance to one-sided tail probability. |
Significance to tail probability in large significance limit. |
|
|
W statistic, for Poisson data with Poisson background. |