I have some data and I can fit a gamma distribution using for example this code taken from Fitting a gamma distribution with (python) Scipy .
import scipy.stats as ss
import scipy as sp
Generate some gamma data:
alpha=5
loc=100.5
beta=22
data=ss.gamma.rvs(alpha,loc=loc,scale=beta,size=10000)
print(data)
# [ 202.36035683 297.23906376 249.53831795 ..., 271.85204096 180.75026301
# 364.60240242]
Here we fit the data to the gamma distribution:
fit_alpha,fit_loc,fit_beta=ss.gamma.fit(data)
print(fit_alpha,fit_loc,fit_beta)
# (5.0833692504230008, 100.08697963283467, 21.739518937816108)
print(alpha,loc,beta)
# (5, 100.5, 22)
I can also fit an exponential distribution to the same data. I would however like to do a likelihood ratio test. To do this I don't just need to fit the distributions but I also need to return the likelihood. How can you do that in python?