SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1506|回复: 0
打印 上一主题 下一主题

Cholesky decomposition to "expand" data

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2012-2-10 03:10:24 | 只看该作者

Cholesky decomposition to "expand" data

From Dapangmao's blog on sas-analysis

<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-eTlJ_pT7DLw/TzQQ-Y7AgnI/AAAAAAAAA60/1UNsfqM7IsI/s1600/plot1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://2.bp.blogspot.com/-eTlJ_pT7DLw/TzQQ-Y7AgnI/AAAAAAAAA60/1UNsfqM7IsI/s320/plot1.png" width="320" /></a></div><br />
Yesterday Rick showed how to use <a href="http://blogs.sas.com/content/iml/2012/02/08/use-the-cholesky-transformation-to-correlate-and-uncorrelate-variables/">Cholesky decomposition to transform data</a> by the ROOT function of SAS/IML. Cholesky decomposition is so important in simulation. For those DATA step programmers who are not very familiar with SAS/IML, PROC FCMP in SAS may be another option, since it has an equivalent routine CALL CHOL.<br />
<br />
To replicate Rick’s example of general Cholesky transformation correlates variables, &nbsp;I chose three variables from a SASHELP dataset SASHELP.CARS and created a simulated dataset which shares the identical variance-covariance structure. A simulated dataset can be viewed as an “expanded’ version of the original data set.<br />
<br />
Conclusion:<br />
In PROC FCMP, don’t allocate many matrices. &nbsp;A better way is to use CALL DYNAMIC_ARRAY routine to resize a used matrix. It is similar to Redim Statement in VBA. &nbsp;A VBA programmer can easily migrate to SAS through PROC FCMP.<br />
<br />
<br />
<pre style="background-color: #ebebeb; border: 1px dashed rgb(153, 153, 153); color: #000001; font-size: 14px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
proc corr data=sashelp.cars cov outp=corr_cov plots=scatter;
&nbsp; &nbsp;var weight length mpg_city;
run;

data cov;
&nbsp; &nbsp;set corr_cov;
&nbsp; &nbsp;where _type_ = 'COV';
&nbsp; &nbsp;drop _:;
run;

proc fcmp; &nbsp;
&nbsp; &nbsp;/* Allocate space for matrices*/
&nbsp; &nbsp;array a1[3,3] / nosymbols;
&nbsp; &nbsp;array a2[3, 3] / nosymbols;;
&nbsp; &nbsp;array b1[3, 1000] / nosymbols;
&nbsp; &nbsp;array b2[3, 1000] / nosymbols;

&nbsp; &nbsp;/* Simulate a matrix by normal distribution*/
&nbsp; &nbsp;do i = 1 to 3;
&nbsp; &nbsp; &nbsp; do j = 1 to 1000;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b1[i, j] = rannor(12345);
&nbsp; &nbsp; &nbsp; end;
&nbsp; &nbsp;end;

&nbsp; &nbsp;/* Read the covariance matrix*/
&nbsp; &nbsp;rc1 = read_array('cov', a1);
&nbsp; &nbsp;call chol(a1, a2);
&nbsp; &nbsp;put a2;
&nbsp; &nbsp;call mult(a2, b1, b2);

&nbsp; &nbsp;/* Output the result matrix*/
&nbsp; &nbsp;call dynamic_array(b1, 1000, 3);
&nbsp; &nbsp;call transpose(b2, b1);
&nbsp; &nbsp;rc2 = write_array('result', b1);
quit;

proc corr data=result cov plots=scatter;
run;</code><code></code></pre><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3256159328630041416-8283692493940392260?l=www.sasanalysis.com' alt='' /></div><img src="http://feeds.feedburner.com/~r/SasAnalysis/~4/C-lL9Xb3iqE" height="1" width="1"/>
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-5-7 00:04 , Processed in 0.071664 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表