<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Algorithm-Forge &#187; Statistics</title>
	<atom:link href="http://www.algorithm-forge.com/techblog/category/statistics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.algorithm-forge.com/techblog</link>
	<description>Java, R, Statistics, Algorithms and other stuff</description>
	<lastBuildDate>Sun, 18 Jul 2010 16:53:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Random Correlation Matrices</title>
		<link>http://www.algorithm-forge.com/techblog/2009/08/random-correlation-matrices/</link>
		<comments>http://www.algorithm-forge.com/techblog/2009/08/random-correlation-matrices/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 12:43:17 +0000</pubDate>
		<dc:creator>Kornelius Rohmeyer</dc:creator>
				<category><![CDATA[R]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Simulations]]></category>

		<guid isPermaLink="false">http://www.algorithm-forge.com/techblog/?p=56</guid>
		<description><![CDATA[Some time ago one of my colleagues with a new method for evaluating the cumulative distribution function of a multivariate normal distribution wanted to compare the speed of his method with that of randomized quasi-Monte Carlo methods. While we were &#8230; <a href="http://www.algorithm-forge.com/techblog/2009/08/random-correlation-matrices/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Some time ago one of my colleagues with a new method for evaluating the cumulative distribution function of a multivariate normal distribution wanted to compare the speed of his method with that of randomized quasi-Monte Carlo methods. While we were going to lunch, he asked me how to generate random correlation matrices, because the speed of his method depends strongly on the <a href="http://en.wikipedia.org/wiki/Correlation#Correlation_matrices">correlation matrix</a> and he wanted to have some sort of average.</p>
<p><strong>But what is a random correlation matrix?</strong></p>
<p>Let&#8217;s first give a characterization of correlation matrices.</p>
<p>It is well known that for a matrix <img src='http://s.wordpress.com/latex.php?latex=C%3A%3D%28c_%7Bi%2Cj%7D%29_%7B1%5Cleq%20i%2Cj%5Cleq%20n%7D%5Cin%5Cmathbb%7BR%7D%5E%7Bn%5Ctimes%20n%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C:=(c_{i,j})_{1\leq i,j\leq n}\in\mathbb{R}^{n\times n}' title='C:=(c_{i,j})_{1\leq i,j\leq n}\in\mathbb{R}^{n\times n}' class='latex' /> there exist (multivariate normal distributed) random variables <img src='http://s.wordpress.com/latex.php?latex=X%2CY&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='X,Y' title='X,Y' class='latex' /> with <img src='http://s.wordpress.com/latex.php?latex=%5Cdisplaystyle%20%5Ctext%7BCor%7D%28X%2CY%29%3A%3D%5Cleft%28%5Cfrac%7B%5Ctext%7BCov%7D%28X_i%2CY_j%29%7D%7B%5Csqrt%7B%5Ctext%7BVar%7D%28X_i%29%5Ctext%7BVar%7D%28Y_j%29%7D%7D%5Cright%29_%7B1%5Cleq%20i%2Cj%5Cleq%20n%7D%3DC&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\displaystyle \text{Cor}(X,Y):=\left(\frac{\text{Cov}(X_i,Y_j)}{\sqrt{\text{Var}(X_i)\text{Var}(Y_j)}}\right)_{1\leq i,j\leq n}=C' title='\displaystyle \text{Cor}(X,Y):=\left(\frac{\text{Cov}(X_i,Y_j)}{\sqrt{\text{Var}(X_i)\text{Var}(Y_j)}}\right)_{1\leq i,j\leq n}=C' class='latex' /> if and only if </p>
<ol>
<li><img src='http://s.wordpress.com/latex.php?latex=-1%5Cleq%20c_%7Bi%2Cj%7D%5Cleq%201&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='-1\leq c_{i,j}\leq 1' title='-1\leq c_{i,j}\leq 1' class='latex' /> for all <img src='http://s.wordpress.com/latex.php?latex=i%2Cj%5Cin%5C%7B0%2C%5Cldots%2Cn%5C%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='i,j\in\{0,\ldots,n\}' title='i,j\in\{0,\ldots,n\}' class='latex' />,</li>
<li><img src='http://s.wordpress.com/latex.php?latex=c_%7Bi%2Ci%7D%3D%201&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='c_{i,i}= 1' title='c_{i,i}= 1' class='latex' /> for all <img src='http://s.wordpress.com/latex.php?latex=i%5Cin%5C%7B0%2C%5Cldots%2Cn%5C%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='i\in\{0,\ldots,n\}' title='i\in\{0,\ldots,n\}' class='latex' />,</li>
<li><img src='http://s.wordpress.com/latex.php?latex=C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C' title='C' class='latex' /> is symmetric (therefore all eigenvalues <img src='http://s.wordpress.com/latex.php?latex=%5Clambda_1%2C%5Cldots%2C%5Clambda_n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\lambda_1,\ldots,\lambda_n' title='\lambda_1,\ldots,\lambda_n' class='latex' /> of <img src='http://s.wordpress.com/latex.php?latex=C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C' title='C' class='latex' /> are real)</li>
<li>and all eigenvalues of <img src='http://s.wordpress.com/latex.php?latex=C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C' title='C' class='latex' /> are greater or equal to zero.</li>
</ol>
<p>But what is the right notion of randomness for these matrices?<br />
For example let&#8217;s look at the orthogonal matrices. In many numerical applications we need uniformly distributed random orthogonal matrices in terms of the Haar measure (See <a href="http://en.wikipedia.org/wiki/Orthogonal_matrix#Randomization">http://en.wikipedia.org/wiki/Orthogonal_matrix#Randomization</a>).</p>
<p>Unfortunately in our case there is no clear, natural notion of randomness. <img src='http://www.algorithm-forge.com/techblog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
<p><strong>Method 1 &#8211; Try and Error:</strong> We generate a matrix fulfilling no. 1, 2 and 3 of the characterization (these matrices are called pseudo correlation matrices) by generating independent pseudo-random numbers uniformly distributed between -1 and 1 for the entries <img src='http://s.wordpress.com/latex.php?latex=c_%7Bi%2Cj%7D%3Dc_%7Bj%2Ci%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='c_{i,j}=c_{j,i}' title='c_{i,j}=c_{j,i}' class='latex' />, <img src='http://s.wordpress.com/latex.php?latex=1%5Cleq%20i%3Cj%5Cleq%20n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='1\leq i&lt;j\leq n' title='1\leq i&lt;j\leq n' class='latex' />.</p>
<p>If this random symmetric matrix is positive semidefinite (i.e. all eigenvalues of <img src='http://s.wordpress.com/latex.php?latex=C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C' title='C' class='latex' /> are greater or equal to zero) than we have the desired result. Otherwise we try again. Here is the corresponding R code:</p>
<div class="codecolorer-container r default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="r codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">random.pseudo.correlation.matrix <span style="color: #78aaac;">&lt;-</span><br />
<span style="color: #a020f0;">function</span><span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; a <span style="color: #78aaac;">&lt;-</span> diag<span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #a020f0;">for</span><span style="color: #66cc66;">&#40;</span>i <span style="color: #a020f0;">in</span> 1:<span style="color: #66cc66;">&#40;</span>n<span style="color: #78aaac;">-</span>1<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a020f0;">for</span><span style="color: #66cc66;">&#40;</span>j <span style="color: #a020f0;">in</span> <span style="color: #66cc66;">&#40;</span>i<span style="color: #78aaac;">+</span>1<span style="color: #66cc66;">&#41;</span>:n<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; a<span style="color: #66cc66;">&#91;</span>i,j<span style="color: #66cc66;">&#93;</span> <span style="color: #78aaac;">&lt;-</span> a<span style="color: #66cc66;">&#91;</span>j,i<span style="color: #66cc66;">&#93;</span> <span style="color: #78aaac;">&lt;-</span> runif<span style="color: #66cc66;">&#40;</span>1,<span style="color: #78aaac;">-</span>1,1<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; <span style="color: #a020f0;">return</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
random.correlation.matrix.try.and.error <span style="color: #78aaac;">&lt;-</span><br />
<span style="color: #a020f0;">function</span><span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #a020f0;">repeat</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; a <span style="color: #78aaac;">&lt;-</span> random.pseudo.correlation.matrix<span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #a020f0;">if</span> <span style="color: #66cc66;">&#40;</span>min<span style="color: #66cc66;">&#40;</span>eigen<span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span>$values<span style="color: #66cc66;">&#41;</span><span style="color: #78aaac;">&gt;=</span>0<span style="color: #66cc66;">&#41;</span> <span style="color: #a020f0;">return</span><span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>This approach is only reasonable for very small dimensions (try it with <img src='http://s.wordpress.com/latex.php?latex=n%3D6%2C7%2C8&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n=6,7,8' title='n=6,7,8' class='latex' />).</p>
<p><strong>Method 2 &#8211; Lift the Diagonal:</strong></p>
<p>We denote by <img src='http://s.wordpress.com/latex.php?latex=I&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='I' title='I' class='latex' /> the identity matrix. If <img src='http://s.wordpress.com/latex.php?latex=C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C' title='C' class='latex' /> has the eigenvalues <img src='http://s.wordpress.com/latex.php?latex=%5Clambda_1%5Cleq%5Cldots%5Cleq%5Clambda_n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\lambda_1\leq\ldots\leq\lambda_n' title='\lambda_1\leq\ldots\leq\lambda_n' class='latex' /> then <img src='http://s.wordpress.com/latex.php?latex=%28C%2Ba%5Ccdot%20I%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(C+a\cdot I)' title='(C+a\cdot I)' class='latex' /> has the eigenvalues <img src='http://s.wordpress.com/latex.php?latex=%5Clambda_1%2Ba%5Cleq%5Cldots%5Cleq%5Clambda_n%2Ba&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\lambda_1+a\leq\ldots\leq\lambda_n+a' title='\lambda_1+a\leq\ldots\leq\lambda_n+a' class='latex' /> since <img src='http://s.wordpress.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x' title='x' class='latex' /> is a solution of <img src='http://s.wordpress.com/latex.php?latex=%5Cdet%28C-x%5Ccdot%20I%29%3D0&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\det(C-x\cdot I)=0' title='\det(C-x\cdot I)=0' class='latex' /> if and only if <img src='http://s.wordpress.com/latex.php?latex=x%2Ba&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x+a' title='x+a' class='latex' /> is a solution of <img src='http://s.wordpress.com/latex.php?latex=%5Cdet%28C%2Ba%5Ccdot%20I-x%5Ccdot%20I%29%3D%5Cdet%28C-%28x-a%29%5Ccdot%20I%29%3D0&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\det(C+a\cdot I-x\cdot I)=\det(C-(x-a)\cdot I)=0' title='\det(C+a\cdot I-x\cdot I)=\det(C-(x-a)\cdot I)=0' class='latex' />.</p>
<p>So we start again with a pseudo correlation matrix <img src='http://s.wordpress.com/latex.php?latex=C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C' title='C' class='latex' />, but instead of retrying when <img src='http://s.wordpress.com/latex.php?latex=C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C' title='C' class='latex' /> has negative eigen values, we lift the diagonal by <img src='http://s.wordpress.com/latex.php?latex=%5Clambda_1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\lambda_1' title='\lambda_1' class='latex' /> and obtain <img src='http://s.wordpress.com/latex.php?latex=C%2B%5Clambda_1%5Ccdot%20I&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='C+\lambda_1\cdot I' title='C+\lambda_1\cdot I' class='latex' />, which is always positive semidefinite. After dividing by <img src='http://s.wordpress.com/latex.php?latex=1%2B%5Clambda_1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='1+\lambda_1' title='1+\lambda_1' class='latex' /> we have a correlation matrix which is &#8220;some kind of random&#8221;. <img src='http://www.algorithm-forge.com/techblog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Unfortunatly the diagonal is accentuated and the smallest eigen value is always zero. We could avoid the second problem by adding <img src='http://s.wordpress.com/latex.php?latex=%5Clambda_1%2Bb&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\lambda_1+b' title='\lambda_1+b' class='latex' /> where <img src='http://s.wordpress.com/latex.php?latex=b&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='b' title='b' class='latex' /> is some random number, but the first remains.</p>
<div class="codecolorer-container r default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="r codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">make.positive.semi.definite <span style="color: #78aaac;">&lt;-</span><br />
<span style="color: #a020f0;">function</span><span style="color: #66cc66;">&#40;</span>a, offset<span style="color: #78aaac;">=</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span>a <span style="color: #78aaac;">+</span> <span style="color: #66cc66;">&#40;</span>diag<span style="color: #66cc66;">&#40;</span>dim<span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #78aaac;">*</span> <span style="color: #66cc66;">&#40;</span>abs<span style="color: #66cc66;">&#40;</span>min<span style="color: #66cc66;">&#40;</span>eigen<span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span>$values<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #78aaac;">+</span>offset<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #78aaac;">/</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #78aaac;">+</span><span style="color: #66cc66;">&#40;</span>abs<span style="color: #66cc66;">&#40;</span>min<span style="color: #66cc66;">&#40;</span>eigen<span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span>$values<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #78aaac;">+</span>offset<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<div class="codecolorer-container r default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="r codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">random.correlation.matrix.lift.diagonal <span style="color: #78aaac;">&lt;-</span><br />
<span style="color: #a020f0;">function</span><span style="color: #66cc66;">&#40;</span>n, offset<span style="color: #78aaac;">=</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; a <span style="color: #78aaac;">&lt;-</span> random.pseudo.correlation.matrix<span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span><br />
&nbsp; make.positive.semi.definite<span style="color: #66cc66;">&#40;</span>offset<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p><strong>Method 3 &#8211; Gramian matrix &#8211; my favorite:</strong> Holmes <a href="#holmes">[1]</a> discusses two principal methods for generating random correlation matrices.<br />
One of them is to generate <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> independent pseudo-random vectors <img src='http://s.wordpress.com/latex.php?latex=t_1%2C%5Cldots%2Ct_n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='t_1,\ldots,t_n' title='t_1,\ldots,t_n' class='latex' /> distributed uniformly on the unit sphere <img src='http://s.wordpress.com/latex.php?latex=S%5E%7Bn-1%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='S^{n-1}' title='S^{n-1}' class='latex' /> in <img src='http://s.wordpress.com/latex.php?latex=%5Cmathbb%7BR%7D%5En&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathbb{R}^n' title='\mathbb{R}^n' class='latex' /> and to use the <a href="http://en.wikipedia.org/wiki/Gramian_matrix">Gram matrix</a> <img src='http://s.wordpress.com/latex.php?latex=T%5EtT&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='T^tT' title='T^tT' class='latex' />, where <img src='http://s.wordpress.com/latex.php?latex=T%3A%3D%28t_1%2C%5Cldots%2Ct_n%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='T:=(t_1,\ldots,t_n)' title='T:=(t_1,\ldots,t_n)' class='latex' /> has <img src='http://s.wordpress.com/latex.php?latex=t_i&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='t_i' title='t_i' class='latex' /> as <img src='http://s.wordpress.com/latex.php?latex=i&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='i' title='i' class='latex' />-th column and <img src='http://s.wordpress.com/latex.php?latex=T%5Et&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='T^t' title='T^t' class='latex' /> is the transpose of <img src='http://s.wordpress.com/latex.php?latex=T&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='T' title='T' class='latex' />.</p>
<p>To create the <img src='http://s.wordpress.com/latex.php?latex=t_i&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='t_i' title='t_i' class='latex' /> in R, we load the package <a href="http://cran.r-project.org/web/packages/mvtnorm/index.html">mvtnorm</a>, generate <img src='http://s.wordpress.com/latex.php?latex=%5Ctau_i%5Csim%5Cmathcal%7BN%7D%280%2CI%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\tau_i\sim\mathcal{N}(0,I)' title='\tau_i\sim\mathcal{N}(0,I)' class='latex' /> and set <img src='http://s.wordpress.com/latex.php?latex=t_i%3A%3D%5Ctau_i%2F%7C%7C%5Ctau_i%7C%7C&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='t_i:=\tau_i/||\tau_i||' title='t_i:=\tau_i/||\tau_i||' class='latex' />:</p>
<div class="codecolorer-container r default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="r codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">random.correlation.matrix.sphere <span style="color: #78aaac;">&lt;-</span><br />
<span style="color: #a020f0;">function</span><span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; require<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;mvtnorm&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; t <span style="color: #78aaac;">&lt;-</span> rmvnorm<span style="color: #66cc66;">&#40;</span>n,rep<span style="color: #66cc66;">&#40;</span>0,n<span style="color: #66cc66;">&#41;</span>,diag<span style="color: #66cc66;">&#40;</span>n<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #a020f0;">for</span> <span style="color: #66cc66;">&#40;</span>i <span style="color: #a020f0;">in</span> <span style="color: #cc66cc;">1</span>:n<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; t<span style="color: #66cc66;">&#91;</span>i,<span style="color: #66cc66;">&#93;</span> <span style="color: #78aaac;">&lt;-</span> t<span style="color: #66cc66;">&#91;</span>i,<span style="color: #66cc66;">&#93;</span><span style="color: #78aaac;">/</span>sqrt<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#91;</span>i,<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #78aaac;">%*%</span>t<span style="color: #66cc66;">&#91;</span>i,<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; t<span style="color: #78aaac;">%*%</span>t<span style="color: #66cc66;">&#40;</span>t<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p><strong>Conclusion:</strong> There are futher methods (like e.g. to generate a random spectrum and then construct the correlation matrix), which are not all so easy to implement. But as much as the three given methods they all are unsatisfactory in some way because we don&#8217;t really know how random correlation matrices should be distributed.</p>
<p>For my colleague an average of calculation time does only make sense when he knows which kinds of correlation matrices occur in the applications. He decided to describe and compare the different cases individually.</p>
<p>But does it perhaps make sense to use random correlation matrices as test cases or are the special cases more important? For example random correlation matrices generated with method 1 and 3 are only singular with probability zero.</p>
<p>Any critique, comments, suggestions or questions are welcome!</p>
<p><strong>And for the next time:</strong> Given a correlation matrix C. How do we generate tuples of pseudo-random numbers following a given multivariate distribution with correlation matrix C?</p>
<p><strong>Literature:</strong><br />
<a name="holmes">Holmes, R. B. 1991.</a><br />
<em>On random correlation matrices.</em><br />
Siam J. Matrix Anal. Appl., Vol. 12 No. 2: 239-272.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm-forge.com/techblog/2009/08/random-correlation-matrices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
