Solving for two parameters using `optim()` in R?

Viewed 610

I'm trying to find shape1 and shape2 in dbeta() such that the answer from dbeta() for the two input values: .6 and .8 become 3.

I'm using the below optim() but don't get exact result, that is I expect getting values for shape1 and shape2 that when used with .6 and .8 give 3 and 3, but they don't, why?

f <- function(x) {
 y <- c(3, 3) - dbeta(c(.6, .8), shape1 = x[1],  shape2 = x[2])  
}

AA = optim(c(1, 1), function(x) sum(f(x)^2), control = list(reltol = (.Machine$double.eps))) 

parms = unname(AA$par)

dbeta(c(.6, .8), parms[1], parms[2]) # Here I expect to get `3` for `.6` and `.8` but I don't.
1 Answers
Related