I searched on line and found the following link:
which discussed calculating the lower triangular matrix. The attached code was provided at the link:
/*LOWER TRIANGULAR CODE SAS IML*/
proc import out=a
datafile='/folders/myfolders/dmatrix/lnparam.csv/'
dbms=csv replace;
getnames=yes;
datarow=2;
run;
proc iml;
/*To get the values in a vector, you can use*/
lower = symsqr(a);
upper = symsqr(a`);
/*If you need the lower triangular matrix with zeros above the diagonal, you can use:*/
n = nrow(a);
p = ncol(a);
low = j(n, p, 0);
do i = 1 to n;
cols = 1:i; /* or cols=iSmiley Tongue; */
low[i, cols] = a[i, cols];
end;
quit;
When I run the code I get several errors:
The matrix 'a' is a data matrix. The "lower triangular portion" of a data matrix is not useful.
If you compute C=cov(A), then C is a symmetric matrix, so the lower triangular portion is relevant and useful. However, the lower triangular matrix does not have the property that you are trying to claim.
I am going to guess that you want the Cholesky decomposition of the covariance matrix, which is the upper triangular matrix U such that C = U` * U. Equivalently, you can define L = U` so that C = L * L`. You can compute the Cholesky matrix by using the ROOT function in SAS/IML, as follows:
proc iml;
use a;
read all var _NUM_ into a;
close;
C = cov(a);
U = root(C); /* C = U` * U */
L = U`; /* C = L * L` */
/* test to make sure it works */
C2 = L*L`;
print L, C, C2;
First, could you please edit the title of this thread to make it more informative? Perhaps "How to extract the lower triangular portion of a matrix".
In the previous thread that you link to, the responder used
a = {1 2 3, 4 5 6, 7 8 9};
before writing the code that you quote. Your problem is that you have not read the data into an IML matrix.
Use
proc iml;
use a;
read all var _NUM_ into a;
close a;
For more information about reading data sets into SAS/IML matrices, see the article "Reading all variables into a matrix."
> A final question related to the lower triangle matrix. If one calls the lower triangular matrix D and D'
> its transpose, does the var cov matrix=DxD'
No. You are reading in the data matrix. You can obtain the variance-covariance matrix by using
C = cov(a);
You can then get the lower triangular elements of C, if that is important.
The matrix 'a' is a data matrix. The "lower triangular portion" of a data matrix is not useful.
If you compute C=cov(A), then C is a symmetric matrix, so the lower triangular portion is relevant and useful. However, the lower triangular matrix does not have the property that you are trying to claim.
I am going to guess that you want the Cholesky decomposition of the covariance matrix, which is the upper triangular matrix U such that C = U` * U. Equivalently, you can define L = U` so that C = L * L`. You can compute the Cholesky matrix by using the ROOT function in SAS/IML, as follows:
proc iml;
use a;
read all var _NUM_ into a;
close;
C = cov(a);
U = root(C); /* C = U` * U */
L = U`; /* C = L * L` */
/* test to make sure it works */
C2 = L*L`;
print L, C, C2;
Worked just as you stated and the key element was use of the Cholesky matrix and the root function in SAS IML.
Thanks