how to use betafit for a data that is outside the range of 0 to 1.?
13 views (last 30 days)
I have numbers between 10 to 20. If I try to use betafit it refuses to fit because the range is not from 0 to 1. If I have numbers from say .12 to .25 it lets me fit a beta. I am not sure why range has to limit my ability to fit a beta distribution to a dataset. Help please.
John D'Errico on 12 Jan 2022
Edited: John D'Errico on 12 Jan 2022
You essentially have a 4 parameter beta distribution that you wish to fit. That is, the upper and lower limits can be part of it. But betafit only does the 2-parameter one, because estimating those bounds can be difficult.
Why do I say the bounds are difficult to estimate automatically? Because where the distrbution goes to zero at the end, exactly where does it become exactly zero? And on distributions where the PDF goes to infinity, now you have a singularity, and trying to figure out exactly where the singularity lies is again a nasty thing.
But you can simply shift and scale your data to [0,1], or [-1,1], depending on the beta parameterization. For example...
x = randn(1,10000)/10 + 3;
Yes, we all know this is normally distributed data. SHSSH! Its a secret. Now, suppose we want to fit a beta distribution to it? Now it lives in the interval [0,1]. Again, exactly where those limits really should be is very difficult to quantify.
xscale = (x - mean(x));
xscale = xscale/max([abs(min(xscale)),max(xscale)])/2 + 1/2;
PHAT = betafit(xscale)
fplot(@(X) betapdf(X,PHAT(1),PHAT(2)),[0 1])
That is not a terrible fit, but a normal would surely have done better.
Finally, what did you do wrong in the pickture you showed? That data does not look very much like any beta distribution I can think of, with that large spike in the center, but flat tails. I'm not remotely surprised you got crap for a fit. And it does not look like you have much data. Betafit had problems fitting a beta to that data. Again, absolutely no surprise.