hepstats.hypotests.core.confidence_interval module#

class hepstats.hypotests.core.confidence_interval.ConfidenceInterval(calculator, poinull, qtilde=False)[source]#

Bases: BaseTest

Class for confidence interval calculation.

Parameters:
  • calculator (BaseCalculator) – calculator to use for computing the pvalues.

  • poinull (POIarray) – parameters of interest for the null hypothesis.

  • qtilde (bool) – if True use the \(\widetilde{q}\) test statistics else (default) use the \(q\) test statistic.

Example with zfit:
>>> import numpy as np
>>> import zfit
>>> from zfit.loss import ExtendedUnbinnedNLL
>>> from zfit.minimize import Minuit
>>>
>>> bounds = (0.1, 3.0)
>>> zfit.Space('x', limits=bounds)
>>>
>>> bkg = np.random.exponential(0.5, 300)
>>> peak = np.random.normal(1.2, 0.1, 80)
>>> data = np.concatenate((bkg, peak))
>>> data = data[(data > bounds[0]) & (data < bounds[1])]
>>> N = data.size
>>> data = zfit.data.Data.from_numpy(obs=obs, array=data)
>>>
>>> mean = zfit.Parameter("mean", 1.2, 0.5, 2.0)
>>> sigma = zfit.Parameter("sigma", 0.1, 0.02, 0.2)
>>> lambda_ = zfit.Parameter("lambda", -2.0, -4.0, -1.0)
>>> Nsig = zfit.Parameter("Ns", 20., -20., N)
>>> Nbkg = zfit.Parameter("Nbkg", N, 0., N*1.1)
>>> signal = Nsig * zfit.pdf.Gauss(obs=obs, mu=mean, sigma=sigma)
>>> background = Nbkg * zfit.pdf.Exponential(obs=obs, lambda_=lambda_)
>>> loss = ExtendedUnbinnedNLL(model=signal + background, data=data)
>>>
>>> from hepstats.hypotests.calculators import AsymptoticCalculator
>>> from hepstats.hypotests import ConfidenceInterval
>>> from hepstats.hypotests.parameters import POI, POIarray
>>>
>>> calculator = AsymptoticCalculator(loss, Minuit())
>>> poinull = POIarray(mean, np.linspace(1.15, 1.26, 100))
>>> ci = ConfidenceInterval(calculator, poinull)
>>> ci.interval()
Confidence interval on mean:
    1.1810371356602791 < mean < 1.2156701172321935 at 68.0% C.L.
property qtilde: bool#

Returns True if qtilde test statistic is used, else False.

pvalues()[source]#

Returns p-values scanned for the values of the parameters of interest in the null hypothesis.

Return type:

ndarray

Returns:

Array of p-values for CLsb, CLs, expected (+/- sigma bands).

interval(alpha=0.32, printlevel=1)[source]#

Returns the confidence level on the parameter of interest.

Parameters:
  • alpha (float) – significance level.

  • printlevel (int) – if > 0 print the result.

Return type:

dict[str, float]

Returns:

Dict of the values for the central, upper and lower bounds on the parameter of interest.

property calculator#

Returns the calculator.

property poialt#

Returns the POI for the alternative hypothesis.

property poinull#

Returns the POI for the null hypothesis.