# pyhf.infer.mle.twice_nll

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

Two times the negative log-likelihood of the model parameters, $$\left(\mu, \boldsymbol{\theta}\right)$$, given the observed data. It is used in the calculation of the test statistic, $$t_{\mu}$$, as defined in Equation (8) in [1007.1727]

$t_{\mu} = -2\ln\lambda\left(\mu\right)$

where $$\lambda\left(\mu\right)$$ is the profile likelihood ratio as defined in Equation (7)

$\lambda\left(\mu\right) = \frac{L\left(\mu, \hat{\hat{\boldsymbol{\theta}}}\right)}{L\left(\hat{\mu}, \hat{\boldsymbol{\theta}}\right)}\,.$

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, $$-2\ln L\left(\mu, \boldsymbol{\theta}\right)$$

Return type:

Tensor