# how to use betafit for a data that is outside the range of 0 to 1.?

27 views (last 30 days)

Show older comments

Pappu Murthy
on 12 Jan 2022

Commented: Pappu Murthy
on 17 Jan 2022

### Accepted Answer

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;

histogram(x,'norm','pdf')

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;

histogram(xscale,'norm','pdf')

PHAT = betafit(xscale)

hold on

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.

### More Answers (0)

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!