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 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 computets
before calling this function if they havechi2
.This function uses the
sf
andisf
methods of thenorm
andchi2
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 as1 - cdf
, wherecdf
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
andchi2
in this function is redundant, it’s kept as a convenience for users that have ats
value from a Poisson likelihood fit and users that have achi2
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 withndf
degrees of freedom in the null hypothesis case, whereL_alt
andL_null
are the log-likelihoods in the null and alternative hypothesis andndf
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 computeTS
asTS = 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
probability
is the one-sidedp-value
, e.g.significance=3
corresponds 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
probability
orsignificance
for a given observedts
orchi2
:>>> 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
orchi2
that would result in a givenprobability
orsignificance
.>>> convert_likelihood(to='ts', probability=0.01, df=1) 6.6348966010212171 >>> convert_likelihood(to='chi2', significance=3, df=10) 28.78498865156606