BookmarkSubscribeRSS Feed
thanoon
Calcite | Level 5

HI ALL

i need your help to correct this commands ( simulation of multivariate regression model).

regards\

&let N=1000;

proc iml;

/* specify the mean and covariance of the population */

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

cov = {0.8838659 0.9738211 0.5075826 0.8869405 0.6893635 0.9432546 0.9287864 0.487664 0.7798851,

       0.9738211 0.8771385 0.5668343 0.6656078 0.8234433 0.9280248 0.7900982 0.1142881 0.8905852,

       0.5075826 0.5668343 0.5448972 0.2810451 0.9316785 0.6140648 0.8564316 0.6149666 0.4655727,

       0.8869405 0.6656078 0.2810451 0.5900954 0.7749225 0.4426628 0.0762391 0.9093871 0.5513743,

       0.6893635 0.8234433 0.9316785 0.7749225 0.6663087 0.236998 0.1419535 0.3321644 0.3306588,

       0.9432546 0.9280248 0.6140648 0.4426628 0.236998 0.7543832 0.6882105 0.6199138 0.7862424,

       0.9287864 0.7900982 0.8564316 0.0762391 0.1419535 0.6882105 0.9863298 0.1584623 0.3849384,

        0.487664 0.1142881 0.6149666 0.9093871 0.3321644 0.6199138 0.1584623 0.3205565 0.0744708,

       0.7798851 0.8905852 0.4655727 0.5513743 0.3306588 0.7862424 0.3849384 0.0744708 0.4806334}

call randseed(4321); 

X = RandNormal(&N, Mean, Cov);               /* 1000 x 9 matrix     */

/* check the sample mean and sample covariance */

SampleMean = mean(X);                        /* mean of each column */

SampleCov =  cov(X);                         /* sample covariance   */

/* print results */

c = "x1":"x9";

print (X[1000:9,])[label="First 5 Obs: MV Normal"];

print SampleMean[colname=c];

print SampleCov[colname=c rowname=c];

/* write SAS/IML matrix to SAS data set for plotting */

create MVN from X[colname=c];  append from X;  close MVN;

quit;

run;

1 REPLY 1
thanoon
Calcite | Level 5

i am sorry i forget the linear equation :

%let N=1000;

proc iml;

/* specify the mean and covariance of the population */

Mean = {1, 2, 3, 2, 1, 4, 5, 6, 1};

Cov = {0.8838659 0.9738211 0.5075826 0.8869405 0.6893635 0.9432546 0.9287864 0.487664 0.7798851,

       0.9738211 0.8771385 0.5668343 0.6656078 0.8234433 0.9280248 0.7900982 0.1142881 0.8905852,

       0.5075826 0.5668343 0.5448972 0.2810451 0.9316785 0.6140648 0.8564316 0.6149666 0.4655727,

       0.8869405 0.6656078 0.2810451 0.5900954 0.7749225 0.4426628 0.0762391 0.9093871 0.5513743,

       0.6893635 0.8234433 0.9316785 0.7749225 0.6663087 0.236998 0.1419535 0.3321644 0.3306588,

       0.9432546 0.9280248 0.6140648 0.4426628 0.236998 0.7543832 0.6882105 0.6199138 0.7862424,

       0.9287864 0.7900982 0.8564316 0.0762391 0.1419535 0.6882105 0.9863298 0.1584623 0.3849384,

        0.487664 0.1142881 0.6149666 0.9093871 0.3321644 0.6199138 0.1584623 0.3205565 0.0744708,

       0.7798851 0.8905852 0.4655727 0.5513743 0.3306588 0.7862424 0.3849384 0.0744708 0.4806334};

call randseed(4321); 

X = RandNormal(&N, Mean, Cov);               /* 1000 x 9 matrix     */

/* check the sample mean and sample covariance */

SampleMean = mean(X);                        /* mean of each column */

SampleCov =  cov(X);                         /* sample covariance   */

/* generate Y according to regression model */

beta = {2, 1, -1, 2, 1, 5, 6, 2, -2};               /* params, not including intercept */

Y = 1 + X*beta + eps;          

/* write SAS data set */

varNames = ('x1':'x9') || {"Y"};

output = X || Y;

run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

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
  • 1 reply
  • 720 views
  • 0 likes
  • 1 in conversation