pyhf.infer.mle.twice_nll#

pyhf.infer.mle.twice_nll(pars, data, pdf)[source]#

Two times the negative log-likelihood of the model parameters, (μ,θ), given the observed data. It is used in the calculation of the test statistic, tμ, as defined in Equation (8) in [1007.1727]

tμ=2lnλ(μ)

where λ(μ) is the profile likelihood ratio as defined in Equation (7)

λ(μ)=L(μ,θ^^)L(μ^,θ^).

It serves as the objective function to minimize in fit() and fixed_poi_fit().

Example

>>> import pyhf
>>> pyhf.set_backend("numpy")
>>> model = pyhf.simplemodels.uncorrelated_background(
...     signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[3.0, 7.0]
... )
>>> observations = [51, 48]
>>> data = pyhf.tensorlib.astensor(observations + model.config.auxdata)
>>> parameters = model.config.suggested_init()  # nominal parameters
>>> twice_nll = pyhf.infer.mle.twice_nll(parameters, data, model)
>>> twice_nll
array([30.77525435])
>>> -2 * model.logpdf(parameters, data) == twice_nll
array([ True])
Parameters:
  • pars (tensor) – The parameters of the HistFactory model

  • data (tensor) – The data to be considered

  • pdf (Model) – The statistical model adhering to the schema model.json

Returns:

Two times the negative log-likelihood, 2lnL(μ,θ)

Return type:

Tensor