How do I use MLE on a shifted gamma distribution?

조회 수: 5 (최근 30일)
Pat
Pat 2012년 9월 11일
댓글: Peter Perkins 2014년 12월 8일
First the Matlab documentation on using the built in distributions is great. I've successfully used gampdf to fit distributions using MLE. However, I would now like to use a custom distribution and I'm running into problems. Error messages such as the "...function returns negative or zero values" are very common when working through. I tried looking at gampdf.m but there's a lot of code in that function: example what is the scaling factor z=x./b?
here is my function below just to start off, any help getting this to work with MLE (in error free form) would be greatly appreciated. Thanks in advance.
function y=mygampdf(x,alpha,beta,x1)
%
% Y = MYGAMPDF(X,ALPHA,BETA,XI);
% This is a shifted gamma function along the x-axis to the right using the
% term XI. All other factors are the same as the usual gamma distribution
% in gampdf.m
for i=1:length(x)
y(i)=0;
end
y=(1/(beta^alpha*gamma(alpha))).*(x-x1).^(alpha-1).*exp(-1.0.*(x-x1)./beta);
end

채택된 답변

Peter Perkins
Peter Perkins 2012년 9월 11일
Pat, thresholded distributions are typically not easy to fit by maximum likelihood. I am not sure of the details for a 3-param gamma, there may be literature specifically dealing with this, I don't know. But for a 3-param lognormal, the MLE is unbounded and in effect estimates the threshold parameter at the smallest observation and the variance parameter at zero, while for the 3-param Weibull, the MLE is unbounded in some cases and in others there are multiple local optima.
You can try fitting by maximum likelihood, but if you're using the MLE function with a custom PDF function, you at least will need to upper bound the threshold parameter by the smallest observation, and probably that minus a small epsilon. You might consider looking at this
which describes another fitting method that doesn't suffer from the problems that ML has in some thresholded distributions.
By the way, it's not clear to me why you need that loop in your PDF. If you want to preallocate y, use y = zeros(size(x)). But given the line that follows the loop, you shouldn't even need to preallocate. Hope this helps.
  댓글 수: 3
sepideh
sepideh 2014년 12월 5일
I am trying to do the same thing and this link apparently should be purchased? What is the fitting method? I am trying to find it from another source if possible.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt Tearle
Matt Tearle 2012년 9월 11일
Peter is the expert on statistical matters, so I'd take his advice on whether what you're trying to do is a good idea. But here's one way to make something work (whether or not it's a good idea!):
% define the pdf
shiftgampdf = @(x,a,b,xi) max(realmin,gampdf(x-xi,a,b));
% make some data
a = pi;
b = 2/pi;
y = gamrnd(a,b,200,1)+10;
% do the MLE fit
mle(y,'pdf',shiftgampdf,'start',[2,1,5])
Note that I'm defining the PDF as a function handle that simply calls gampdf with a shifted x value. However, you can get values that are 0 to machine precision during the MLE fitting, which is why I've added the max(realmin... part. This ensures that the values returned are always very slightly positive (avoiding the error messages that you get from mle).
  댓글 수: 1
Pat
Pat 2012년 9월 11일
Thanks Matt! I appreciate your input. I will give your solution a shot, and I agree with you, Peter is certainly the expert. His statements above make me nervous about proceeding but we'll see where this goes. Thanks again.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by