FREQTABLE Function
Tallies observations into a one-way or two-way frequency table.
Usage
result = FREQTABLE(x, nxbins[, y, nybins])
Input Parameters
x—One-dimensional array containing the observations for the first variable.
nxbins—Number of intervals (bins) for x.
y—(Optional) One-dimensional array containing the observations for the second variable.
nybins—(Optional) Number of intervals (bins) for y.
Returned Value
result—One-dimensional or two-dimensional array containing the counts.
Input Keywords
Double—If present and nonzero, double precision is used.
IF Two Positional Arguments Are Used:
Lower_Bound—Used with Upper_Bound to specify two semi-infinite intervals that are used as the initial and last interval. The initial interval is closed on the right and includes Lower_Bound as its right endpoint. The last interval is open on the left and includes all values greater than Upper_Bound. The remaining nxbins − 2 intervals are of length. (Upper_Bound – Lower_Bound)/(nxbins – 2) and are open on the left and closed on the right. The keyword Upper_Bound also must be specified with this keyword. Parameter nxbins must be greater than or equal to 3 for this option.
Upper_Bound—Used along with Lower_Bound to specify two semi-infinite intervals that are used as the initial and last interval. The initial interval is closed on the right and includes Lower_Bound as its right endpoint. The last interval is open on the left and includes all values greater than Upper_Bound. The remaining nxbins − 2 intervals are of length (Upper_Bound – Lower_Bound)/( nxbins – 2)and are open on the left and closed on the right. Lower_Bound must also be specified with this keyword. Parameter nxbins must be greater than or equal to 3 for this option.
Cutpoints—Specifies a one-dimensional array of length nxbins containing the cutpoints to use. This option allows unequal intervals. The initial interval is closed on the right and contains the initial cutpoint as its right endpoint. The last interval is open on the left and includes all values greater than the last cutpoint. The remaining nxbins − 2 intervals are open on the left and closed on the right. Parameter nxbins must be greater than 3 for this option. If Cutpoints is used, no other keywords should be specified.
Class_Marks—Specifies a one-dimensional array containing equally spaced class marks in ascending order. The class marks are the midpoints of each of the nxbins, and each interval is taken to have length (Class_Marks(1) – Class_Marks(0)). Parameter nxbins must be greater than or equal to 2 for this option. If Class_Marks is used, then no other keywords should be specified.
If Four Positional Arguments Are Used:
Lower_Bound—Used with Upper_Bound to specify intervals of equal lengths. See the Discussion section for details.
Upper_Bound—Used with Lower_Bound to specify intervals of equal lengths. See the Discussion section for details.
Cutpoints—Specifies a one-dimensional array of cutpoints (boundaries). Cutpoints must be a one-dimensional array of length
(nxbins – 1) + (nybins – 1) containing the cutpoints for x in the first (nxbins–1) elements followed by the cutpoints for y in the final (nybins–1) elements.
Class_Marks—Specifies a one-dimensional array containing equally spaced class marks in ascending order. The class marks are the midpoints of each interval. The keyword Class_marks must be a one-dimensional array of length (nxbins + nybins) containing the class marks for x in the first nxbins elements followed by the class marks for y in the final nybins elements.
Discussion
If Two Positional Arguments Are Used:
The default action of FREQTABLE is to group data into nxbins categories of size (max (x) – min (x))/nxbins. The initial interval is closed on the left and open on the right. The remaining intervals are open on the left and closed on the right. Using keywords, the types of intervals used may be changed.
If Upper_Bound and Lower_Bound are specified, two semi-infinite intervals are used as the initial and last interval. The initial interval is closed on the right and includes Lower_Bound as its right endpoint. The last interval is open on the left and includes all values greater than Upper_Bound. The remaining nxbins – 2 intervals are of length (Upper_Bound – Lower_Bound)/(nxbins – 2) and are open on the left and closed on the right. Parameter nxbins must be greater than or equal to 3 for this option.
If keyword Class_Marks is used, equally spaced class marks in ascending order must be provided in an array of length nxbins. The class marks are the midpoints of each of the nxbins, and each interval is taken to have the following length:
(Class_Marks(1) – Class_Marks(0))
Parameter nxbins must be greater than or equal to 2 for this option.
If keyword Cutpoints is used, cutpoints (bounders) must be provided in an array of length nxbins. This option allows unequal intervals. The initial interval is closed on the right and contains the initial cutpoint as its right endpoint. The last interval is open on the left and includes all values greater than the last cutpoint. The remaining nxbins − 2 intervals are open on the left and closed on the right. Parameter nxbins must be greater than 3 for this option.
If Four Positional Arguments Are Used:
By default, nxbins intervals of equal length are used. Let xmin and xmax be the minimum and maximum values in x, respectively, with similar meanings for ymin and ymax. Then, table(0, 0) is the tally of observations with the x value less than or equal to xmin + (xmax–xmin)/nxbins, and the y value less than or equal to ymin + (ymax–ymin)/ny.
If Upper_Bound and Lower_Bound are specified, intervals of equal lengths are used just as in the default case, except the upper and lower bounds are taken as the user supplied keywords xmin = Lower_bound(0), xmax = Upper_bound(0), ymin = Lower_bound(1), and ymax = Upper_bound(1), instead of the actual minima and maxima in the data. Therefore, the first and last intervals for both variables are semi-infinite in length.
If Cutpoints is specified, cutpoints (boundaries) must be provided. The keyword Cutpoints must be a one-dimensional array of length (nxbins – 1) + (nybins – 1) containing the cutpoints for x in the first (nxbins–1) elements followed by the cutpoints for y in the final (nybins–1) elements.
If Class_marks is specified, equally spaced class marks in ascending order must be provided. The class marks are the midpoints of each interval. The keyword Class_marks must be a one-dimensional array of length (nxbins + nybins) containing the class marks for x in the first nxbins elements followed by the class marks for y in the final nybins elements.
Example 1: One-way Frequency Table
The data for this example is from Hinkley (1977) and Velleman and Hoaglin (1981). Data includes measurements (in inches) of precipitation in Minneapolis/St. Paul during the month of March for 30 consecutive years.
; Define the data set.
x = [0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43, 3.37, 2.20, $
3.00, 3.09, 1.51, 2.10, 0.52, 1.62, 1.31, 0.32, 0.59, 0.81, $
2.81, 1.87, 1.18, 1.35, 4.75, 2.48, 0.96, 1.89, 0.90, 2.05]
; Call FREQTABLE with nxbins = 10.
table = FREQTABLE(x, 10)
PRINT, ' Bin Number Count' &$
PRINT, ' ---------- -----' &$
FOR i=0L, 9 DO PRINT, i + 1, table(i)
This results in the following output:
Bin Number Count
---------- -----
1 4.00000
2 8.00000
3 5.00000
4 5.00000
5 3.00000
6 1.00000
7 3.00000
8 0.00000
9 0.00000
10 1.00000
Example 2: Two-way Frequency Table
The data for x in this example is the same as in the example above. The data for y were created by adding small integers to x.
nxbins = 5
nybins = 6
; Define the data set.
x = [0.77, 1.74, 0.81, 1.20, 1.95, 1.20, 0.47, 1.43, 3.37, $
2.20, 3.00, 3.09, 1.51, 2.10, 0.52, 1.62, 1.31, 0.32, $
0.59, 0.81, 2.81, 1.87, 1.18, 1.35, 4.75, 2.48, 0.96, $
1.89, 0.90, 2.05]
y = [1.77, 3.74, 3.81, 2.20, 3.95, 4.20, 1.47, 3.43, 6.37, $
3.20, 5.00, 6.09, 2.51, 4.10, 3.52, 2.62, 3.31, 3.32, $
1.59, 2.81, 5.81, 2.87, 3.18, 4.35, 5.75, 4.48, 3.96, $
2.89, 2.90, 5.05]
; Default usage of FREQTABLE
table = FREQTABLE(x, nxbins, y, nybins)
PM, table, Format = '(6(F8.5, 2X))', $
Title = ' counts'
; PV-WAVE prints the following:
; counts
; 4.00000 2.00000 4.00000 2.00000 0.00000 0.00000
; 0.00000 4.00000 3.00000 2.00000 1.00000 0.00000
; 0.00000 0.00000 1.00000 2.00000 0.00000 1.00000
; 0.00000 0.00000 0.00000 0.00000 1.00000 2.00000
; 0.00000 0.00000 0.00000 0.00000 0.00000 1.00000
lb = [1, 2]
up = [4, 6]
; Using user-defined bounds
table = FREQTABLE(x, nxbins, y, nybins, Upper_Bound = up, $
Lower_Bound = lb)
PM, table, Format = '(6(F8.5, 2X))', $
Title = ' counts'
; PV-WAVE prints the following:
; counts
; 3.00000 2.00000 4.00000 0.00000 0.00000 0.00000
; 0.00000 5.00000 5.00000 2.00000 0.00000 0.00000
; 0.00000 0.00000 1.00000 3.00000 2.00000 0.00000
; 0.00000 0.00000 0.00000 0.00000 0.00000 2.00000
; 0.00000 0.00000 0.00000 0.00000 1.00000 0.00000
cm = [0.5, 1.5, 2.5, 3.5, 4.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5]
; Using class-marks
table = FREQTABLE(x, nxbins, y, nybins, Class_Marks = cm)
PM, table, Format = '(6(F8.5, 2X))', $
Title = ' counts'
; PV-WAVE prints the following:
; counts
3.00000 2.00000 4.00000 0.00000 0.00000 0.00000
0.00000 5.00000 5.00000 2.00000 0.00000 0.00000
0.00000 0.00000 1.00000 3.00000 2.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 2.00000
0.00000 0.00000 0.00000 0.00000 1.00000 0.00000
cp = [1, 2, 3, 4, 2, 3, 4, 5, 6]
; Using cutpoints
table = FREQTABLE(x, nxbins, y, nybins, Cutpoints = cp)
PM, table, Format = '(6(F8.5, 2X))', $
Title = ' counts'
; PV-WAVE prints the following:
; counts
; 3.00000 2.00000 4.00000 0.00000 0.00000 0.00000
; 0.00000 5.00000 5.00000 2.00000 0.00000 0.00000
; 0.00000 0.00000 1.00000 3.00000 2.00000 0.00000
; 0.00000 0.00000 0.00000 0.00000 0.00000 2.00000
; 0.00000 0.00000 0.00000 0.00000 1.00000 0.00000