Turn on suggestions

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

Showing results for

Options

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 12-31-2013 02:00 AM
(1324 views)

I have a specific data and now I need to know how I can produce a matrix with the following formula:

1/2+sum of multiplications of row(i)-row(n). That is to say, I have a matrix with let say 2 columns and 3 rows and I need to produce a new matrix by calculating a value for each element (value in the cell=v(row,column). In the real matrix the number of rows and columns are 106 and 133...

First the original matrix

column1 column2

row1 v(1,1) v(1,2)

row2 v(2,1) v(2,2)

row3 v(3,1) v(3,2)

And then the desired one. Read carefully, v(row, column)'s come from the upper matrix :

column1 column2

row1 1/2+v(1,1)+v(1,1)*v(2,1)+v(1,1)*v(2,1)*v(3,1) 1/2+v(1,2)+v(1,2)*v(2,2)+v(1,2)*v(2,2)*v(3,2)

row2 1/2+v(2,1)+v(2,1)*v(3,1) 1/2+v(2,2)+v(2,2)*v(3,2)

row3 1/2+v(3,1) 1/2+v(3,2)

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Let A be the desired matrix without the 1/2 term. Notice that formula for first column of A is

v11(1+v21*(1+v31))

v21*(1+v31))

v31

and similar for other columns. Therefore you can compute A by

computing from the bottom row to the top. The i_th row of A is the i_th row of V times (1 + i_th row of A),

as follows. (Then add the 1/2 at the end.)

proc iml;

V = {1 2,

3 4,

5 6};

N = nrow(V);

A = j(N, ncol(V), .); /* allocate */

A[N, ] = V[N, ]; /* assign last row */

do i = N-1 to 1 by -1;

A[i, ] = V[i, ]#(1 + A[i+1, ]);

end;

A = 1/2 + A;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Dealing with missing values can be compliated. Mathematically, they can/should propogate, but you are intending to replace missing values with a nonmissing, which can be dangerous because the missing values are often there for a reason. You are biasing your results if you arbitrarily replace missing values by 0 or 1. Statisticians tend to use some imputation technique instead of simple repacement.

If you insist on replacing the missing values, try some variation of this approach. Inside the loop, use these formulas:

Q = choose(V[i, ]=., 0, V[i, ]);

R = choose(V[i, ]=., 1, V[i, ]);

A[i, ] = Q + R#A[i+1, ];

I don't know what you want to do if there is a missing value in the last row. Presumably use the 'Q' formula.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.