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?
BXC (Bendix Carstensen)
2005-Jan-07 10:31 UTC
[R] hist function to give each cell equal area
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 bxc at steno.dk www.biostat.ku.dk/~bxc ----------------------> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] 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 at 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 >
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 at 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 >
Dan Bolser <dmb at mrc-dunn.cam.ac.uk> 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 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
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 at 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: Roger.Bivand at nhh.no