Library: | smoother |
See also: | bindata binweights |
Quantlet: | binlindata | |
Description: | linear binning for univariate data, given the binwidth and optionally the origin of the bin grid. The smallest grid with width d that covers the data is found and the data are binned to this grid using the linear binning rule. |
Usage: | {bing, binc} = binlindata(x, d{, orig}) | |
Input: | ||
x | n x 1 vector, the data to be binned | |
d | optional scalar (d > 0), representing the binwidth | |
orig | optional scalar, corresponds to the origin of the bingrid, default = 0. | |
Output: | ||
bing | m x 1 vector, the equidistant bingrid | |
binc | m x 1 vector, the bincounts at the grid points |
library("smoother") library("xplore") n = 6000 {w,mu,sigma}=normalmixselect("Marron_Wand_6") x = normalmix(n,w,mu,sigma) x = round(x,1) d = 0.1 {bing, binc} = binlindata(x, d) bing~round(binc,12)
Generates 6000 variates from a normal mixture example distribution, rounds them, and bins them to a grid. The bin grid and the corresponding bin counts are shown. Note that the bin counts are integers when data are rounded by round(x,1). This is done to get rid of floating point inaccuracies and they sum up to the total sample size. If the data are not rounded (i.e. x = round(x,1) is commented out) then the bin counts are no longer integers but still sum up to the total sample size.