I am using R to get quantile from a given function which is giving the error below which I don't quite understand what it means. Although the error message seems self explanatory this R Noob can't work it out. Any help appreciated.
Error:
Error in cum(x) - p : non-numeric argument to binary operator
Here is the code:
library(nleqslv)
dens<-function(x)
{
(dbeta(x, shape1 = 1, shape2 = 5) + dbeta(x, shape1 = 3, shape2 = 5) + dbeta(x, shape1 = 10,
shape2 = 5))*1/3
}
cum<-function(x)
{
integrate(dens,-Inf,x)
}
quant<-function(p)
{
nleqslv(0, function(x){cum(x)-p})
}
print(quant(0.50))