<?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>johnramey &#187; code</title>
	<atom:link href="http://johnramey.net/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnramey.net/blog</link>
	<description>Don&#039;t think. Compute.</description>
	<lastBuildDate>Wed, 07 Dec 2011 23:52:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Autocorrelation Matrix in R</title>
		<link>http://johnramey.net/blog/2010/12/26/autocorrelation-matrix-in-r/</link>
		<comments>http://johnramey.net/blog/2010/12/26/autocorrelation-matrix-in-r/#comments</comments>
		<pubDate>Sun, 26 Dec 2010 04:55:09 +0000</pubDate>
		<dc:creator>ramhiser</dc:creator>
				<category><![CDATA[r]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://johnramey.net/blog/?p=12</guid>
		<description><![CDATA[I have been simulating a lot of data lately  with various covariance (correlation) structures, and one that I have been using is the autocorrelation (or autoregressive) structure, where there is a &#8220;lag&#8221; between variables. The matrix is a v-dimension matrix of the form $$\begin{bmatrix} 1 &#38; \rho &#38; \rho^2 &#38; \dots &#38; \rho^{v-1}\\ \rho &#38; [...]]]></description>
			<content:encoded><![CDATA[<p>I have been simulating a lot of data lately  with various covariance (correlation) structures, and one that I have been using is the autocorrelation (or autoregressive) structure, where there is a &#8220;lag&#8221; between variables. The matrix is a v-dimension matrix of the form</p>
<p>$$\begin{bmatrix} 1 &amp; \rho &amp; \rho^2 &amp; \dots &amp; \rho^{v-1}\\ \rho &amp; 1&amp; \ddots &amp; \dots &amp; \rho^{v-2}\\ \vdots &amp; \ddots &amp; \ddots &amp; \ddots &amp; \vdots\\ \rho^{v-2} &amp; \dots &amp; \ddots &amp; \ddots &amp; \rho\\ \rho^{v-1} &amp; \rho^{v-2} &amp; \dots &amp; \rho &amp; 1 \end{bmatrix}$$,</p>
<p>where \(\rho \in [-1, 1]\) is the lag. Notice that the lag decays to 0 as v increases.</p>
<p>My goal was to make the construction of such a matrix simple and easy in R.  The method that I used explored a function I have not used yet in R called &#8220;lower.tri&#8221; for the lower triangular part of the matrix.  The upper triangular part is referenced with &#8220;upper.tri.&#8221;</p>
<p>My code is as follows:</p>

<div class="wp_codebox"><table><tr id="p123"><td class="code" id="p12code3"><pre class="c" style="font-family:monospace;">autocorr.<span style="color: #202020;">mat</span></pre></td></tr></table></div>

<p>I really liked it because I feel that it is simple, but then I found <a href="http://tolstoy.newcastle.edu.au/R/e2/help/07/05/16585.html">Professor Peter Dalgaard&#8217;s method</a>, which I have slightly modified. It is far better than mine, easy to understand, and slick. Oh so slick. Here it is:</p>

<div class="wp_codebox"><table><tr id="p124"><td class="code" id="p12code4"><pre class="c" style="font-family:monospace;">autocorr.<span style="color: #202020;">mat</span></pre></td></tr></table></div>

<p>Professor Dalgaard&#8217;s method puts mine to shame. It is quite obvious how to do it once it is seen, but I certainly wasn&#8217;t thinking along those lines.</p>
]]></content:encoded>
			<wfw:commentRss>http://johnramey.net/blog/2010/12/26/autocorrelation-matrix-in-r/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

