BookmarkSubscribeRSS Feed
EricB40
Fluorite | Level 6

Does anyone know what is wrong with this code:

proc iml;
x={1,
2,
3,
4,
5,
6};


xt=t(x);
print transpose;

Using this data, I am expected to find x', x'x, x'x inverse, X’Y, b = (X’X)-1X’Y, e = Y-Xb, etc. Does anyone know how to best do this?

X

Y

1

2

3

4

5

6

  0.83

  7.48

14.45

12.70

20.46

25.73

 

4 REPLIES 4
JosvanderVelden
SAS Super FREQ

Have a look at the results when you run this:

proc iml;
   /* transpose a matrix */
   s = {1 2 3, 4 5 6, 7 8 9, 10 11 12}; /* 4 x 3 matrix */
   transpose = t(s); /* 3 x 4 matrix */
   print transpose;
run;

proc iml;
   x = {1, 2, 3, 4, 5, 6};
   xt = t(x);
   print xt;
run;
PaigeMiller
Diamond | Level 26

@EricB40 wrote:

 

Using this data, I am expected to find x', x'x, x'x inverse, X’Y, b = (X’X)-1X’Y, e = Y-Xb, etc. Does anyone know how to best do this?


You turn these formulas into the appropriate PROC IML code. It should be very straighforward, the actual math formulas have a very simple and easy-to-understand representation in code

 

Example:

 

x'x in IML code is

 

t(x)*x

 

You need to do this for the rest of the functions you need. Show us what you have tried.

--
Paige Miller
Ksharp
Super User

Why not post it at IML forum, since it is about IML question. and @Rick_SAS  is there.

 

data have;
input x y;
cards;
1  0.83
2 7.48
3 14.45
4 12.70
5 20.46
6 25.73
;

proc iml;
use have;
read all var {x y};
close;

x=j(nrow(x),1,1)||x;
xt=t(x);
xtx=xt*x;
xtx_inv=inv(xtx);
xty=xt*y;
b=solve(xtx,xty);
bb=inv(t(x)*x)*t(x)*y; /*another way to get BETA*/
e=y-x*b;

print x,xt,xtx,xtx_inv,xty,b ,bb ,e;
quit;

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 4 replies
  • 1350 views
  • 0 likes
  • 4 in conversation