luohuaping 发表于 2009-12-1 20:27 ![](http://www.pinggu.org/bbs/images/common/back.gif)
本人需要生成多元正态分布的随机数,在其他地方看到了一个程序,但是运行后提示错误。本人刚刚接触iml过程,对其中的运算不是很了解,故求助于高手看一下哪里出现了错误,怎样能够正确的运行程序。不甚感激!
题意是要生成1000组相关系数均为0.3的服从多元正态分布的随机向量(X,Y,Z),其中随机变量X~N(0,1),y~N(10,22),Z~ N(20,32)。
程序如下:
proc iml;
R={1.00 0.30 0.30,
0.30 1.00 0.30,
0.30 0.30 1.00};
S={1 0 0,
0 2 0,
0 0 3};
E=S*R*S;
u={0,10,20};
do i=1 to 1000;
zl=RANNOR(0);
z2=RANNOR(0);
z3=RANNOR(0);
C=root(E);
xi=C`*(z1//z2//z3)+u;
m=m//xi`;
end ;
ERROR: (execution) Matrices do not conform to the operation.(运行窗口提示)
create example4 var{x y z};
append from m ;
run;
ERROR: Number of columns in m does not match with the number of variables in the data set.(运行窗口提示)
SAS iml has a random multivariate normal call routine vnormal.
Here is an example,
proc iml;
n=1000;
et=repeat(0,n,3);
mu = { 0, 0,0 };
corr= { 1 0.3 0.3,
0.3 1 0.3,
0.3 0.3 1};
call vnormal(et, mu, corr, n, 89010);
et[ ,1]=et[ ,1] + 0;
et[ ,2]=22*et[ ,2] + 10;
et[ ,3]=32*et[ ,3] + 20;
norm_err=et;
create a from norm_err;
append from norm_err;
quit;
proc corr data=a;
var col1 col2 col3;
run;