Statistics - Maple Programming Help

Home : Support : Online Help : Graphics : Statistics : Statistics/Histogram

Statistics

 Histogram
 generate histograms

 Calling Sequence Histogram(X, options, plotoptions) Histogram['interactive'](X)

Parameters

 X - options - (optional) equation(s) of the form option=value where option is one of averageshifted, binbounds, bincount, binwidth, color, discrete, frequencyscale, ignore, maxbins, minbins, or range; specify options for generating the frequency plot plotoptions - options to be passed to the plots[display] command

Description

 • The Histogram command generates a histogram for the specified data. Ordinary and average shifted histograms are supported. An average shifted histogram is obtained by calculating $m$ histograms with the same binwidth $w$, shifting them by $\frac{w}{m}$ and taking the average. Average shifted histograms are smoother than ordinary histograms and are less dependent on the choice of the origin.
 • The first parameter X is a single data sample, given as e.g. a Vector.
 • If the ['interactive'] option is used, then a dialog box appears that allows for customized creation of the plot.

Options

 The options argument can contain one or more of the options shown below. All unrecognized options will be passed to the plots[display] command. See plot[options] for details.
 • discrete=truefalse
 If discrete is set to true, the Histogram command will tally the data and plot each data point with the corresponding frequency.  The default value is false. If discrete = true, then the averageshifted, binbounds, bincount, binwidth, maxbins, and minbins options are ignored.
 • averageshifted=posint
 This option specifies how many frequency plots are used to compute the average. The default value is 1. Values other than 1 are only compatible with binbounds = deduce (the default value for that option).
 • frequencyscale=relative or absolute
 This option controls whether the absolute or relative data frequencies should be plotted. If frequencyscale is set to relative (the default) then the area of each bar is proportional to the number of data points in the corresponding bin. If the bins are equally wide, then the height of the bars is also proportional to the number of data points in the bin. Furthermore, the histogram is rescaled so that the total area of the bars is equal to 1.
 If, on the other hand, frequencyscale = absolute is specified, then the height of each bar is the exact number of data points in the bin. In this case, if the bins are not equally wide, then the area of the bars is not proportional to the number of data points in the corresponding bins.
 • binbounds=proportional or list or quantiles(...) or quartiles(...) or deciles(...) or percentiles(...) or deduce
 This option specifies the bounds for each of the bins.
 • binbounds = deduce (the default) specifies that the bins should be equally wide and determined by the bincount, binwidth, maxbins, minbins, and range options. All other values of binbounds override all of these options, unless mentioned otherwise below. This is the only value for binbounds that is compatible with averageshifted being different from 1.
 • binbounds = [x0, x1, ..., xn] with x0 < x1 < ... < xn specifies that numbers given in the list are the boundaries between the bins. So binbounds = [x0, x1, x2, x3] would specify three bins: from x0 to x1, from x1 to x2, and from x2 to x3. Instead of a list, you can also specify a Vector or other 1-dimensional rtable.
 • binbounds = quantiles(x0, x1, ..., xn) with 0 <= x0 < x1 < ... < xn <= 1 is equivalent to specifying the list $\left[\mathrm{Quantile}\left(X,\mathrm{x0}\right),\mathrm{Quantile}\left(X,\mathrm{x1}\right),\mathrm{...},\mathrm{Quantile}\left(X,\mathrm{xn}\right)\right]$. See the Quantile help page for details. If the option ignore=true is specified, then it is also passed to the Quantile command.
 • binbounds = quartiles(x0, x1, ..., xn) or deciles(x0, x1, ..., xn) or percentiles(x0, x1, ..., xn) is similar to quantiles(x0, x1, ..., xn), except the commands used are Quartile, Decile, and Percentile, respectively, instead of Quantile.
 • binbounds = proportional determines the bin count in the same way as binbounds = deduce, resulting in, say, $n$ bins. It then proceeds as binbounds = quantiles(0, 1/n, 2/n, ..., 1). Consequently, every bin has roughly the same number of data points in it.
 • range=deduce or range
 The default value is deduce and all available data will be used to generate the histogram.  If a range is specified, all data points outside the given range will be ignored.
 • bincount=positive or deduce
 This option controls the number of bins for the histogram. If the number of bins is explicitly specified through this option, the maxbins, minbins, and binwidth options will be ignored.
 • binwidth=positive, Sturges, Scott, or FreedmanDiaconis
 This option controls the bin width (and consequently the number of bins) for the histogram. The bin width can be either specified explicitly (which overrides the maxbins and minbins options) or can be calculated using one of three methods: Sturges, Scott, or FreedmanDiaconis. The default value is Sturges.
 • maxbins=posint
 This option specifies the maximum number of bins in a histogram. If the computed bin width is too small, it will be increased. The default is 500.
 • minbins=posint
 This option specifies the minimum number of bins in a histogram. If the computed bin width is too large, it will be decreased. The default is 30.
 • color=name, list, or range
 This option specifies the color of the histogram. When a list or range of colors is given, the first color is used.
 • ignore=truefalse
 This option is used to specify how to handle non-numeric data. If ignore is set to true all non-numeric items in X will be ignored.  The default is false.

