<< distfun_histocdf Histogram distfun_histoinv >>

Distfun >> Distfun > Histogram > distfun_histocreate

distfun_histocreate

Creates an histogram

Calling Sequence

h=distfun_histocreate("data",data)
h=distfun_histocreate("data",data,nbins)
h=distfun_histocreate("data",data,nbins,binmethod)
h=distfun_histocreate("pdf",edges,heights)

Parameters

data :

a 1-by-m or m-by-1 matrix of doubles, the observations

nbins :

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.

binmethod :

a 1-by-1 matrix of strings, the binning method. Must be "scott" (default), "sturges" or "integers".

edges :

a (nbins+1)-by-1 matrix of doubles, the edges of the classes, in increasing order.

heights :

a nbins-by-1 matrix of doubles, the height of each class.

h :

an histogram object

Description

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.

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.

Examples

m=1000; // Number of observations
data=distfun_normrnd(0,1,m,1);
h=distfun_histocreate("data",data)
// Set number of bins
nbins=5;
h=distfun_histocreate("data",data,nbins)
// Use Sturges rule
h=distfun_histocreate("data",data,[],"sturges")

// Integer data
m=1000; // Number of observations
pr=0.7;
data=distfun_geornd(pr,1,m);
h=distfun_histocreate("data",data,[],"integers")

// Histogram from edges and heights
edges=[-3.028,-1.978,-0.927,0.122,1.173,2.223,3.273];
heights=[0.0314,0.1361,0.3541,0.317,0.098,0.0152];
h=distfun_histocreate("pdf",edges,heights)

Authors


Report an issue
<< distfun_histocdf Histogram distfun_histoinv >>