Calculate Negative loglikelihood of custom probability distribution

Hello,
I have a 1D vector, whose data are chi distributed. The Matlab built-in function negloglik expects a probability distribution object pd, which for standard distributions can be created by fitdist. Unfortunately, my chi distribution is no standard distribution and is thus not supported by fitdist.
How can I calculated the Negative loglikelihood in my special case?

 Accepted Answer

% Generate random numbers from chi distribution with k = 6
k = 6;
y = rand(150,1);
x = gammaincinv(y,k/2);
x = sqrt(2*x);
% Recover k by maximum likelihood estimate
syms k
f = prod(x.^(k-1).*exp(-x.^2/2)/(2^(k/2-1)*gamma(k/2)));
logf = log(f)
logf = 
dlogfdk = simplify(diff(logf,k))
dlogfdk = 
knum = vpasolve(dlogfdk==0,k,[0 10])
knum = 
6.2804404606724144851804043896857
negative_log_likelihood = subs(-logf,k,knum)
negative_log_likelihood = 
148.38329537359329151154663411951
k = 0:0.1:10;
Logf = matlabFunction(logf);
plot(k,-Logf(k))

6 Comments

I'm not sure about your response, as I cannot see the calculation of a negative loglikelihood. I was asking for negative loglikelihood, not for the distribution parameter k. Perhaps there's a misunderstanding. I need the negative loglikelihood value in order to compare with negative loglikelihood value of similar distributions (not chi!), in order to determine the 'best' distribution for my data based on their negative loglikelihood values.
-logf is the negative loglikelihood function.
Evaluate it at the k-value you get from the above calculation to get its minimum value (see above).
I need the negative loglikelihood value in order to compare with negative loglikelihood value of similar distributions (not chi!), in order to determine the 'best' distribution for my data based on their negative loglikelihood values.
And this is possible - comparing distributions simply by the value of the negative loglikelihood ? Do you have a link for this assertion ?
One concluding question: Beside the negative loglikelihood, is it possible to calculate the Bayesian information criterion (BIC) and the Akaike information criterion (AIC) in a similar manner? These two latter criteria are said to provide a better determination of the 'best' fitting distribution.
One concluding question:
I'm clueless in this respect - sorry.

Sign in to comment.

More Answers (1)

Torsten
Torsten on 20 Aug 2022
Edited: Torsten on 20 Aug 2022
Why don't you deduce the equation you have to solve for k by hand ?
The paragraph
Continuous distribution, continuous parameter space
under
explains in detail what to do.
I get (for comparison):
sum_{i=1}^{i=n} log(xi) - n/2*log(2) - n/2*digamma(k/2) = 0
where xi (i=1,...,n) are your measurement data.
Solve for k (e.g. using fsolve) to get the maximum likelihood estimate for the parameter.

Tags

Asked:

on 20 Aug 2022

Commented:

on 21 Aug 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!