Examples

 > $\mathrm{with}\left(\mathrm{Statistics}\right):$
 > $N≔\mathrm{RandomVariable}\left(\mathrm{Normal}\left(0,1\right)\right):$
 > $A≔\mathrm{Sample}\left(N,1000\right):$
 > $P≔\mathrm{DensityPlot}\left(\mathrm{Normal}\left(0,1\right),\mathrm{color}="Niagara Red"\right):$
 > $Q≔\mathrm{Histogram}\left(A,\mathrm{averageshifted}=4,\mathrm{style}=\mathrm{polygon},\mathrm{color}="LightSlateGrey"\right):$

By default frequencyscale is set to relative.

 > $\mathrm{plots}[\mathrm{display}]\left(P,Q\right)$

Ordinary histogram.

 > $\mathrm{Histogram}\left(A\right)$

Varying bin width histogram. In this case, each bar has approximately the same area.

 > $\mathrm{Histogram}\left(A,\mathrm{binbounds}=\mathrm{proportional}\right)$

Varying bin width histogram with absolute frequency scale. In this case, each bar is approximately equally high and the density of data points is represented by the width. This type of histogram is sometimes called an equi-depth histogram.

 > $\mathrm{Histogram}\left(A,\mathrm{binbounds}=\mathrm{proportional},\mathrm{bincount}=10,\mathrm{frequencyscale}=\mathrm{absolute}\right)$

One can find the number of elements in each bin from a similar computation using the TallyInto command.

 > $\mathrm{TallyInto}\left(A,\mathrm{default},\mathrm{bins}=5\right)$
 $\left[{-}{2.71396014591046}{..}{-}{1.57809021633834}{=}{47}{,}{-}{1.57809021633834}{..}{-}{0.442220286766215}{=}{261}{,}{-}{0.442220286766215}{..}{0.693649642805906}{=}{423}{,}{0.693649642805906}{..}{1.82951957237803}{=}{231}{,}{1.82951957237803}{..}{2.96538950195015}{=}{38}\right]$ (1)
 > $U≔\mathrm{RandomVariable}\left(\mathrm{Geometric}\left(\frac{1}{3}\right)\right)$
 ${U}{≔}{\mathrm{_R1}}$ (2)
 > $B≔\mathrm{Sample}\left(U,500\right)$
 ${B}{≔}\left[\begin{array}{c}{\mathrm{1 .. 500}}{\mathrm{Vector}}{[}{\mathrm{row}}{]}\\ {\mathrm{Data Type:}}{\mathrm{float}}{[}{8}{]}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{Fortran_order}}\end{array}\right]$ (3)
 > $\mathrm{Histogram}\left(B\right)$
 > $\mathrm{Histogram}\left(B,\mathrm{discrete}=\mathrm{true}\right)$

The following call to Histogram will produce an error.

 > $\mathrm{Histogram}\left(\left[1,2,3,\mathrm{undefined}\right]\right)$

Use option ignore to ignore undefined values.

 > $\mathrm{Histogram}\left(\left[1,2,3,\mathrm{undefined}\right],\mathrm{ignore}\right)$

The command to create the plot from the Plotting Guide is

 > $\mathrm{Histogram}\left(A,\mathrm{frequencyscale}=\mathrm{absolute}\right)$

Compatibility

 • The binbounds option was introduced in Maple 16.