Search code examples
rdistributionreverseinverse

The reverse/inverse of the normal distribution function in R


To plot a normal distribution curve in R we can use:

(x = seq(-4,4, length=100))
y = dnorm(x)
plot(x, y)

enter image description here

If dnorm calculates y as a function of x, does R have a function that calculates x as a function of y? If not what is the best way to approach this?


Solution

  • I'm not sure if the inverse of the density function is built in -- it's not used nearly as often as the inverse of the cumulative distribution function. I can't think offhand of too many situation where the inverse density function is useful. Of course, that doesn't mean there aren't any, so if you are sure this is the function you need, you could just do:

    dnorminv<-function(y) sqrt(-2*log(sqrt(2*pi)*y))
    
    plot(x, y)
    points(dnorminv(y),y,pch=3)
    

    enter image description here