[R] odd dnorm behaviour (?)

Moshe Olshansky m_olshansky at yahoo.com
Tue Jul 8 07:30:07 CEST 2008


dnorm() computes the density, so it may be > 1;  pnorm() computes the distribution function.


--- On Tue, 8/7/08, Mike Lawrence <Mike.Lawrence at dal.ca> wrote:

> From: Mike Lawrence <Mike.Lawrence at dal.ca>
> Subject: Re: [R] odd dnorm behaviour (?)
> To: "Rhelp" <r-help at stat.math.ethz.ch>
> Received: Tuesday, 8 July, 2008, 2:51 PM
> #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? Last time  
> I checked,
> #a probability shouldn't be greater than 1 as produced
> by:
> 
> curve(dnorm(x,0,.1),from=-.5,to=.5)
> 
> #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)
> 
> #If the latter code betrays a misunderstanding of what a
> pdf is, be  
> gentle!
> 
> #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.



More information about the R-help mailing list