How do I use MLE on a shifted gamma distribution?
Show older comments
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
Accepted Answer
More Answers (1)
Matt Tearle
on 11 Sep 2012
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).
Categories
Find more on Gamma Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!