Re: [R] odd dnorm behaviour (?)

From: Charles C. Berry <cberry_at_tajo.ucsd.edu>
Date: Mon, 07 Jul 2008 22:39:06 -0700

On Tue, 8 Jul 2008, Mike Lawrence wrote:

> #Let's try this again! This time the code is more sensible (curve range, same
> sd value).
>
> # Quick one hopefully. Shouldn't dnorm be returning the pdf?

No. See the documentation

         ?dnorm

especially what it says under 'Value'

> Last time I
> # checked,
> # a probability shouldn't be greater than 1 as produced by:
>
> curve(dnorm(x,0,.1),from=-.5,to=.5)

I do not see a probability that is greater than one here:

> integrate(function(x) dnorm(x,0,.1),lower=-Inf,upper=Inf)
1 with absolute error < 6.1e-07

... looks like 1 to me.

>
> #Shouldn't I be getting an axis more like that produced by:
>
> f=function(x,m,s){
> y=rep(NA,length(x))
> for(i in 1:length(x)){
> y[i]=integrate(
> dnorm
> , upper=x[i]+sqrt(.Machine$double.eps)
> , lower=x[i]-sqrt(.Machine$double.eps)
> , mean=m
> , sd=s
> ) $value
> }
> return(y)
> }
> curve(f(x,0,.1),from=-.5,to=.5)

Well, what does this suggest?

> integrate(function(x) f(x,0,.1),lower=-Inf,upper=Inf)
2.980232e-08 with absolute error < 2.6e-10
>
> sqrt(.Machine$double.eps)*2

[1] 2.980232e-08

>
> #If the latter code betrays a misunderstanding of what a pdf is, be gentle!

Well, the posting guide does ask you to do some homework before posting.

Nowadays, it is as easy. Google 'wiki probability density function' or look in the reference in ?dnorm.

>
> #Mike
>
> --
> Mike Lawrence
> Graduate Student, Department of Psychology, Dalhousie University
>
> www.memetic.ca
>
> "The road to wisdom? Well, it's plain and simple to express:
> Err and err and err again, but less and less and less."
> - Piet Hein
>
> ______________________________________________
> 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.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry_at_tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901

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. Received on Tue 08 Jul 2008 - 05:41:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Jul 2008 - 06:31:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive