From murdoch at stats.uwo.ca  Thu Feb 15 00:14:27 2007
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Wed, 14 Feb 2007 18:14:27 -0500
Subject: [Rd] Problem with the 'hist' function
In-Reply-To: <7B7F2C3E-07D7-44ED-A7E7-06E97CCB702E@princeton.edu>
References: <7B7F2C3E-07D7-44ED-A7E7-06E97CCB702E@princeton.edu>
Message-ID: <45D397D3.3020602@stats.uwo.ca>

On 2/14/2007 5:51 PM, Edo Airoldi wrote:
> Hi, I am using the following R version:
> 
>  > R version 2.4.1 (2006-12-18)
>  > Copyright (C) 2006 The R Foundation for Statistical Computing
>  > ISBN 3-900051-07-0
> 
>   I believe I found a bug in the 'hist' function, when  
> 'probability=TRUE'. I looked in the archives and I came across  
> problems with the 'hist' functions (e.g., bug PR# 944, posted in  
> 2001), however, a quick search did not find the exact problem I a  
> found. A brief description of the issue follows.
> 
>  > z<-rnorm(10)
>  > z
> [1]  0.51649608 -0.20676010  0.65951365  0.46733006  0.02084361   
> 0.18323525
> [7] -0.21522566  0.29597667  0.81549448  0.26252625
>  > hist(z,breaks=seq(-1,1,by=.25))
>  > hist(z,breaks=seq(-1,1,by=.25),probability=TRUE)
> 
>   I think the values on the Y axis are messed up, e.g., it should top  
> at 0.3 (relative frequency) for the bin [0.25 0.50). How is 'Density'  
> computed?

It's not relative frequency, it's density:  relative frequency per unit 
of x.  The upper limit would be 4 with a step size of 0.25 (if all the 
observations fell in one interval).

Duncan Murdoch



[Rd] Problem with the 'hist' function
Duncan Murdoch