turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-20-2010 12:55 PM

Hi

I'd like to bring back the lower or upper triangular matrix with IML.

Is it possible ?

I'd like to bring back the lower or upper triangular matrix with IML.

Is it possible ?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-22-2010 03:13 PM

"bring back"?? I don't understand what you are asking for.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-22-2010 03:50 PM

It's always a good idea to supply an example.

Are you saying that you have a matrix

a = {1 2 3, 4 5 6, 7 8 9};

and you want the lower triangular values?

If so, do you want them in a vector or in a matrix?

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=i; */

low[i, cols] = a[i, cols];

end;

Are you saying that you have a matrix

a = {1 2 3, 4 5 6, 7 8 9};

and you want the lower triangular values?

If so, do you want them in a vector or in a matrix?

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=i; */

low[i, cols] = a[i, cols];

end;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-24-2010 05:15 AM

oops sorry it's true that my explanation is light and I'm newbie in IML.

using your (excellent) proposition :

proc iml;

a={

-3 2 4,

2 -2 3,

4 3 -4};

r={"A" "B" "C"};

c={"A" "B" "C"};

v=vecdiag(a);

lower = symsqr(a);

upper = symsqr(a`);

n = nrow(a);

p = ncol(a);

low = j(n, p, .);

do i = 1 to n;

cols = 1:i; /* or cols=i; */

low[i, cols] = a[i, cols];

end;

print a[rowname=r colname=c];

print low[rowname=r colname=c];

quit;

You see that the "a" matrix is a variance/covariance matrix and I want the covariance values. So your low matrix is fine except that I would like the low matrix but with missing values on the diagonal.

Otherwise Rick, could you show me how to produce the mean, min, max, ... of the covariance part of the matrix for A, B and C in IML ? Message was edited by: Stephane

using your (excellent) proposition :

proc iml;

a={

-3 2 4,

2 -2 3,

4 3 -4};

r={"A" "B" "C"};

c={"A" "B" "C"};

v=vecdiag(a);

lower = symsqr(a);

upper = symsqr(a`);

n = nrow(a);

p = ncol(a);

low = j(n, p, .);

do i = 1 to n;

cols = 1:i; /* or cols=i; */

low[i, cols] = a[i, cols];

end;

print a[rowname=r colname=c];

print low[rowname=r colname=c];

quit;

You see that the "a" matrix is a variance/covariance matrix and I want the covariance values. So your low matrix is fine except that I would like the low matrix but with missing values on the diagonal.

Otherwise Rick, could you show me how to produce the mean, min, max, ... of the covariance part of the matrix for A, B and C in IML ? Message was edited by: Stephane

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-24-2010 08:31 AM

> I want the covariance values.

They are in v.

> I would like the low matrix but with missing values on the diagonal.

low = j(n, p, .);

do i = 2 to n;

cols = 1:i-1;

low[i, cols] = a[i, cols];

end;

> show me how to produce the mean, min, max, ... of the covariance part

> of the matrix for A, B and C in IML ?

For the matrix a, you can compute the mean (or max or min...) of three different quantities: the total mean, the rows means, or the column means.

For the totals:

mean = a[:]; /* ":" is mean operator */

min = min(a);

max = max(a);

print mean min max;

For the column means:

ColMean = a[:,]; /* mean of each column (apply operation on rows)*/

ColMin = a[><,]; /* min of each column */

ColMax = a[<>,]; /* max of each column */

print ColMean, ColMin, ColMax;

These subscript reduction operators take some getting used to, but are great for computing summary statistics without writing any loops. They are documented in the "Working with Matrices" chapter of the SAS/IML User's Guide:

http://support.sas.com/documentation/cdl/en/imlug/59656/HTML/default/workmatrix_sect14.htm

They are in v.

> I would like the low matrix but with missing values on the diagonal.

low = j(n, p, .);

do i = 2 to n;

cols = 1:i-1;

low[i, cols] = a[i, cols];

end;

> show me how to produce the mean, min, max, ... of the covariance part

> of the matrix for A, B and C in IML ?

For the matrix a, you can compute the mean (or max or min...) of three different quantities: the total mean, the rows means, or the column means.

For the totals:

mean = a[:]; /* ":" is mean operator */

min = min(a);

max = max(a);

print mean min max;

For the column means:

ColMean = a[:,]; /* mean of each column (apply operation on rows)*/

ColMin = a[><,]; /* min of each column */

ColMax = a[<>,]; /* max of each column */

print ColMean, ColMin, ColMax;

These subscript reduction operators take some getting used to, but are great for computing summary statistics without writing any loops. They are documented in the "Working with Matrices" chapter of the SAS/IML User's Guide:

http://support.sas.com/documentation/cdl/en/imlug/59656/HTML/default/workmatrix_sect14.htm

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-24-2010 10:17 AM

> I want the covariance values.

They are in v.

=> No it's the variance and this is why I want to the rest.

for your explanations for the statistics, it's fine. Message was edited by: Stephane

They are in v.

=> No it's the variance and this is why I want to the rest.

for your explanations for the statistics, it's fine. Message was edited by: Stephane

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-24-2010 10:45 AM

Of course. Sorry. The variances are in v; the covariances are in low.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-25-2010 07:58 AM

Thank you very much Rick.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-27-2016 05:24 AM

Hi rick,

did you have any suggests to do the same thing but without PROC IML?

thank you bery much

MC

Martino Crippa

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-27-2016 06:18 AM

Please start a new thread in the Base SAS Programming community rather than re-opening a SAS/IML thread from 2010. You can solve this problem in the DATA step by using arrays and the _N_ automatic variable.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-27-2016 06:21 AM

OK, thanks. Here we are: New Topic on SAS BASE

Martino Crippa