CORR
(x <, method> <, excludemiss> ) ;
The CORR function computes a sample correlation matrix for data. The arguments are as follows:
specifies an numerical matrix of data. The CORR function computes a correlation matrix of the data.
specifies the method used to compute the correlation matrix. The following strings are valid:
specifies the computation of Pearson product-moment correlations. The correlations range from to . This is the default value.
specifies the computation of Hoeffding’s statistics, scaled to range between and .
specifies the computation of Kendall’s tau- coefficients based on the number of concordant and discordant pairs of observations. Kendall’s tau- ranges from to .
specifies the computation of Spearman correlation coefficients based on the ranks of the variables. The correlations range from to .
specifies how missing values are handled. The following values are valid:
specifies that observations with missing values are excluded from the analysis. This is the default value.
specifies that all nonmissing pairs of values for each pair of variables are included in the statistical computations.
The method and excludemiss arguments are not case-sensitive. The first four characters are used to determine the value. For example, “LIST” and “listwise” specify the same option.
The CORR function computes a sample correlation matrix for data, as shown in the following example:
x = {5 1 10, 6 2 3, 6 8 5, 6 7 9, 7 2 13}; corr = corr(x); spearman = corr(x, "spearman"); print corr, spearman;
Figure 23.69: Correlation Matrices
corr | ||
---|---|---|
1 | 0.1091089 | 0.265165 |
0.1091089 | 1 | -0.289319 |
0.265165 | -0.289319 | 1 |
spearman | ||
---|---|---|
1 | 0.3441236 | 0.2236068 |
0.3441236 | 1 | -0.410391 |
0.2236068 | -0.410391 | 1 |
The CORR function behaves similarly to the CORR procedure. In particular, the documentation for the CORR procedure in the Base SAS Procedures Guide: Statistical Procedures includes details about the various correlation statistics.
The CORR function also handles missing values in the same way as the CORR procedure. In particular, be aware that specifying excludemiss=“pairwise” might result in a correlation matrix that is not nonnegative definite.
You can use the ROWNAME= and COLNAME= options in the MATTRIB statement or the PRINT statement to associate names of variables
to rows and columns of the correlation matrix. For example, if the names of the variables in the previous example are X1
, X2
, and X3
, then the following statements associate those names with the matrix returned by the CORR function:
varnames = {"X1" "X2" "X3"}; mattrib corr rowname=varnames colname=varnames spearman rowname=varnames colname=varnames; print corr, spearman;
Figure 23.70: Correlation Matrices with Named Rows and Columns
corr | |||
---|---|---|---|
X1 | X2 | X3 | |
X1 | 1 | 0.1091089 | 0.265165 |
X2 | 0.1091089 | 1 | -0.289319 |
X3 | 0.265165 | -0.289319 | 1 |
spearman | |||
---|---|---|---|
X1 | X2 | X3 | |
X1 | 1 | 0.3441236 | 0.2236068 |
X2 | 0.3441236 | 1 | -0.410391 |
X3 | 0.2236068 | -0.410391 | 1 |
Prior to SAS/IML 9.22, there was a module named CORR in the IMLMLIB library. This module has been removed.