|
楼主

楼主 |
发表于 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, 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. A better way is to use CALL DYNAMIC_ARRAY routine to resize a used matrix. It is similar to Redim Statement in VBA. 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;
var weight length mpg_city;
run;
data cov;
set corr_cov;
where _type_ = 'COV';
drop _:;
run;
proc fcmp;
/* Allocate space for matrices*/
array a1[3,3] / nosymbols;
array a2[3, 3] / nosymbols;;
array b1[3, 1000] / nosymbols;
array b2[3, 1000] / nosymbols;
/* Simulate a matrix by normal distribution*/
do i = 1 to 3;
do j = 1 to 1000;
b1[i, j] = rannor(12345);
end;
end;
/* Read the covariance matrix*/
rc1 = read_array('cov', a1);
call chol(a1, a2);
put a2;
call mult(a2, b1, b2);
/* Output the result matrix*/
call dynamic_array(b1, 1000, 3);
call transpose(b2, b1);
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"/> |
|