How do I Define Zero Truncated distribution to find MLEs And How do I Calculate Loglikelihood value

Dear Support,
I needed an urgent help to work on my thesis project.
Could someone please help me out with Log-likelihood Calculations by MATLAB for the Lognormal, Gamma and Weibull distributions. Also, for Poisson and Negative Binomial.
I need your assistance very very urgently.
I just started using the matlab and finding it difficult defining the loglikelihood function and calculating the Negative Loglikelihood values.
I am able to find the Maximum Likelihood Estimates for the distribution with MATLAB. But having difficulty with the Loglikelihood value calculation. This value will enable me select best model.
Also, how to indicate that in the code that the random variable(claim amounts) starts from say, 2000 upwards.
I defined X = (Claims) where claims is a one dimensional array of data eg. nx1 vector.
Much thanks in advance.
Silas

 Accepted Answer

You ask a number of questions. Here are two answers. You ask how to compute the negative log likelihood. If you have the Statistics Toolbox and you are fitting a probability distribution, here's how to compute the negative log likelihood for the Poisson distribution. Note that it is smaller (likelihood is larger) at the mle than at a different value.
>> x = poissrnd(3,1000,1);
>> m = poissfit(x)
m =
2.9660
>> negloglik = -sum(log(poisspdf(x,m)))
negloglik =
1.9322e+03
>> negloglik = -sum(log(poisspdf(x,m+.1)))
negloglik =
1.9338e+03
You ask about a zero truncated distribution. Here I define a Poisson distribution truncated to exclude the zero value. Then I use the mle function to fit this to the same sample as above but with zero excluded.
>> ztpdf = @(x,m) (x>0).*poisspdf(x,m)./(1-poisspdf(0,m));
>> mle(x(x>0),'pdf',ztpdf,'start',1)
ans =
2.9678

4 Comments

Hi Tom, Much thanks for your promptness. However, I would like to seek few clarifications. 1. In trying to generate random poisson numbers, what is the meaning of 3 and 1 in poissrnd(3, 1000,1). I suppose 1000 means resampling 1000 times. 2. Since I already have my data, do I need to generate random number again? 3. in the equation, negloglik = -sum(log(poisspdf(x,m+.1))) why is the .1 added to m?
4. Can you please work on the other issues Gamma and Lognormal for me.
Thank you very much.
Silas
I generated data to compute the likelihood for it. You are right that you don't need to do that if you have data. The 3 is the Poisson mean that I used, and [1000,1] is the size of the result.
I added .1 in order to demonstrate that the result is smaller (likelihood is larger) at the mle than at a different value.
Try "help lognpdf" and "help gampdf". Or type "help pdf".

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!