[R] odd dnorm behaviour (?)

From: Mike Lawrence <Mike.Lawrence_at_DAL.CA>
Date: Tue, 08 Jul 2008 01:41:37 -0300


#Quick one hopefully. Shouldn't dnorm be returning the pdf? Last time
I checked,
#a probability shouldn't be greater than 1 as produced by:

curve(dnorm(x,0,.1),from=-1,to=t)

#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,m=0,s=1),from=-5,to=5)

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

#Mike



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 - 04:44:54 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 - 05:31:07 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