So for example, I have a discrete function with a CDF as follows:
cdf <- c(0.00, 0.35, 0.71, 0.92, 1.00, 1.00, 1.00, 1.00)
I can create a sort of quantile function with the following line . . .
result <- which(cdf == min(cdf[cdf > x]))
. . . where x is the cumulative probability. So for example, qfunction(0.9) = 4 and qfunction(0.99) = 5.
This solution appears fine (albeit inelegant) until I want to handle vectors. So if x = c(0.9, 0.99) my function falls over. This seems like something that people would do a lot of in R and yet I haven't found a solution. R is not my primary language.
Any help would be appreciated.
You probably want the findInterval()
function. See the ?findInerval
help page for details about the function. But something like
findInterval(c(.9, .99), cdf)+1
should work for your sample data/input.