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 |
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;
@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.
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.