Born2Smile's answer, bin(x)=width*floor(x/width), incorrectly maps it to 1.this function correctly maps it to the centre of the left bin (0.75).the value 1.1 truly falls in the left bin: Width = (Max-Min)/n # binwidth evaluates to 1.0īin(x) = width*(floor((x-Min)/width)+0.5) + MinĮ.g. Then 'floor' the result to go to the left-hand edge of that bin, add 0.5 to go to the middle of the bin, multiply by the width so that you're no longer working in units of bins but in an absolute scale again, then finally add back on the Min offset you subtracted at the start.Ĭonsider this function in action: Min = 0.25 # where binning starts Then divide by binwidth so that you're effectively working in units of 'bins'. Subtract Min from your data point to see how far into the binning range it is. You can see why this is correct sequentially (it helps to draw a few bins and a point somewhere in one of them). With an arbitrary starting point for binning 'Min', the correct function is: bin(x) = width*(floor((x-Min)/width)+0.5) + Min If the user is combining any of these functions for binning data with his/her own decision about where binning starts (as is done on the blog which is linked to above) the functions above are all incorrect. Be very careful: all of the answers on this page are implicitly taking the decision of where the binning starts - the left-hand edge of the left-most bin, if you like - out of the user's hands.
0 Comments
Leave a Reply. |