Search code examples
rnormal-distributionprobability-densitydensity-plot

R - Get X value for given Y value


I have a cumulative distribution function from a standard normal distribution and I have a given y value, which should be 0.95

dist <- function(x) pnorm(x,0,1)

How can I solve the equation 0.95 = dist(x) for x?


Solution

  • You can use the uniroot function as follows:

    dist <- function(x) pnorm(x,0,1) - 0.95
    uniroot(dist, interval = c(-1,4))
    

    which would give you the same answer as qnorm(0.95,0,1).