Re: Reconciling BinCounts and RangeCounts
- To: mathgroup at smc.vnet.net
- Subject: [mg68091] Re: Reconciling BinCounts and RangeCounts
- From: "Ray Koopman" <koopman at sfu.ca>
- Date: Sat, 22 Jul 2006 06:24:14 -0400 (EDT)
- References: <e9nn01$ak7$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Gregory Lypny wrote: > Hello Everyone, > > I get a discrepancy between the results of BinCounts and RangeCounts > and can confirm only that RangeCounts is, in fact, counting the > number of instances where a number is at least as big as the lower > cut-off and less than the upper cut-off. Not so for BinCounts, which > leads me to believe that it is buggy or, more likely, I am. > > I have a vector, x, with 7320 observations of real numbers in the > range .06 to .14 with up to seven decimal places. Here's what I get > if I use bins or cut-offs of .01. > > First with BinCounts > BinCounts[x, {.06, .14, .01}] > {103, 333, 802, 1266, 997, 662, 611, 2265, 281} > > Now with RangeCounts > RangeCounts[x, Range[.07, .14, .01]] > {103, 333, 797, 1270, 997, 663, 611, 2265, 281} > > Notice that elements 3, 4, and 6 of the results differ. So I tried > to check what was going on by using Select and was able to confirm > all of the RangeCounts elements. For example, the third element of > the RangeCounts results, 797, can be confirmed by using > > Length[Select[x, .08 =B2 # < .09 &]] >>>> returns 797 > > However, the third element of the BinCounts results, 802, can be > obtained only if I include the upper bound, .09, in the count as > > Length[Select[x, .08 =B2 # =B2 .09 &]] >>>>> returns 802, > > which of course makes no sense because we need a strong inequality > for one of them. But it gets worse. When I go on to check elements > 4 and 6 of BinCounts, there is no combination of weak or strong > inequalities that will give me the results 1266 and 662. > > Can anyone shed any light on this? In the meantime, I think it > safest to use RangeCounts. > > Regards, > > Gregory= In[1]:= <<Statistics`DataManipulation` In[2]:= k = 0; Do[x = Table[Random[Real,{.06,.14}],{7320}]; b = BinCounts[ x, {.06, .14, .01}]; r = RangeCounts[x, Range[.07, .14, .01]]; If[b != r, Print[{++k,b,r}]], {100}]; k Out[4]= 0 I can't replicate your problem. Are some of your data values right on the boundaries?