楼主: bobguy
1415 2

[原创博文] random normal generation with any covariance structure [推广有奖]

学科带头人

7%

还不是VIP/贵宾

-

威望
0
论坛币
14187 个
通用积分
28.9279
学术水平
344 点
热心指数
363 点
信用等级
228 点
经验
104882 点
帖子
1846
精华
0
在线时间
1608 小时
注册时间
2008-7-18
最后登录
2019-3-8

中级热心勋章

楼主
bobguy 发表于 2012-3-30 11:27:17 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
Any covariance structure(symmetric positive definite COV)  can be decomposed into COV=L*L`.
L is lower triangle matrix. We can use Cholesky decomposition routine to solve for L.
We generate a group of standard normal random variable X. The X*L` will have COV as its covariance.

We can do the same job as vnormal routine in IML within a data step.

Here is an example.

COV=( 1  0.8 2,
           0.8 3  1,
           2   1  5)

The program results as


                Covariance Matrix, DF = 99999

                     x1                x2                x3

   x1       1.003938580       0.805219557       2.008134939
   x2       0.805219557       3.022280567       1.006021545
   x3       2.008134939       1.006021545       5.018633530



proc fcmp outlib=sasuser.funcs.temp;;
     subroutine Choleskydecom (mat[*,*],lmat[*,*] );
      outargs lmat;
      call chol(mat, lmat);
      call transpose(lmat, lmat);
      endsub;
run;
quit;

options cmplib=sasuser.funcs;

%let n=100000;
data random;
  array a(3,3) _temporary_   ( 1  0.8 2,
                               0.8 3  1,
                               2   1  5

                             );
  array b(3,3) _temporary_ ;
  call Choleskydecom (a, b);

  array x(3);
  array norm(3);
  seed=190;
  do j=1 to &n;
    do i=1 to dim(x);
   norm=rannor(seed);
x=
.;
end;
do i=1 to dim(x);
do k=1 to i;
x=sum(x,b[k,i]*norm[k]);
end;

end;
output;
end;
run;

proc corr data=random cov ;
var x1 x2 x3;
run;
二维码

扫码加我 拉你入群

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

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

关键词:Generation covariance Structure variance struct generation structure positive generate standard

沙发
research 发表于 2012-3-30 11:37:41
提示: 作者被禁止或删除 内容自动屏蔽

藤椅
bobguy 发表于 2012-3-31 08:28:53


norm and x should have index. I don't know why it become like that. It looks good in editing window.

norm-->norm[i]

x--->x[i]

norm[i]=rannor(seed);
x[i]=.;
end;
do i=1 to dim(x);
do k=1 to i;
x[i]=sum(x[i],b[k,i]*norm[k]);

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-21 06:53