pythonscipystatistics

log-likelihood function generated by scipy.stats.rv_continuous.fit


The method scipy.stats.rv_continuous.fit finds the parameters that maximise a log likelihood function which is determined by the input data and the specification of the distribution rv_continuous. For instance, this could be normal or gamma.

The documentation for scipy.stats.rv_continuous.fit doesn't explain how the log-likelihood function is generated and I would like to know how. I need it so I can calculate the value of the log-likelihood at the parameters estimated by fit (i.e. the maximum value).


Solution

  • Log-likelihood is the logarithm of the probability that a given set of observations is observed given a probability distribution. You can access the value of a probability density function at a point x for your scipy.stats.rv_continuous member using scipy.stats.rv_continuous.pdf(x,params). You would take the product of these values for each member of your data, then take the log of that. For instance:

    import numpy as np
    from scipy.stats import norm
    
    data = [1,2,3,4,5]
    m,s = norm.fit(data)
    log_likelihood = np.log(np.product(norm.pdf(data,m,s)))