[R] odd dnorm behaviour (?)
Charles C. Berry
cberry at tajo.ucsd.edu
Tue Jul 8 07:39:06 CEST 2008
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
More information about the R-help
mailing list