[R] looking for beta parameters

Kehl Dániel kehld at ktk.pte.hu
Thu Nov 24 12:43:36 CET 2011


Dear Community,

I am trying to write (update) a code for the following problem.
Lets assume we have a beta distribution.
I know one quantile, lets say, 10% of the mass lies above .8, that is 
between .8 and 1.
In addition, I  know that the average of this "truncated tail" is a 
given number, lets say .86.
I have found the beta.select function in the LearnBayes package, which 
is as follows:

function (quantile1, quantile2)
{
     betaprior1 = function(K, x, p) {
         m.lo = 0
         m.hi = 1
         flag = 0
         while (flag == 0) {
             m0 = (m.lo + m.hi)/2
             p0 = pbeta(x, K * m0, K * (1 - m0))
             if (p0 < p)
                 m.hi = m0
             else m.lo = m0
             if (abs(p0 - p) < 1e-04)
                 flag = 1
         }
         return(m0)
     }
     p1 = quantile1$p
     x1 = quantile1$x
     p2 = quantile2$p
     x2 = quantile2$x
     logK = seq(-3, 8, length = 100)
     K = exp(logK)
     m = sapply(K, betaprior1, x1, p1)
     prob2 = pbeta(x2, K * m, K * (1 - m))
     ind = ((prob2 > 0) & (prob2 < 1))
     app = approx(prob2[ind], logK[ind], p2)
     K0 = exp(app$y)
     m0 = betaprior1(K0, x1, p1)
     return(round(K0 * c(m0, (1 - m0)), 2))
}

I assume one could change this code to get the results I need, but some 
parts of the function are not clear for me, any help would be greatly 
appreciated.

Thanks a lot:
Daniel



More information about the R-help mailing list