irfpy.util.likelihood

Functions for likelihood.

Code author: Yoshifumi Futaana

log_likelihood_normal(observed, predicted)

Return the log likelihood for normal distribution.

log_likelihood_poisson(observed, predicted)

Return the log likelihood for poisson statistics

For details about likelihood, see http://en.wikipedia.org/wiki/Likelihood_function

irfpy.util.likelihood.log_likelihood_normal(observed, predicted)[source]

Return the log likelihood for normal distribution.

The log-likelihood for normal distribution is calculated from

\[\log L = -\sum (y_o - y_p)^2\]

where yo is the observed values and yp is the predicted values. The standard deviation of the normal distribution is assumed constant over each observed value.

Normally, predicted values are derived from some parametric function, and therefore the likelihood is a function of the parameters.

Parameters:
  • observed – Observed value as np.array

  • predicted – Predicted value as np.array

Returns:

Log likelihood under normal distribution.

>>> observed = [3, 2, 3, 4, 6, 2, 1]
>>> predicted = [1.8, 2.2, 3.4, 4.6, 6.7, 5.1, 3.2]
>>> print('{:.3f}'.format(log_likelihood_normal(observed, predicted)))
-16.940
irfpy.util.likelihood.log_likelihood_poisson(observed, predicted)[source]

Return the log likelihood for poisson statistics

The log likelihood for Poisson distribution is calculated from

\[\log L = (y_o \times \ln y_p - y_p)\]

where yo is the observed values (thus, integer, for Poisson distribution) and yp is the predicted values (usually, float). Normally, predicted values are derived from some parametric function, and therefore the likelihood is a function of the parameters.

Parameters:
  • observed – Observed value as np.array

  • predicted – Predicted value as np.array

Returns:

Log likelihood under Poisson distribution.

>>> observed = [3, 2, 3, 4, 6, 2, 1]
>>> predicted = [1.8, 2.2, 3.4, 4.6, 6.7, 5.1, 3.2]
>>> print('{:.3f}'.format(log_likelihood_poisson(observed, predicted)))
1.950
irfpy.util.likelihood.aic(number_of_parameter, log_likelihood)[source]

Return the AIC value

The AIC (https://en.wikipedia.org/wiki/Akaike_information_criterion) is calculated and returned.

\[AIC = 2 k - 2 \ln(L)\]

If your observations are

>>> observed = [3, 2, 3, 4, 6, 2, 1]

and the best fitted values are

>>> predicted = [1.8, 2.2, 3.4, 4.6, 6.7, 5.1, 3.2]

the log-likelihood calculate from Poisson distribution is obtained as

>>> print('{:.3f}'.format(log_likelihood_poisson(observed, predicted)))
1.950

Then, if the number of parameters used for the best fitted values are 3, the AIC is simply obtained as

>>> print('{:.3f}'.format(aic(3, log_likelihood_poisson(observed, predicted))))
2.100