FREQ

Tallies multivariate observations into a multiway frequency table.

Required Arguments

XNOBS by NCOL matrix containing the data. (Input)

INDCL — Index vector of length NCLVAR containing the column numbers in X that are the classification variables. (Input)

MAXTAB — An upper bound for the total number of cells in the frequency table. (Input)
This is the product of the number of distinct values taken by all of the classification variables since the table includes the empty cells.

MAXCL — An upper bound for the sum of the number of distinct values taken by all of the classification variables. (Input)

NCLVAL — Vector of length NCLVAR containing, in its i-th element, the number of levels or categories of the i-th classification variable. (Output, if IDO = 1; Input/Output, if IDO = 2.)
Each variable must have more than one level.

CLVAL — Vector of length NCLVAL(1) + NCLVAL(2) +  + NCLVAL(NCLVAR) containing the values of the classification variables. (Output, if IDO= 1; input/output, if
IDO = 2.)
Since in general the length of CLVAL will not be known in advance, MAXCL is an upper bound for this length. The first NCLVAL(1) elements of CLVAL contain the values for the first classification variable. The next NCLVAL(2) contain the values for the second variable. The last NCLVAL(NCLVAR) positions contain the values for the last classification variable.

TABLE — Vector of length NCLVAL(1) * NCLVAL(2) *  * NCLVAL(NCLVAR) containing the frequencies in the cells of the table to be fit. (Output, if IDO = 1; input/output, if IDO = 2) Since, in general, the length of TABLE will not be known in advance, MAXTAB is an upper bound for this length. Empty cells are included in TABLE, and each element of TABLE is nonnegative. The cells of TABLE are sequenced so that the first variable cycles from 1 to NCLVAL(1) one time, the second variable cycles from 1 to NCLVAL(2) NCLVAL(1) times, and so on, up to the NCLVAR-th variable, which cycles from 1 to NCLVAL(NCLVAR) most rapidly (NCLVAL(1) * NCLVAL(2) *  * NCLVAL(NCLVAR   1) times). That is to say, the second element of TABLE is the count for the first value for each classification variable except the last one and the second value of the last classification variable (assuming that variable takes more than one distinct value).

Optional Arguments

IDO — Processing option. (Input)
Default: IDO = 1.

IDO

Action

1

This is the first (or the only) invocation of FREQ for this data set. Initialization and updating for the data in X are performed.

2

This is an additional invocation of FREQ, and updating for the data in X is performed.

NOBS — Number of observations. (Input)
Default: NOBS = size (X,1).

NCOL — Number of columns in X. (Input)
Default: NCOL = size (X,2).

LDX — Leading dimension of X exactly as specified in the dimension statement in the calling program. (Input)
Default: LDX = size (X,1).

IFRQ — Frequency option. (Input)
IFRQ = 0 means that all frequencies are 1.0. For positive IFRQ, column number IFRQ of X contains the frequencies.
Default: IFRQ = 0.

NCLVAR — Number of classification variables. (Input)
NCLVAR must be greater than one.
Default: NCLVAR = size (INDCL,1).

FORTRAN 90 Interface

Generic: CALL FREQ (X, INDCL, MAXTAB, MAXCL, NCLVAL, CLVAL, TABLE [])

Specific: The specific interface names are S_FREQ and D_FREQ.

FORTRAN 77 Interface

Single: CALL FREQ (IDO, NOBS, NCOL, X, LDX, IFRQ, NCLVAR, INDCL, MAXTAB, MAXCL, NCLVAL, CLVAL, TABLE)

Double: The double precision name is DFREQ.

Description

The routine FREQ determines the distinct values in multivariate data and computes frequencies for the data. The routine accepts the data in the matrix X, but performs computations only for the variables (columns) in X specified in INDCL. In general, the variables for which frequencies should be computed are discrete; that is, they should take on a relatively small number of different values. Variables that are continuous can be grouped first.

