Calculating loglikelihood of distributions in Python

13,129

Solution by OP.

Python has 82 standard distributions which can be found here and in scipy.stats.distributions

Suppose you find the parameters such that the probability density function(pdf) fits the data as follows:

dist = getattr(stats.stats, 'distribution name')
params = dist.fit(data)

Then since it is a standard distribution included in the SciPy library, the pdf and logpdf can be found and used very easily in the following way:

LLH = dist.logpdf(data,*params).sum()

Note that that this corresponds to the loglikelihood function defined here.

Share:
13,129
dejoma
Author by

dejoma

c++ dev with a financial engineering background

Updated on June 05, 2022

Comments

  • dejoma
    dejoma almost 2 years

    What is an easy way to calculate the loglikelihood of any distribution fitted to data?