A reduction operator is a statistical operation (for example, a sum or a mean) that returns a matrix of a smaller dimension. Reduction operators are often encountered in frequency tables: the marginal frequencies represent the sum of the frequencies across rows or down columns.
In SAS/IML software, you can use reduction operators in place of values for subscripts to get reductions across all rows or columns. Table 5.3 lists operators for subscript reduction.
Table 5.3: Subscript Reduction Operators
Operator |
Description |
---|---|
|
Addition |
|
Multiplication |
|
Maximum |
|
Minimum |
|
Index of maximum |
|
Index of minimum |
|
Mean |
|
Sum of squares |
For example, to get row sums of a matrix X
, you can sum across the columns with the syntax X[,+]
. Omitting the first subscript specifies that the operator apply to all rows. The second subscript (+) specifies that summation
reduction take place across the columns. The elements in each row are added, and the new matrix consists of one column that
contains the row sums.
To give a specific example, consider the coffee data from earlier in the chapter. The following statements use the summation reduction operator to compute the sums for each row:
coffee={4 2 2 3 2, 3 3 1 2 1, 2 1 0 2 1, 5 4 4 3 4}; names={Jenny, Linda, Jim, Samuel}; mattrib coffee rowname=names colname={'MON' 'TUE' 'WED' 'THU' 'FRI'}; Total = coffee[,+]; print coffee Total;
Figure 5.30: Summation across Columns to Find the Row Sums
You can use these reduction operators to reduce the dimensions of rows, columns, or both. When both rows and columns are reduced, row reduction is done first.
For example, the expression results in the maximum of the column sums .
You can repeat reduction operators. To get the sum of the row maxima, use the expression , or, equivalently, .
A subscript such as first selects the second and third rows of and then finds the row sums of that submatrix.
The following examples demonstrate how to use the operators for subscript reduction. Consider the following matrix:
The following statements are true: