Creates an histogram
h=distfun_histocreate("data",data) h=distfun_histocreate("data",data,nbins) h=distfun_histocreate("data",data,nbins,binmethod) h=distfun_histocreate("pdf",edges,heights)
a 1-by-m or m-by-1 matrix of doubles, the observations
a 1-by-1 matrix of doubles, the number of bins (default is Scott rule). If nbins is not a scalar, it contains the edges of the classes, in increasing order.
a 1-by-1 matrix of strings, the binning method. Must be "scott" (default), "sturges" or "integers".
a (nbins+1)-by-1 matrix of doubles, the edges of the classes, in increasing order.
a nbins-by-1 matrix of doubles, the height of each class.
an histogram object
distfun_histocreate("data",...) creates the histogram object associated with the data.
distfun_histocreate("pdf",...) creates the histogram object associated with the given edges and heights.
The h object can then be passed to the distfun_histo* functions to manage the corresponding histogram.
If nbins is not provided, compute automatically the number of bins and the edges from the data.
If binmethod=="scott", the bin width is h=3.5*sigma/(m**(1/3)). This is a good choice for normal data.
If binmethod=="sturges", the number of bins is nbins=ceil(log2(m)+1).
If binmethod=="integers", the bins width is 1.
The bins are chosen so that each bin contains at least one observation. This allows to invert the CDF and prevents errors from the dsearch function.
Implementation notes
The algorithm is the following. We computes the number of classes and the edges of the histogram classes, with equal widths. Then we compute the number of observations in each bin. The pdf and the cdf of the histogram is then computed according to the number of observations in each bin.