How do I estimate the parameters for a beta distribution using MLE?
15 次查看(过去 30 天)
显示 更早的评论
I have tried to search and I have tried out several things in Matlab and I cannot figure out for the life of me what is going on. :(
If I take an example dataset:
alpha = 1.5 ; beta = 1.25 ;
x = 0:0.01:1 ;
y = betapdf(x,alpha,beta) ;
Then, I want to estimate the alpha and beta parameters from this distribution, how do I do it?
I'll show you what I've tried and what hasn't worked...
Attempt 1:
>> phat = mle(y,'distribution','beta')
Error using betafit (line 45)
All values must be within the closed interval [0,1].
Error in mle (line 278)
phat = betafit(data,alpha);
Attempt 2:
>> phat = betafit(y,0.1) ;
Error using betafit (line 45)
All values must be within the closed interval [0,1].
Attempt 3:
>> phat = mle(y*0.01,'distribution','beta')
ans =
0.112285261232716 11.744190900225709
Attempt 4:
>> phat = betafit(y*0.01,0.1)
ans =
0.112285261232716 11.744190900225709
Attempt 5:
alphas = 0.1:0.1:4 ; betas = alphas ;
lnlik = zeros(length(alphas),length(betas)) ;
for i = 1:length(alphas)
for j = 1:length(betas)
lnlik(i,j) = betalike([alphas(i) betas(j)],y*0.01) ;
end
end
[ind(:,1),ind(:,2)] = find(lnlik == min(min(lnlik))) ;
>> [alphas(ind(1)), betas(ind(2))
ans =
0.100000000000000 4.000000000000000
Grrr! How do I do this?? I have some data that I want to find the best-fitting beta distribution, but I cannot even figure it out for a distribution I know is beta…please help me! What am I doing wrong???
The examples I've seen for using these estimation functions all use betarnd as the function to generate the sample, but I when I plot the results from betarnd, I cannot make sense of it. I am so utterly confused as to what betarnd is really (I tried a comparison with normrnd to see if I could understand, I was just as much at a loss…the results do not look like a normal distribution). I'm so confused.
0 个评论
采纳的回答
Jeremy Kemmerer
2014-10-1
Hi Jessica,
It looks like the approaches you are using to estimate the Beta distribution parameters are valid, but it seems you are trying to fit to the Beta pdf rather than a data set generated according to the Beta distribution.
You can try generating a test case with 1000 samples according to the beta distribution like this:
>>y = betarnd(1.5,1.25,1000,1); //generate sample
Now, if you try your first approach you should get meaningful parameter estimates:
>>phat = mle(y,'distribution','beta');
Please refer to the following documentation for more information on the “betarnd” function: http://www.mathworks.com/help/stats/betarnd.html
3 个评论
Jeremy Kemmerer
2014-10-1
Hi Jessica,
Here’s one thing to try using the simpler uniform pdf. First, generate the pdf itself:
>> x = 0:0.01:1;
>> y = unifpdf(x);
You should see that the vector y contains only the value 1, since the uniform pdf is a constant (and equal to 1 if the interval is 0 to 1).
Now, if we want to create random variables whose pdf is uniform, you can try:
>>r = rand(1000,1);
>>hist(r);
This will generate 1000 values uniformly and at random between 0 and 1. The “hist” command will plot the histogram of your data, which should be fairly flat and look similar to the pdf. For “y”, you might use the plot command to view the pdf itself.
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!