TWFRQ
Tallies observations into a two-way frequency table.
Required Arguments
X — Vector of length NOBS containing the data for one variable. (Input)
Y — Vector of length NOBS containing the data for the other variable. (Input)
KX — Number of intervals for the variable X. (Input)
KY — Number of intervals for the variable Y. (Input)
TABLE — KX by KY matrix containing the counts. (Output)
Optional Arguments
NOBS — Number of observations. (Input)
Default: NOBS = size (X,1).
IOPT — Tallying option. (Input)
Default: IOPT = 0.
IOPT | Action |
---|
0 | Intervals of equal lengths for each variable, determined from the data, are used. Let XMIN and XMAX be the minimum and maximum values in X, respectively, with similar meanings for YMIN and YMAX. Then, TABLE(1, 1) is the tally of observations with the X value less than or equal to XMIN + (XMAX ‑ XMIN)/KX, and the Y value less than or equal to YMIN + (YMAX ‑ YMIN)/KY. The other table entries are determined similarly. |
1 | Intervals of equal lengths are used just as in the case of IOPT = 0, except the upper and lower bounds are taken as the user-supplied variables XLO, XHI, YLO, and YHI instead of the actual minima and maxima in the data. Therefore, the first and the last intervals for both variables are semi-infinite in length. KX and KY must be greater than 2. |
2 | KX ‑ 1 cutpoints are input in DIVX, and KY ‑ 1 cutpoints are input in DIVY. The tally in TABLE(1, 1) is the number of observations for which the X value is less than or equal to DIVX(1), and the Y value is less than or equal to DIVY(1). For I greater than 1 and less than KX and J greater than 1 and less than KY, the tally in TABLE(I, J) is the number of observations with X greater than DIVX(I ‑ 1) and less than or equal to DIVX(I) and with Y greater than DIVY(J ‑ 1) and less than or equal to DIVY(J). The tally in TABLE(KX, KY) is the number of observations for which the X value is greater than DIVX(KX ‑ 1) and the Y value is greater than DIVY(KY ‑ 1). KX and KY must be greater than 1. |
3 | Class marks are input in DIVX and DIVY and a constant class half-width are input in CLHWX and CLHWY. The total of the elements in TABLE may be less than NOBS. The tally in TABLE(I, J) is the number of observations with X value between DIVX(I) ‑ CLHWX and DIVX(I) + CLHWX, and with Y value between DIVY(J) ‑ CLHWY and DIVY(J) + CLHWY. |
XLO — If IOPT = 1, XLO is the lower bound at which to begin forming the class intervals for X. (Input)
XLO is only used if IOPT = 1.
YLO — If IOPT = 1, YLO is the lower bound at which to begin forming the class intervals for Y. (Input)
YLO is only used if IOPT = 1.
XHI — If IOPT = 1, XHI is the upper bound to use in forming the class intervals for X. (Input)
XHI is only used if IOPT = 1.
YHI — If IOPT = 1, is the upper bound to use in forming the class intervals for Y. (Input)
YHI is only used if IOPT = 1.
CLHWX — If IOPT = 3, CLHWX is the half-width of the class intervals for X. (Input)
CLHWX is only used if IOPT = 3.
CLHWY —If IOPT = 3, CLHWY is the half-width of the class intervals for Y. (Input)
CLHWY is only used if IOPT = 3.
DIVX — Vector of varying length and contents depending on IOPT. (Input if IOPT= 2 or 3; output if IOPT = 0 or 1)
The contents of DIVX are in ascending order.
IOPT | Contents |
---|
0 | DIV is of length KX containing interval midpoints for the X variable. (DIVX is output.) |
1 | DIV is of length KX containing interval midpoints for the X variable. Since the first and last intervals are semi-infinite in length, DIVX(1) contains XLO ‑ half the interval length, and DIV(KX) contains XHI + half the interval length. (DIVX is output.) |
2 | DIVX is a vector of length KX ‑ 1 containing cutpoints. (DIVX is input.) |
3 | DIVX is of length KX containing classmarks. (DIVX is input.) |
DIVY — Vector of varying length and contents depending on
IOPT. (Input if
IOPT= 2 or 3; output if
IOPT = 0 or 1)
The contents of
DIVY are in ascending order. See
DIVX.
LDTABL — Leading dimension of TABLE exactly as specified in the dimension statement in the calling program. (Input)
Default: LDTABL = size (TABLE,1).
FORTRAN 90 Interface
Generic: CALL TWFRQ (X, Y, KX, KY, TABLE [, …])
Specific: The specific interface names are S_TWFRQ and D_TWFRQ.
FORTRAN 77 Interface
Single: CALL TWFRQ (NOBS, X, Y, KX, KY, IOPT, XLO, YLO, XHI, YHI, CLHWX, CLHWY, DIVX, DIVY, TABLE, LDTABL)
Double: The double precision name is DTWFRQ.
Description
The routine
TWFRQ groups bivariate numerical data into categories, which can be defined in any of four different ways as chosen by
IOPT. This routine is very similar to routine
OWFRQ for univariate data. If
IOPT= 0,
KX intervals of equal length are formed for the first variable (in
X) between the minimum and maximum values in
X and similarly
KY intervals are formed for the second variable (in
Y). The data are then tallied in these intervals. The midpoints of the intervals for the first variable are output in
DIVX and those of the second in
DIVY.
If IOPT = 1, K ‑ 2 intervals of equal length are formed between XLO and XHI for the data in X and likewise for Y. The data are then tallied in these intervals. In this option, there is one group that consists of data less than XLO and one group of data greater than XHI. This option is similar to IOPT = 0, except in this case, the midpoints of the classes are under control of the user. The midpoints of the intervals are output in DIVX and DIVY.
For IOPT = 2 or 3, the intervals need not be equally spaced. If IOPT = 2, the intervals need not be equal in length. In this case, the intervals are defined by their boundaries, the “cutpoints”, which are input in DIVX and DIVY. The number of cutpoints is one less than the number of intervals. The first cutpoint defines the upper bound of the first interval, and the last cutpoint defines the lower bound of the last interval.
If IOPT = 3, the intervals are all of length twice CLHWX for X and twice CLHWY for Y, and they are centered on the class marks input in DIVX and DIVY. This option can be used to exclude portions of the data. The examples use all of these options with the same data set.
Examples
Example 1
The data for
X in these examples are the same as those used in the routine for one-way frequency tabulation,
OWFRQ. The data for
Y were created by adding small integers to the data in
X. In the first example, we set
IOPT = 0. This option may be appropriate if we do not know the range of the data. Notice that the midpoints of the class intervals, output in
DIVX and
DIVY, are not “pretty” numbers. Routine
WRRRN, (see
Chapter 19, “Utilities”) is used to print the frequencies. This printing routine puts column and row numbers above and to the left of the matrix being printed. For example, the “4” in the second row and second column of the output is the first number that represents a frequency. That frequency is the number of occurrences of pairs of observations in which both values are in the lowest groups.
USE TWFRQ_INT
USE UMACH_INT
USE WRRRN_INT
IMPLICIT NONE
INTEGER KX, KY, LDTABL, NOBS
PARAMETER (KX=5, KY=6, LDTABL=5, NOBS=30)
!
INTEGER NOUT
REAL DIVX(KX), DIVY(KY), TABLE(LDTABL,KY), X(NOBS), Y(NOBS)
!
DATA 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/
DATA 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/
!
CALL UMACH (2, NOUT)
!
CALL TWFRQ (X, Y, KX, KY, TABLE, DIVX=DIVX, DIVY=DIVY)
WRITE (NOUT,99999) DIVX, DIVY
99999 FORMAT (' Midpoints for X (Rows): ', 5F5.2, /, ' Midpoints ' &
, 'for Y (Columns): ', 6F5.2)
CALL WRRRN ('Frequencies', TABLE)
END
Output
Midpoints for X (Rows): 0.76 1.65 2.53 3.42 4.31
Midpoints for Y (Columns): 1.88 2.69 3.51 4.33 5.14 5.96
Frequencies
1 2 3 4 5 6
1 4.000 2.000 4.000 2.000 0.000 0.000
2 0.000 4.000 3.000 2.000 1.000 0.000
3 0.000 0.000 1.000 2.000 0.000 1.000
4 0.000 0.000 0.000 0.000 1.000 2.000
5 0.000 0.000 0.000 0.000 0.000 1.000
Example 2
In this example, we set IOPT = 1 and choose XLO, XHI, YLO, and YHI so that the intervals will be 0 to 1, 1 to 2, and so on for X, and 1 to 2, 2 to 3, and so on for Y. This means that the midpoints of the class intervals, output in DIVX and DIVY, will be 0.5, 1.5, 2.5, and so on. The “5” in the third row and fourth column of the printed output below, (i.e., the second row and the third column of the frequencies TABLE) represents five pairs of observations with the X value between 1.0 and 2.0 and the Y value between 3.0 and 4.0.
USE TWFRQ_INT
USE UMACH_INT
USE WRRRN_INT
IMPLICIT NONE
INTEGER KX, KY, LDTABL, NOBS
PARAMETER (KX=5, KY=6, LDTABL=5, NOBS=30)
!
INTEGER IOPT, NOUT
REAL DIVX(KX), DIVY(KY), TABLE(LDTABL,KY), &
X(NOBS), XHI, XLO, Y(NOBS), YHI, YLO
!
DATA 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/
DATA 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/
!
CALL UMACH (2, NOUT)
IOPT = 1
XLO = 1.0
XHI = 4.0
YLO = 2.0
YHI = 6.0
!
CALL TWFRQ (X, Y, KX, KY, TABLE, iopt=iopt, xlo=xlo, ylo=ylo, &
xhi=xhi, yhi=yhi, divx=divx, divy=divy)
WRITE (NOUT,99999) DIVX, DIVY
99999 FORMAT (' Midpoints for X (Rows): ', 5F5.2, /, ' Midpoints ' &
, 'for Y (Columns): ', 6F5.2)
CALL WRRRN ('Frequencies', TABLE)
END
Output
Midpoints for X (Rows): 0.50 1.50 2.50 3.50 4.50
Midpoints for Y (Columns): 1.50 2.50 3.50 4.50 5.50 6.50
Frequencies
1 2 3 4 5 6
1 3.000 2.000 4.000 0.000 0.000 0.000
2 0.000 5.000 5.000 2.000 0.000 0.000
3 0.000 0.000 1.000 3.000 2.000 0.000
4 0.000 0.000 0.000 0.000 0.000 2.000
5 0.000 0.000 0.000 0.000 1.000 0.000
Example 3
In this example, we input class boundaries in DIVX and DIVY. We choose the same intervals as in the example above: 0 to 1, 1 to 2, and so on. DIVX and DIVY begins with the first cutpoint between classes.
USE TWFRQ_INT
USE UMACH_INT
USE WRRRN_INT
IMPLICIT NONE
INTEGER KX, KY, LDTABL, NOBS
PARAMETER (KX=5, KY=6, LDTABL=5, NOBS=30)
!
INTEGER IOPT, NOUT
REAL DIVX(4), DIVY(5), TABLE(LDTABL,KY), X(NOBS), Y(NOBS)
!
DATA 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/
DATA 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/
DATA DIVX/1.0, 2.0, 3.0, 4.0/
DATA DIVY/2.0, 3.0, 4.0, 5.0, 6.0/
!
CALL UMACH (2, NOUT)
IOPT = 2
!
CALL TWFRQ (X, Y, KX, KY, TABLE, IOPT=IOPT, DIVX=DIVX, DIVY=DIVY)
WRITE (NOUT,99999) DIVX, DIVY
99999 FORMAT (' Cutpoints for X (Rows): ', 4F5.2, /, ' Cutpoints ' &
, 'for Y (Columns): ', 5F5.2)
CALL WRRRN ('Frequencies', TABLE)
END
Output
Cutpoints for X (Rows): 1.00 2.00 3.00 4.00
Cutpoints for Y (Columns): 2.00 3.00 4.00 5.00 6.00
Frequencies
1 2 3 4 5 6
1 3.000 2.000 4.000 0.000 0.000 0.000
2 0.000 5.000 5.000 2.000 0.000 0.000
3 0.000 0.000 1.000 3.000 2.000 0.000
4 0.000 0.000 0.000 0.000 0.000 2.000
5 0.000 0.000 0.000 0.000 1.000 0.000
Example 4
In this example, we set IOPT = 3, and set the values in DIVX, DIVY, CLHWX, and CLHWY so that the intervals will be the same as in the previous two examples.
USE TWFRQ_INT
USE UMACH_INT
USE WRRRN_INT
IMPLICIT NONE
INTEGER KX, KY, LDTABL, NOBS
PARAMETER (KX=5, KY=6, LDTABL=5, NOBS=30)
!
INTEGER IOPT, NOUT
REAL CLHWX, CLHWY, DIVX(KX), DIVY(KY), TABLE(LDTABL,KY), &
X(NOBS), Y(NOBS)
!
DATA 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/
DATA 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/
DATA DIVX/0.5, 1.5, 2.5, 3.5, 4.5/
DATA DIVY/1.5, 2.5, 3.5, 4.5, 5.5, 6.5/
!
CALL UMACH (2, NOUT)
IOPT = 3
CLHWX = 0.5
CLHWY = 0.5
!
CALL TWFRQ (X, Y, KX, KY, TABLE, IOPT=IOPT, CLHWX=CLHWX, &
CLHWY=CLHWY, DIVX=DIVX, DIVY=DIVY)
WRITE (NOUT,99999) DIVX, DIVY
99999 FORMAT (' Class marks for X (Rows): ', 5F5.2, /, ' Class ', &
'marks for Y (Columns): ', 6F5.2)
CALL WRRRN ('Frequencies', TABLE)
END
Output
Class marks for X (Rows): 0.50 1.50 2.50 3.50 4.50
Class marks for Y (Columns): 1.50 2.50 3.50 4.50 5.50 6.50
Frequencies
1 2 3 4 5 6
1 3.000 2.000 4.000 0.000 0.000 0.000
2 0.000 5.000 5.000 2.000 0.000 0.000
3 0.000 0.000 1.000 3.000 2.000 0.000
4 0.000 0.000 0.000 0.000 0.000 2.000
5 0.000 0.000 0.000 0.000 1.000 0.000