convert_likelihood

gammapy.stats.convert_likelihood(to, probability=None, significance=None, ts=None, chi2=None, df=None)[source]

Convert between various equivalent likelihood measures.

TODO: don’t use chi2 with this function at the moment … I forgot that one also needs the number of data points to compute ts: http://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test#Calculating_the_test-statistic Probably it’s best to split this out into a separate function or just document how users should compute ts before calling this function if they have chi2.

This function uses the sf and isf methods of the norm and chi2 distributions to convert between various equivalent ways to quote a likelihood.

  • sf means “survival function”, which is the “tail probability” of the distribution and is defined as 1 - cdf, where cdf is the “cumulative distribution function”.
  • isf is the inverse survival function.

The relation between the quantities can be summarised as:

  • significance <– normal distribution —> probability
  • probability <— chi2 distribution with df —> ts
  • ts = chi2 / df

So supporting both ts and chi2 in this function is redundant, it’s kept as a convenience for users that have a ts value from a Poisson likelihood fit and users that have a chi2 value from a chi-square fit.

Parameters:

to : {‘probability’, ‘ts’, ‘significance’, ‘chi2’}

Which quantity you want to compute.

probability, significance, ts, chi2 : array_like

Input quantity value … mutually exclusive, pass exactly one!

df : array_like

Difference in number of degrees of freedom between the alternative and the null hypothesis model.

Returns:

value : numpy.ndarray

Output value as requested by the input to parameter.

Notes

TS computation

Under certain assumptions Wilk’s theorem say that the likelihood ratio TS = 2 (L_alt - L_null) has a chi-square distribution with ndf degrees of freedom in the null hypothesis case, where L_alt and L_null are the log-likelihoods in the null and alternative hypothesis and ndf is the difference in the number of freedom in those models.

Note that the cash statistic already contains the factor 2, i.e. you should compute TS as TS = cash_alt - cash_null.

Physical limits

probability is the one-sided p-value, e.g. significance=3 corresponds to probability=0.00135.

TODO: check if this gives correct coverage for cases with hard physical limits, e.g. when fitting TS of extended sources vs. point source and in half of the cases TS=0 … I suspect coverage might not be OK and we need to add an option to this function to handle those cases!

Examples

Here’s some examples how to compute the probability or significance for a given observed ts or chi2:

>>> from gammapy.stats import convert_likelihood
>>> convert_likelihood(to='probability', ts=10, df=2)
0.0067379469990854679
>>> convert_likelihood(to='significance', chi2=19, df=7)
2.4004554920435521

Here’s how to do the reverse, compute the ts or chi2 that would result in a given probability or significance.

>>> convert_likelihood(to='ts', probability=0.01, df=1)
6.6348966010212171
>>> convert_likelihood(to='chi2', significance=3, df=10)
28.78498865156606