全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
7885 7
2009-12-01
本人需要生成多元正态分布的随机数,在其他地方看到了一个程序,但是运行后提示错误。本人刚刚接触iml过程,对其中的运算不是很了解,故求助于高手看一下哪里出现了错误,怎样能够正确的运行程序。不甚感激!
       题意是要生成1000组相关系数均为0.3的服从多元正态分布的随机向量(X,Y,Z),其中随机变量X~N(0,1),y~N(10,2),Z~ N(20,3)。

程序如下:
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.(运行窗口提示)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2009-12-2 02:29:11
zl=RANNOR(0);
zl should be z1; that is ZL ^= Z1
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2009-12-2 18:35:56
谢谢jingju11,我刚才改了一下,但是还是运行不了。
最后提示NOTE: Module MAIN is undefined in IML; cannot be RUN.
郁闷!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2009-12-2 21:48:58
3# luohuaping

Replace

run;
by
复制代码
in the last line of your code to terminate the PROC IML.
NOTE: Module MAIN is undefined in IML; cannot be RUN.
the note in the log likely results from
In PROC IML, the RUN statement is used to execute/run a module.
when a RUN statement is submitted but without giving the name of a module, the RUN statement takes the name of the module as MAIN and tries to run it.
but apparently it fails in your case.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2009-12-4 08:42:12
luohuaping 发表于 2009-12-1 20:27
本人需要生成多元正态分布的随机数,在其他地方看到了一个程序,但是运行后提示错误。本人刚刚接触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;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2009-12-26 18:52:19
已经解决!谢谢各位!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群