Search code examples
rstatisticsbeta-distribution

How do I estimate parameters of beta distribution with known percentiles in r


I have this dataset which I know is from a beta distribution but with unknown parameters:

2.5% 0.264 50% 0.511 97.5% 0.759

Is there anyway to find the best-fit beta distribution and estimate the shape parameters by using r?


Solution

  • m=function(z){
       if(any(z<0))return(NA)
       x=z[1];y=z[2]
       a=c(qbeta(0.025,x,y),qbeta(0.5,x,y),qbeta(0.975,x,y))-c(0.264,0.511,0.759)
       b=c(pbeta(0.264,x,y), pbeta(0.511,x,y), pbeta(0.759,x,y))-c(0.025,0.5,0.975)
       abs(a)+abs(b)
     }
    sol=optim(c(0.1,1),function(x)sum(abs(m(x))),m)$par;sol
    [1] 7.375020 7.071576
    pbeta(0.264,sol[1],sol[2])
    [1] 0.02500033# almost close to 0.025
     pbeta(0.511,sol[1],sol[2])
    [1] 0.5
     pbeta(0.759,sol[1],sol[2])
    [1] 0.9774994
     qbeta(0.025,sol[1],sol[2])
    [1] 0.2639994
     qbeta(0.5,sol[1],sol[2])
    [1] 0.511
     qbeta(0.975,sol[1],sol[2])
    [1] 0.7542515
    

    You can also decide to just use the pbeta alone or the qbeta alone, all this will give varied results but close to the correct results