3

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
dejoma
  • 394
  • 1
  • 6
  • 18
  • 4
    Possible duplicate of [Fitting empirical distribution to theoretical ones with Scipy (Python)?](https://stackoverflow.com/questions/6620471/fitting-empirical-distribution-to-theoretical-ones-with-scipy-python) – MPA May 29 '18 at 16:47
  • I use some methods of that post indeed, but the notion of loglikelihood is not mentioned there nor could I find it elsewhere on SO. – dejoma May 29 '18 at 18:41

1 Answers1

3

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267