Statistical programming, matrix languages, and more

simulatiom data with sas/iml

Reply
Contributor
Posts: 74

simulatiom data with sas/iml

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;

Contributor
Posts: 74

Re: simulatiom data with sas/iml

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;

Ask a Question
Discussion stats
  • 1 reply
  • 260 views
  • 0 likes
  • 1 in conversation