Error in BinCounts function?
- To: mathgroup at smc.vnet.net
- Subject: [mg36515] Error in BinCounts function?
- From: "Mark D. Normand" <mnormand at foodsci.umass.edu>
- Date: Tue, 10 Sep 2002 06:24:47 -0400 (EDT)
- Organization: UMass. Dept. of Food Science
- Reply-to: mnormand at foodsci.umass.edu
- Sender: owner-wri-mathgroup at wolfram.com
Subject: [mg36515] Possible Mathematica error It seems there is an error in the BinCounts function of Mathematica's standard <<Statistics`DataManipulation` package where it sometimes returns one more than the expected number of histogram bins. An example of this is shown in the notebook code below where the comment in the last notebook cell explicitly describes the problem. If anyone can explain this behavior it would be appreciated, otherwise Wolfram Research should be made aware of this "feature" of the function when it is called as: BinCounts[{x1, x2, ...}, {xmin, xmax, dx}] Thanks in advance. Mark Normand UMass Dept. of Food Science mnormand at foodsci.umass.edu --------------------------- Notebook[{ Cell["BinCounts_error.nb.", "Text", TextAlignment->Left, FontSize->18], Cell["\<\ Sept. 9, 2002 Mark D. Normand UMass Dept. of Food Science mnormand at foodsci.umass.edu\ \>", "Text", TextAlignment->Left], Cell[CellGroupData[{ Cell["\<\ Load the Data Manipulation functions from the Statistics Standard \ Package.\ \>", "Text", TextAlignment->Left], Cell[BoxData[ \(<< Statistics`DataManipulation`\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Assign data to the vector (1D list) dat.", "Text", TextAlignment->Left], Cell[BoxData[ \(\(dat = {63, 184, 23, 14, 17, 32, 26, 666, 27, 11, 28, 53, 37, 29, 4, 60, 7, 23, 94, 18, 43, 15, 74, 42, 81, 8, 7, 19, 0, 27, 87, 35, 3, 24, 94, 42, 4, 7, 18, 7, 38, 1, 0, 61, 3, 40, 22, 8, 3, 2, 0, 2, 5, 5, 7, 0, 9, 2, 11, 13, 105, 51, 36, 149, 147, 12, 1, 1, 7, 8, 10, 1, 7, 25, 38, 142, 15, 8, 9, 16, 0, 1, 4, 3, 31, 30, 10};\)\)], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Count the number of dat data rows.", "Text", TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ \(datRows = Length[dat]\)], "Input"], Cell[BoxData[ \(87\)], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Find the minimum value in the dat data rows.", "Text", TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ \(datMin = Min[dat]\)], "Input"], Cell[BoxData[ \(0\)], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Find the maximum value in the dat data rows.", "Text", TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ \(datMax = Max[dat]\)], "Input"], Cell[BoxData[ \(666\)], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Calculate the number of histogram bins to use.", "Text", TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ \(datBins = Ceiling[Log[2, datRows]]\)], "Input"], Cell[BoxData[ \(7\)], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Set the width of a histogram bin.", "Text", TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ \(datBinWidth = N[\((datMax - datMin)\)/datBins]\)], "Input"], Cell[BoxData[ \(95.14285714285714`\)], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Histogram the data in the dat list.", "Text", TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ \(datHist = BinCounts[dat, {datMin, datMax, datBinWidth}]\)], "Input"], Cell[BoxData[ \({76, 5, 0, 0, 0, 0, 0, 1}\)], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["\<\ For the above dat list, if datBins equals, for example, 5,7,10,14 \ or15 then the number of elements in the list datHist (the ACTUAL number of \ histogram bins generated) is one more than the assigned datBins value. Yet \ datHist equals datBins if datBins is assigned, for example, 6, 8, 9, 11, 13 \ or 16. Why!? (Is this a bug?)\ \>", "Text", TextAlignment->Left], Cell[CellGroupData[{ Cell[BoxData[ \(actualBins = Length[datHist]\)], "Input"], Cell[BoxData[ \(8\)], "Output"] }, Open ]] }, Open ]] }, FrontEndVersion->"4.0 for Macintosh", ScreenRectangle->{{0, 1024}, {0, 748}}, CellGrouping->Manual, WindowSize->{520, 626}, WindowMargins->{{-1, Automatic}, {Automatic, -1}}, MacintoshSystemPageSetup->"\<\ 0080001804P000000_82@?okonh34`9B;@<5:0?l00;m009H0UP0000068dB`0B` 02d5X5k/02H80@4101P00BL?00400@00000000000000P0010000020D00000000 0000000000000000000004T400002004\>" ]