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
chi2with this function at the moment … I forgot that one also needs the number of data points to computets: 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 computetsbefore calling this function if they havechi2.This function uses the
sfandisfmethods of thenormandchi2distributions to convert between various equivalent ways to quote a likelihood.sfmeans “survival function”, which is the “tail probability” of the distribution and is defined as1 - cdf, wherecdfis the “cumulative distribution function”.isfis 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
tsandchi2in this function is redundant, it’s kept as a convenience for users that have atsvalue from a Poisson likelihood fit and users that have achi2value 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.ndarrayOutput value as requested by the input
toparameter.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 withndfdegrees of freedom in the null hypothesis case, whereL_altandL_nullare the log-likelihoods in the null and alternative hypothesis andndfis the difference in the number of freedom in those models.Note that the
cashstatistic already contains the factor 2, i.e. you should computeTSasTS = cash_alt - cash_null.- https://en.wikipedia.org/wiki/Chi-squared_distribution
- http://docs.scipy.org/doc/scipy-dev/reference/generated/scipy.stats.chi2.html
- https://en.wikipedia.org/wiki/Likelihood-ratio_test
- https://adsabs.harvard.edu/abs/1979ApJ…228..939C
- https://adsabs.harvard.edu/abs/2009A%26A…495..989S
Physical limits
probabilityis the one-sidedp-value, e.g.significance=3corresponds toprobability=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
probabilityorsignificancefor a given observedtsorchi2:>>> 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
tsorchi2that would result in a givenprobabilityorsignificance.>>> convert_likelihood(to='ts', probability=0.01, df=1) 6.6348966010212171 >>> convert_likelihood(to='chi2', significance=3, df=10) 28.78498865156606