scipy.stats.Normal.

llf#

Normal.llf(sample, /, *, axis=-1)[source]#

Log-likelihood function

Given a sample \(x\), the log-likelihood function (LLF) is the logarithm of the joint probability density of the observed data. It is typically viewed as a function of the parameters \(\theta\) of a statistical distribution:

\[\mathcal{L}(\theta | x) = \log \left( \prod_i f_\theta(x_i) \right) = \sum_{i} \log(f_\theta(x_i))\]

where \(f_\theta\) is the probability density function with parameters \(\theta\).

As a method of ContinuousDistribution, the parameter values are specified during instantiation; llf accepts only the sample \(x\) as sample.

Parameters:
samplearray_like

The given sample for which to calculate the LLF.

axisint or tuple of ints

The axis over which the reducing operation (sum of logarithms) is performed.

Notes

The LLF is often viewed as a function of the parameters with the sample fixed; see the Notes for an example of a function with this signature.

References

[1]

Likelihood function, Wikipedia, https://en.wikipedia.org/wiki/Likelihood_function

Examples

Instantiate a distribution with the desired parameters:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy import stats
>>> X = stats.Normal(mu=0., sigma=1.)

Evaluate the LLF with the given sample:

>>> sample = [1., 2., 3.]
>>> X.llf(sample)
-9.756815599614018
>>> np.allclose(X.llf(sample), np.sum(X.logpdf(sample)))
True

To generate a function that accepts only the parameters and holds the data fixed:

>>> def llf(mu, sigma):
...     return stats.Normal(mu=mu, sigma=sigma).llf(sample)
>>> llf(0., 1.)
-9.756815599614018