hist

Another useful utility constructs histograms. These are frequency distributions for a single variable. For example, the course utility normdist generates a list of Gaussian distributed random numbers. Suppose you wanted to reconstruct a graph of this probability distribution, based on a sample that you generated. You would make a bar graph with the x-axis representing the random number and the y-axis representing a count (integer) as follows. First you would mark off a series of equally spaced intervals on the x-axis to represent the ``bins'' of the histogram. Then you would examine each number in your sample and tally a ``one'' for the bin that that number falls into. After processing all of the numbers in this way, each bin would contain the count of the number of values in your sample that fall in that bin. This is the ``frequency'' of the occurrence of numbers in that bin. A bar graph of these frequencies is a histogram.

To see one, try this example:

normdist | hist -g | axis | xplot
 Enter mean
0
 Enter st dev
4
 How many values do you want?
1000
 Enter random number seed.
35
STOP
(In the dialog above, you type every other line. The computer gives the others.) The command line starts by running normdist, the course utility that generates the random numbers. The output is piped into hist, the course histogramming utility. The option -g tells hist to produce output in the axis style. This output is piped into the axis utility and finally into xplot to put it on your screen. The graph that emerges shows that about 280 of the 1000 values fall in the the central bin (the one around 0), and about 15 values fall in the leftmost bin.

The hist options are listed here:

*    option -n specifies number of bins            *
*    option -s specifies size of bin                *
*    option -x specifies lower and upper limits of histogram    *
*    option -g specifies output in form suitable for "graph"    *
*            or "axis"                *
*          if -g 1 we get a full bar for each bin    *
*          if -g 2 the bars don't go down to the origin    *
*    option -m specifies the line type for use with "axis"   *
So you could make the bins line up with the tick marks with the command
normdist | hist -g -s 2 -x -20 20 | axis | xplot