Re: [R] dnorm and qnorm

2010-11-14 Thread Edwin Sun

Thank you all for the great help. I think the optimize function and approach
solves my problem well. 

Edwin Sun
-- 
View this message in context: 
http://r.789695.n4.nabble.com/dnorm-and-qnorm-tp3040427p3041962.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] dnorm and qnorm

2010-11-12 Thread David Winsemius


On Nov 12, 2010, at 5:35 PM, Edwin Sun 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



Since only at the mode of dnorm will there be a unique solution, you  
will need to decide on which side of zero you want to work, apparently  
the negative side from the expected answer. Then you can use optim or  
optimize to minimize the difference between dnorm() and 0.328161 for  
arguments over an appropriate range:

 f - function (x,a) (dnorm(x)-a)^2
 xmin - optimize(f, c(-1, 0), tol = 0.0001, a =0.328161)
 xmin
$minimum
[1] -0.6250044

$objective
[1] 8.71397e-13




David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] dnorm and qnorm

2010-11-12 Thread Peter Langfelder
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 c...@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@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.


__
R-help@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.


Re: [R] dnorm and qnorm

2010-11-12 Thread Bert Gunter
There is no reversing the dnorm function -- dnorm is many to one in
general (in the normal case, 2 to 1 except for the mean). How would
you reverse dunif, for example?!

However, with that understanding you could do a simple one dimensional
search within the range you want via optimize(), as in

 optimize(function(x)abs(dnorm(x) - .3286),lower=-5,upper = 0) ## or use 
 squared error
$minimum
[1] -0.6228337

$objective
[1] 4.817833e-06

-- Bert

On Fri, Nov 12, 2010 at 2:35 PM, Edwin Sun c...@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@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.




-- 
Bert Gunter
Genentech Nonclinical Biostatistics

__
R-help@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.