[R] hist function to give each cell equal area

2005-01-07 Thread Dan Bolser

Hi,

I want to use hist with non-equi-spaced breaks, picked such that the
fraction of the data points falling in the cells (defined by 'breaks') is 
roughly equal accross all cells.

Is there such a function that will automatically try to determine the
breaks to fullfill this requirement?

Something like..

hist( x, br = magic_function_to_pick_breaks())


For example, if x looked like this...

x - c( 1:5, 10+1:5, 100+1:5 )

the breaks would define cells like this 

hist(x,breaks=c(0,5,15,105))

Is there such a function?

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] hist function to give each cell equal area

2005-01-07 Thread BXC (Bendix Carstensen)
how about:

x - rnorm(400)
nbin-7
hist(x,breaks=quantile(x,prob=seq(0,1,length=nbin+1)))

Bendix Carstensen
--
Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 30 75 87 38
fax: +45 44 43 07 06
[EMAIL PROTECTED]
www.biostat.ku.dk/~bxc
--



 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Dan Bolser
 Sent: Friday, January 07, 2005 11:21 AM
 To: R mailing list
 Subject: [R] hist function to give each cell equal area
 
 
 
 Hi,
 
 I want to use hist with non-equi-spaced breaks, picked such 
 that the fraction of the data points falling in the cells 
 (defined by 'breaks') is 
 roughly equal accross all cells.
 
 Is there such a function that will automatically try to 
 determine the breaks to fullfill this requirement?
 
 Something like..
 
 hist( x, br = magic_function_to_pick_breaks())
 
 
 For example, if x looked like this...
 
 x - c( 1:5, 10+1:5, 100+1:5 )
 
 the breaks would define cells like this 
 
 hist(x,breaks=c(0,5,15,105))
 
 Is there such a function?
 
 __
 R-help@stat.math.ethz.ch mailing list 
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read 
 the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] hist function to give each cell equal area

2005-01-07 Thread Achim Zeileis
On Fri, 7 Jan 2005, Dan Bolser wrote:


 Hi,

 I want to use hist with non-equi-spaced breaks, picked such that the
 fraction of the data points falling in the cells (defined by 'breaks') is
 roughly equal accross all cells.

 Is there such a function that will automatically try to determine the
 breaks to fullfill this requirement?

 Something like..

 hist( x, br = magic_function_to_pick_breaks())

It's not that magic, but such points are usually called quantiles in
statistics...

 For example, if x looked like this...

 x - c( 1:5, 10+1:5, 100+1:5 )

 the breaks would define cells like this

 hist(x,breaks=c(0,5,15,105))

quantile(x, 0:3/3, type = 1)

hth,
Z

 Is there such a function?

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] hist function to give each cell equal area

2005-01-07 Thread Peter Dalgaard
Dan Bolser [EMAIL PROTECTED] writes:

 Hi,
 
 I want to use hist with non-equi-spaced breaks, picked such that the
 fraction of the data points falling in the cells (defined by 'breaks') is 
 roughly equal accross all cells.
 
 Is there such a function that will automatically try to determine the
 breaks to fullfill this requirement?
 
 Something like..
 
 hist( x, br = magic_function_to_pick_breaks())
 
 
 For example, if x looked like this...
 
 x - c( 1:5, 10+1:5, 100+1:5 )
 
 the breaks would define cells like this 
 
 hist(x,breaks=c(0,5,15,105))
 
 Is there such a function?

