<?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>Probability and statistics blog &#187; Autoregressive model</title>
	<atom:link href="http://www.statisticsblog.com/tag/autoregressive-model/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.statisticsblog.com</link>
	<description>In Monte Carlo We Trust</description>
	<lastBuildDate>Mon, 16 Jan 2012 01:30:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Zone of instability</title>
		<link>http://www.statisticsblog.com/2010/05/zone-of-instability/</link>
		<comments>http://www.statisticsblog.com/2010/05/zone-of-instability/#comments</comments>
		<pubDate>Wed, 26 May 2010 16:47:38 +0000</pubDate>
		<dc:creator>Matt Asher</dc:creator>
				<category><![CDATA[r]]></category>
		<category><![CDATA[Autoregressive model]]></category>
		<category><![CDATA[instability]]></category>
		<category><![CDATA[markov chain]]></category>
		<category><![CDATA[normal]]></category>

		<guid isPermaLink="false">http://www.statisticsblog.com/?p=128</guid>
		<description><![CDATA[I woke up from my afternoon nap feeling a bit off-kilter, so I decided to go for another random walk. In particular, I wanted a journey that avoided the center, but didn&#8217;t just run for an exit either. After playing around for a while I came up with this: # Take a wacky walk, return [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.statisticsblog.com/wp-content/uploads/2010/05/wackyWalk.gif"><img src="http://www.statisticsblog.com/wp-content/uploads/2010/05/wackyWalk.gif" alt="" title="wackyWalk" width="480" height="480" class="alignnone size-full wp-image-137" /></a></p>
<p>I woke up from my afternoon nap feeling a bit off-kilter, so I decided to go for another random walk. In particular, I wanted a journey that <em>avoided</em> the center, but didn&#8217;t just run for an exit either. After playing around for a while I came up with this:</p>

<div class="wp_syntax"><div class="code"><pre class="rsplus" style="font-family:monospace;"><span style="color: #228B22;"># Take a wacky walk, return the final &quot;track&quot; steps</span>
wackyWalk <span style="color: #080;">&lt;-</span> <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span>iters, track<span style="color: #080;">=</span>iters<span style="color: #080;">&#41;</span> <span style="color: #080;">&#123;</span>
	locations <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
	mean2use <span style="color: #080;">=</span> <span style="color: #ff0000;">0</span>
	sd2use <span style="color: #080;">=</span> <span style="color: #ff0000;">1</span>
&nbsp;
	<span style="color: #0000FF; font-weight: bold;">for</span> <span style="color: #080;">&#40;</span>i <span style="color: #0000FF; font-weight: bold;">in</span> <span style="color: #ff0000;">1</span><span style="color: #080;">:</span>iters<span style="color: #080;">&#41;</span> <span style="color: #080;">&#123;</span>
		mean2use <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">1</span>,mean2use,sd2use<span style="color: #080;">&#41;</span> 
&nbsp;
		<span style="color: #228B22;"># The farther from the center, the smaller the variance</span>
		sd2use <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">abs</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">1</span><span style="color: #080;">/</span>mean2use<span style="color: #080;">&#41;</span>
		<span style="color: #0000FF; font-weight: bold;">if</span><span style="color: #080;">&#40;</span>track <span style="color: #080;">&gt;</span> <span style="color: #080;">&#40;</span>iters <span style="color: #080;">-</span> i<span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span> <span style="color: #080;">&#123;</span>
	 		locations <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span>locations, mean2use<span style="color: #080;">&#41;</span>
	 	<span style="color: #080;">&#125;</span>
	<span style="color: #080;">&#125;</span>
	<span style="color: #0000FF; font-weight: bold;">return</span><span style="color: #080;">&#40;</span>locations<span style="color: #080;">&#41;</span>
<span style="color: #080;">&#125;</span>
&nbsp;
<span style="color: #228B22;"># How many steps to take</span>
iters <span style="color: #080;">=</span> <span style="color: #ff0000;">300</span>
track <span style="color: #080;">=</span> <span style="color: #ff0000;">300</span>
locations <span style="color: #080;">=</span> wackyWalk<span style="color: #080;">&#40;</span>iters,track<span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;"># Start us off with a plot</span>
<span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">0</span>,<span style="color: #ff0000;">0</span>,xlim<span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">min</span><span style="color: #080;">&#40;</span>locations<span style="color: #080;">&#41;</span>,<span style="color: #0000FF; font-weight: bold;">max</span><span style="color: #080;">&#40;</span>locations<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>,ylim<span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">0</span>,iters<span style="color: #080;">&#41;</span>,pch<span style="color: #080;">=</span><span style="color: #ff0000;">20</span>,<span style="color: #0000FF; font-weight: bold;">col</span><span style="color: #080;">=</span><span style="color: #ff0000;">&quot;white&quot;</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">for</span> <span style="color: #080;">&#40;</span>i <span style="color: #0000FF; font-weight: bold;">in</span> <span style="color: #ff0000;">1</span><span style="color: #080;">:</span>track<span style="color: #080;">&#41;</span> <span style="color: #080;">&#123;</span>
	<span style="color: #0000FF; font-weight: bold;">points</span><span style="color: #080;">&#40;</span>locations<span style="color: #080;">&#91;</span>i<span style="color: #080;">&#93;</span>,i,pch<span style="color: #080;">=</span><span style="color: #ff0000;">20</span>,<span style="color: #0000FF; font-weight: bold;">col</span><span style="color: #080;">=</span><span style="color: #ff0000;">&quot;blue&quot;</span><span style="color: #080;">&#41;</span>
&nbsp;
	<span style="color: #228B22;"># To create a pseudo animation, take a break between plotting points</span>
	<span style="color: #0000FF; font-weight: bold;">Sys.<span style="">sleep</span></span><span style="color: #080;">&#40;</span>.10<span style="color: #080;">&#41;</span>
<span style="color: #080;">&#125;</span></pre></div></div>

<p>Basically, during each iteration the program samples from a normal distribution centered at the same location as the previous iteration, with standard deviation equal to the inverse of the previous location. So if the sequence is at 5, the next number will be sampled from the <img src='http://s.wordpress.com/latex.php?latex=Normal%285%2C%20%28%5Cfrac%7B1%7D5%29%5E2%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='Normal(5, (\frac{1}5)^2)' title='Normal(5, (\frac{1}5)^2)' class='latex' /> distribution.</p>
<p>Run it a few times and you&#8217;ll see how the blue dot bounces around for a bit near 0, then shoots off to one side or the other, where it will most likely hang out for the rest of its life. There are a number of interesting questions about this sequence which, sadly, will remain unanswered. Among these are: For a given number of iterations, how many times is this sequence expected to cross zero? What is the maximum (or minimum) value the sequence is expected to obtain over a fixed number of iterations? Will the sequence ever diverge to some flavor of infinity? </p>
<p>My hunch for this last question is to say no, since the normal distribution is thin-tailed, and the standard deviation is set to converge to 0 (slowly) as the value of the sequence gets larger and larger. At the same time, I suspect that the higher the number of iterations, the larger (in absolute terms) the final number in the sequence. This makes general sense, as the farther you get from 0, the harder it is to return to 0. During testing, I saw a lot of plots that wiggled back and forth, getting closer to the edges of the plot with each wiggle. Since I&#8217;m never content to just have a thought without actually testing it out, I plotted the final value in the sequence after <img src='http://s.wordpress.com/latex.php?latex=2%5Ex&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='2^x' title='2^x' class='latex' /> iterations, where x went from 1 to 20. Here&#8217;s the result:</p>
<p><a href="http://www.statisticsblog.com/wp-content/uploads/2010/05/wackyDestinations.gif"><img class="alignnone size-full wp-image-135" title="wackyDestinations" src="http://www.statisticsblog.com/wp-content/uploads/2010/05/wackyDestinations.gif" alt="" width="550" height="485" /></a></p>
<p>Sure enough, as a general trend, the more iterations you run, the farther you are from zero. It would have been interesting to see how the 8th trial ended up north of 300, but I only tracked the final result for these. I suspect that it made up most of the ground in a single leap while sampling from a Normal with extremely high variance (ie when the previous number was very close to 0).</p>
<p>Here&#8217;s the extra bit of code for comparing final location to number of iterations:</p>

<div class="wp_syntax"><div class="code"><pre class="rsplus" style="font-family:monospace;"><span style="color: #228B22;"># How does the number of steps compare with distance from center</span>
meta <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">for</span> <span style="color: #080;">&#40;</span>j <span style="color: #0000FF; font-weight: bold;">in</span> <span style="color: #ff0000;">1</span><span style="color: #080;">:</span><span style="color: #ff0000;">20</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#123;</span>
	iters <span style="color: #080;">=</span> <span style="color: #ff0000;">2</span><span style="color: #080;">^</span>j
	track <span style="color: #080;">=</span> <span style="color: #ff0000;">1</span>
	meta <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span>meta, wackyWalk<span style="color: #080;">&#40;</span>iters,track<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&#125;</span>
&nbsp;
<span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">1</span><span style="color: #080;">:</span><span style="color: #ff0000;">20</span>, <span style="color: #0000FF; font-weight: bold;">abs</span><span style="color: #080;">&#40;</span>meta<span style="color: #080;">&#41;</span>, pch<span style="color: #080;">=</span><span style="color: #ff0000;">20</span>, <span style="color: #0000FF; font-weight: bold;">col</span><span style="color: #080;">=</span><span style="color: #ff0000;">&quot;blue&quot;</span>,xlab<span style="color: #080;">=</span><span style="color: #ff0000;">&quot;2^x&quot;</span>,ylab<span style="color: #080;">=</span><span style="color: #ff0000;">&quot;abs value of final number in sequence&quot;</span><span style="color: #080;">&#41;</span></pre></div></div>

<p>These results, I should note, provide very little evidence that the sequence, if extended out to infinite length, will have to converge or diverge. Weird things happen when you start to consider random walks of infinite length, and the one sure limitation of Monte Carlo testing is that no matter how long let a computer simulation run, your PC will crash well before it performs an infinite number of calculations, and most likely before you finish your coffee. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.statisticsblog.com/2010/05/zone-of-instability/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