The routine OWFRQ or TWFRQ can be used to group variables and determine the frequencies of groups. The routine FREQ fills the vector CLVAL with the unique values of the variables and tallies the number of unique values of each variable in the vector NCLVAL. Each combination of one value from each variable forms a cell in a multiway table. The frequencies of these cells are entered in TABLE so that the first variable cycles through its values exactly once and the last variable cycles through its values most rapidly. Some cells may not correspond to any observation in the data; that is, “missing cells” are included and have 0’s in TABLE.

The length of the vectors CLVAL and TABLE depend on the data. The parameters MAXCL and MAXTAB are used as checks that the arrays sizes are not exceeded.

Comments

1. Workspace may be explicitly provided, if desired, by use of F2EQ/DF2EQ. The reference is

CALL F2EQ (IDO, NOBS, NCOL, X, LDX, IFRQ, NCLVAR, INDCL, MAXTAB, MAXCL, NCLVAL, CLVAL, TABLE, IWK, WK)

The additional arguments are as follows:

IWK — Workspace of length NCLVAR.

WK — Workspace of length NCLVAR.

2. Informational errors

Type

Code

Description

4

1

MAXCL is too small. Increase the length of CLVAL.

4

2

MAXTAB is too small. Increase the length of TABLE.

Example

The data for this example are taken from the examples used in routine TWFRQ, but modified so that the values of all points within a given interval of Example 2 for TWFRQ are exactly equal to the class mark for that interval. The results from this example, therefore, are the same as for Example 2 for TWFRQ, except that TABLE is a vector. (The elements of the vector are sequenced as the columns of the matrix.)

 

USE FREQ_INT

USE UMACH_INT

 

IMPLICIT NONE

INTEGER LDX, MAXCL, MAXTAB, NCLVAR, NCOL, J

PARAMETER (LDX=30, MAXCL=15, MAXTAB=40, NCLVAR=2, NCOL=2)

!

INTEGER I, INDCL(NCLVAR), NCLVAL(NCLVAR), NOUT, &

NVAL1, NVAL2

REAL CLVAL(MAXCL), TABLE(MAXTAB), X(LDX,NCOL)

!

DATA X/0.50, 1.50, 0.50, 1.50, 1.50, 1.50, 0.50, 1.50, 3.50, &

2.50, 2.50, 3.50, 1.50, 2.50, 0.50, 1.50, 1.50, 0.50, &

0.50, 0.50, 2.50, 1.50, 1.50, 1.50, 4.50, 2.50, 0.50, &

1.50, 0.50, 2.50, &

1.50, 3.50, 3.50, 2.50, 3.50, 4.50, 1.50, 3.50, 6.50, &

3.50, 4.50, 6.50, 2.50, 4.50, 3.50, 2.50, 3.50, 3.50, &

1.50, 2.50, 5.50, 2.50, 3.50, 4.50, 5.50, 4.50, 3.50, &

2.50, 2.50, 5.50/

!

CALL UMACH (2, NOUT)

INDCL(1) = 1

INDCL(2) = 2

CALL FREQ (X, INDCL, MAXTAB, MAXCL, NCLVAL, CLVAL, TABLE)

NVAL1 = NCLVAL(1)

NVAL2 = NCLVAL(2)

WRITE (NOUT,99999) (CLVAL(J),J=NVAL1+1,NVAL1+NVAL2), &

(CLVAL(I),(TABLE((I-1)*NVAL2+J),J=1,NVAL2),I=1,NVAL1)

99999 FORMAT (' Frequencies for All Combinations of Values', /, &

8X,6F7.2,/,5(F7.2,6F7.0,/))

END

Output

 

Frequencies for All Combinations of Values

1.50 2.50 3.50 4.50 5.50 6.50

0.50 3. 2. 4. 0. 0. 0.

1.50 0. 5. 5. 2. 0. 0.

2.50 0. 0. 1. 3. 2. 0.

3.50 0. 0. 0. 0. 0. 2.

4.50 0. 0. 0. 0. 1. 0.