Probably not giving pretty numbers, but quantile() gets you most of
the way

 quantile(x,seq(0,1,1/3))
 hist(x,breaks=quantile(x,seq(0,1,1/3)))
 table(cut(x,breaks=quantile(x,seq(0,1,1/3

obviously, with that distribution you have to be a little careful:

 hist(x,breaks=quantile(x)) does look somewhat different...

-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] hist function to give each cell equal area

2005-01-07 Thread Roger Bivand
On Fri, 7 Jan 2005, Dan Bolser wrote:

 
 Hi,
 
 I want to use hist with non-equi-spaced breaks, picked such that the
 fraction of the data points falling in the cells (defined by 'breaks') is 
 roughly equal accross all cells.

?quantile

 
 Is there such a function that will automatically try to determine the
 breaks to fullfill this requirement?
 
 Something like..
 
 hist( x, br = magic_function_to_pick_breaks())
 
 
 For example, if x looked like this...
 
 x - c( 1:5, 10+1:5, 100+1:5 )
 
 the breaks would define cells like this 
 
 hist(x,breaks=c(0,5,15,105))

hist(x, quantile(x, seq(0,1,1/3)))

isn't the same, but your breaks are arbitrary and based on knowing where 
the gaps are.

 
 Is there such a function?
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] hist function to give each cell equal area

2005-01-07 Thread Dan Bolser
On Fri, 7 Jan 2005, BXC (Bendix Carstensen) wrote:

how about:

x - rnorm(400)
nbin-7
hist(x,breaks=quantile(x,prob=seq(0,1,length=nbin+1)))

Thanks for the replies! Quantiles are my new friend. Its true the example
I gave was a bit tricky, I just wanted to get the idea over.

One thing that is slightly confusing (probably a slight syntax thing),
combining the above with the reply from Peter Dalgaard...

nbin-10
x - rnorm(400)
hist(x,breaks=quantile(x,prob=seq(0,1,length=nbin+1)))

y - table(cut(x,breaks=quantile(x,seq(0,1,length=nbin+1

 y
[1] 399

I only get 399 counts out, and I put 400 counts in?

Cheers,
Dan.


Bendix Carstensen
--
Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 30 75 87 38
fax: +45 44 43 07 06
[EMAIL PROTECTED]
www.biostat.ku.dk/~bxc
--



 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Dan Bolser
 Sent: Friday, January 07, 2005 11:21 AM
 To: R mailing list
 Subject: [R] hist function to give each cell equal area
 
 
 
 Hi,
 
 I want to use hist with non-equi-spaced breaks, picked such 
 that the fraction of the data points falling in the cells 
 (defined by 'breaks') is 
 roughly equal accross all cells.
 
 Is there such a function that will automatically try to 
 determine the breaks to fullfill this requirement?
 
 Something like..
 
 hist( x, br = magic_function_to_pick_breaks())
 
 
 For example, if x looked like this...
 
 x - c( 1:5, 10+1:5, 100+1:5 )
 
 the breaks would define cells like this 
 
 hist(x,breaks=c(0,5,15,105))
 
 Is there such a function?
 
 __
 R-help@stat.math.ethz.ch mailing list 
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read 
 the posting guide! http://www.R-project.org/posting-guide.html
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] hist function to give each cell equal area

2005-01-07 Thread Roger Bivand
On Fri, 7 Jan 2005, Dan Bolser wrote:

 On Fri, 7 Jan 2005, BXC (Bendix Carstensen) wrote:
 
 how about:
 
 x - rnorm(400)
 nbin-7
 hist(x,breaks=quantile(x,prob=seq(0,1,length=nbin+1)))
 
 Thanks for the replies! Quantiles are my new friend. Its true the example
 I gave was a bit tricky, I just wanted to get the idea over.
 
 One thing that is slightly confusing (probably a slight syntax thing),
 combining the above with the reply from Peter Dalgaard...
 
 nbin-10
 x - rnorm(400)
 hist(x,breaks=quantile(x,prob=seq(0,1,length=nbin+1)))
 
 y - table(cut(x,breaks=quantile(x,seq(0,1,length=nbin+1
 
  y
 [1] 399
 
 I only get 399 counts out, and I put 400 counts in?

 y - table(cut(x,breaks=quantile(x,seq(0,1,length=nbin+1)), 
+include.lowest = TRUE))

It's the include.lowest= argument to cut()

 
 Cheers,
 Dan.
 
 
 Bendix Carstensen
 --
 Bendix Carstensen
 Senior Statistician
 Steno Diabetes Center
 Niels Steensens Vej 2
 DK-2820 Gentofte
 Denmark
 tel: +45 44 43 87 38
 mob: +45 30 75 87 38
 fax: +45 44 43 07 06
 [EMAIL PROTECTED]
 www.biostat.ku.dk/~bxc
 --
 
 
 
  -Original Message-
  From: [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED] On Behalf Of Dan Bolser
  Sent: Friday, January 07, 2005 11:21 AM
  To: R mailing list
  Subject: [R] hist function to give each cell equal area
  
  
  
  Hi,
  
  I want to use hist with non-equi-spaced breaks, picked such 
  that the fraction of the data points falling in the cells 
  (defined by 'breaks') is 
  roughly equal accross all cells.
  
  Is there such a function that will automatically try to 
  determine the breaks to fullfill this requirement?
  
  Something like..
  
  hist( x, br = magic_function_to_pick_breaks())
  
  
  For example, if x looked like this...
  
  x - c( 1:5, 10+1:5, 100+1:5 )
  
  the breaks would define cells like this 
  
  hist(x,breaks=c(0,5,15,105))
  
  Is there such a function?
  
  __
  R-help@stat.math.ethz.ch mailing list 
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read 
  the posting guide! http://www.R-project.org/posting-guide.html
  
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] hist function to give each cell equal area

2005-01-07 Thread Peter Dalgaard
Dan Bolser [EMAIL PROTECTED] writes:

 y - table(cut(x,breaks=quantile(x,seq(0,1,length=nbin+1
 
  y
 [1] 399
 
 I only get 399 counts out, and I put 400 counts in?

Look at the include.lowest argument. For some reason this is TRUE in
hist() but FALSE in cut().

-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html