Accuracy of dnorm (PR#8586)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Accuracy of dnorm (PR#8586)

Marco VEZZOLI
Full_Name: Marco Vezzoli
Version: 2.2.0 2.1.0 2.0.0
OS: Solaris, Windows, Linux
Submission from: (NULL) (57.78.11.38)


The dnorm functions yield a wrong value when the standard deviation is near to
1e-1
e.g.
> dnorm(0,mean=0.04,sd=0.3)
[1] 1.318039

this error is consistent in various version and os.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Accuracy of dnorm (PR#8586)

Brian Ripley
On Fri, 10 Feb 2006, [hidden email] wrote:

> Full_Name: Marco Vezzoli
> Version: 2.2.0 2.1.0 2.0.0
> OS: Solaris, Windows, Linux
> Submission from: (NULL) (57.78.11.38)
>
>
> The dnorm functions yield a wrong value when the standard deviation is near to
> 1e-1
> e.g.
>> dnorm(0,mean=0.04,sd=0.3)
> [1] 1.318039

What is wrong here?  Try the textbook formula

> x <- 0
> m <- 0.04
> sd <- 0.3
> 1/(sqrt(2*pi)*sd) * exp(-0.5*(x-m)^2/sd^2)
[1] 1.318039

> this error is consistent in various version and os.

It _is_ good that R is consistent.

I don't think we are going to believe you unless you give your credentials
and state your `correct value' and your reasoning.

--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Accuracy of dnorm (PR#8586)

barry rowlingson
Prof Brian Ripley wrote:

>>The dnorm functions yield a wrong value when the standard deviation is near to
>>1e-1

> What is wrong here?  Try the textbook formula
>
>
>>x <- 0
>>m <- 0.04
>>sd <- 0.3
>>1/(sqrt(2*pi)*sd) * exp(-0.5*(x-m)^2/sd^2)
>
> [1] 1.318039
>

Even MS Excel gets this one right:

=NORMDIST(0,0.04,0.3,FALSE)

1.31803947

Barry

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Accuracy of dnorm (PR#8586)

Peter Dalgaard
In reply to this post by Marco VEZZOLI
[hidden email] writes:

> Full_Name: Marco Vezzoli
> Version: 2.2.0 2.1.0 2.0.0
> OS: Solaris, Windows, Linux
> Submission from: (NULL) (57.78.11.38)
>
>
> The dnorm functions yield a wrong value when the standard deviation is near to
> 1e-1
> e.g.
> > dnorm(0,mean=0.04,sd=0.3)
> [1] 1.318039
>
> this error is consistent in various version and os.

What's wrong with it???

> (pnorm(0.000001,mean=0.04,sd=0.3) - pnorm(0,mean=0.04,sd=0.3))/.000001
[1] 1.318040


--
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([hidden email])                  FAX: (+45) 35327907

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Accuracy of dnorm (PR#8586)

Marco VEZZOLI
I'm very sorry for the error.
I confused probability density with the distribution.
Thank you for your answer.
        Marco

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel