1
$\begingroup$

Suppose I'm given the mean and one quantile (e.g. the 95% quantile) of a random variable $x$, and I want to find the parameters $\alpha$ and $\beta$ of a Beta distribution that has the same mean and quantile. Is there an efficient way to do it in R?

$\endgroup$
  • 2
    $\begingroup$ @DilipSarwate - she actually tried to ask this question as an answer to that other one, but it was deleted as it wasn't an answer to the other one, so I suspect the question really is "how to do this in R", rather than "how to do this". $\endgroup$ – jbowman Jun 6 '14 at 18:25
  • $\begingroup$ If it is possible either of $\alpha$ or $\beta$ could be close to zero, then a carefully crafted solution is needed because the natural general-purpose ones can fail to work. For instance, the Beta$(1/10,1/5)$ distribution has a mean of $1/3$ and a $95\%$ quantile of $0.999933679286$. Any good solution should tell you that $\alpha$ is very close to $0.1$! $\endgroup$ – whuber Jun 6 '14 at 18:44
  • 1
    $\begingroup$ @jbowman I would have thought "How to do this?" would be a more interesting question that "How to do this in R?" on stats.SE; the latter seems more appropriate for a programming website. $\endgroup$ – Dilip Sarwate Jun 6 '14 at 18:45
1
$\begingroup$
m <- 1/4   # mean
pr <- 0.95 # prob
qnt <- 2/3 # quantile
f <- function(a) abs(qbeta(pr, shape1 = a, shape2 = a * (1 - m) / m) -  qnt)
optim(1, f, lower = 0, upper = 10^3, method = "L-BFGS-B")$par
$\endgroup$
  • 2
    $\begingroup$ I'd use the squared error if using L-BFGS-B as it probably has a smoother gradient, unlike abs. $\endgroup$ – Avraham Jun 6 '14 at 18:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.