[R] dnorm and qnorm

Peter Langfelder peter.langfelder at gmail.com
Fri Nov 12 23:47:56 CET 2010


Not sure if there's a pre-defined function for it, but use your basic
math skills: the normal distribution is

dnorm(x) = 1/(sqrt(2*pi)) * exp(-x^2/2),

so the inverse function (on the interval [0, infinity] is

f = function(x) {sqrt( -2*log(sqrt(2*pi) * x)) }

Since the dnorm function is not 1-to-1, f is strictly speaking not the
inverse (since the latter doesn't exist), but it is true that
f(dnorm(x)) = abs(x).


Test:

x = seq(from = -2, to = 2, by = 0.01)

plot(x, dnorm(x))
plot(x, f(dnorm(x)))

> all.equal(abs(x), f(dnorm(x)))
[1] TRUE


Note again that f(dnorm(x)) = abs(x), not x, since the dnorm function
is not 1-to-1.

Peter



On Fri, Nov 12, 2010 at 2:35 PM, Edwin Sun <csun at cfr.msstate.edu> wrote:
>
> Hello all,
>
> I have a question about basic statistics.  Given a PDF value of 0.328161,
> how can I find out the value of -0.625 in R? It is like reversing the dnorm
> function but I do not know how to do it in R.
>
>> pdf.xb <- dnorm(-0.625)
>
>> pdf.xb
> [1] 0.328161
>
>> qnorm(pdf.xb)
> [1] -0.444997
>
>> pnorm(pdf.xb)
> [1] 0.628605
>
> Many thanks,
>
>
> Edwin
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/dnorm-and-qnorm-tp3040427p3040427.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list