{"id":173,"date":"2008-03-07T20:20:33","date_gmt":"2008-03-08T04:20:33","guid":{"rendered":"http:\/\/rankexploits.com\/musings\/2008\/correcting-for-serial-autocorrelation-cochrane-orcutt\/"},"modified":"2008-03-07T20:34:37","modified_gmt":"2008-03-08T04:34:37","slug":"correcting-for-serial-autocorrelation-cochrane-orcutt","status":"publish","type":"post","link":"https:\/\/rankexploits.com\/musings\/2008\/correcting-for-serial-autocorrelation-cochrane-orcutt\/","title":{"rendered":"Correcting for Serial Autocorrelation: Cochrane Orcutt"},"content":{"rendered":"<p>Today, I&#8217;m going to try to apply  <a href=\"http:\/\/en.wikipedia.org\/wiki\/Cochrane-Orcutt_estimation\" rel=\"nofollow\">Cochrane-Orcutt<\/a> a method that could be used to deal with serial autocorrelation in residuals to a linear regression.  I hadn&#8217;t done this before, so I hunted down some references, and read how it&#8217;s supposed to be done.<\/p>\n<p>I have some result&#8211; but the problem is I really need someone to look them over and tell me if I&#8217;ve made a hash of this.  And, even more unfortunately, the only way to do that is to a) publish an analysis, even if it might be wrong.  <\/p>\n<p>So, I&#8217;ll be doing that, and hoping someone tells me what I&#8217;ve done right or wrong in applying the method.<\/p>\n<p>So, this post  organized as follows:<\/p>\n<ol>\n<li>Discussion of Least Squares applied to GMST data from 1979-Jan 2008 without correcting for red noise.<\/li>\n<li>Discussion of how I corrected for red noise using Cochrane-Orcutt. <\/li>\n<li>Discussion of  how I <i>think<\/i> one interprets the uncertainty intervals<\/li>\n<li>Questions for <i>real<\/i> statisticians!<\/li>\n<\/ol>\n<p>I&#8217;m asking questions because the issue of calculating the uncertainty intervals is key to validating or falsifying hypothesis. Today, I&#8217;m limiting my post to examining a long run of data, because the conclusions will be no surprise: Temperature rose since the late 70s.   This lets me illustrate what I have done, and get answers to questions without worrying dealing with any potentially controversial issues.<\/p>\n<p>So, here goes the boring post! <\/p>\n<h3>Ordinary Least Squares: Ignore Red Noise.<\/h3>\n<p>For the past few blog posts&#8211; and in many statistical analysis on the web, we&#8217;ve been assuming that GMST anomaly data can be described as obeying a linear trend with time, plus some amount of noise. The noise may be due to weather or measurement error or both.  That is, if we have a series of temperature, time pairs (T<sub>i<\/sub>,t<sub>i<\/sub>)  if denoted by  T<sub>i<\/sub>,  the data obeys the following equation: <\/p>\n<p>  <equation><eqnumber>(1)<\/eqnumber>  T<sub>i<\/sub>=( m t<sub>i<\/sub>+ b )+\u00ce\u00b5<sub>i<\/sub><\/equation><\/p>\n<p>where &#8220;m&#8221; is a trend in temperature over time, b is an intercept at t=0, and \u00ce\u00b5<sub>i<\/sub> is the &#8216;noise&#8217; or &#8216;residuals&#8217; associated with data point &#8216;i&#8217;. <\/p>\n<p>Now, if the values of \u00ce\u00b5<sub>i<\/sub> &#8212; the residuals&#8211; are all uncorrelated with each other, one can simply perform an OLS using a LINEST in Excel (or whatever tool you prefer.)  The values of the slope, m, and the intercept pop-out.   (They may be wrong. But Excel will give you numbers if you ask!)<\/p>\n<p><a href='http:\/\/rankexploits.com\/musings\/2008\/my-notes-on-cochrane-orcutt-applied-to-gmst\/these-are-anomalies-with-20-year-trends-shown\/' rel='attachment wp-att-160' title='These are anomalies with 20 year trends shown.'><img src='http:\/\/rankexploits.com\/musings\/wp-content\/uploads\/2008\/03\/anomalies_30year.jpg' alt='These are anomalies with 20 year trends shown.' \/><\/a>To the left, I show simple linear regression to monthly data obtained using Excel.<\/p>\n<p>Even better, LINEST provides values of the standard error in the slope, s<sub>m<\/sub>. Knowing that, and the number of data pairs used to create the fit permits the analyst to state 95% uncertainty intervals, or do simple hypothesis tests. <\/p>\n<p>In fact, using OLS results in fits like those illustrated in the figure to the left, where I include for GMST data sets plus the average of the four. As you can see, depending on which of four data sets for temperature measurements I used, the trend in temperature between 1978-2007 ranges from 1.8 C\/century to 1.4 C\/century.   <\/p>\n<p>For the my test case, I averaged the temperature measurements from all four souces; I get a m=1.6C\/century with a claimed standard error or s<sub>m<\/sub>=0.1 C\/century.  (If you download the EXCEL spread sheet,  this result is the fit to average temperature and year in columns C and D. LINEST is done in cell C364.)<\/p>\n<p>In principle, if GMST data really follows a linear fit as in (1), I can look up the &#8220;t&#8221; for 5% confidence bands, and I find t=1.967. (I used TINV with probability 0.05 and 346 degrees of freedom.)<\/p>\n<p>Using this &#8220;t&#8221;, I found  confidence bands by taking the product product (t s<sub>m<\/sub>=  \u00c2\u00b1(1.967) (1 C\/century). This results in: 1.5 C\/century &lt; m< 1.8 C\/century.  \n\nBut there is a problem: The trend,  \"m\" and <em>particularly<\/em> s<sub>m<\/sub> aren&#8217;t correct.  Why not, some might ask?<\/p>\n<h3>The Residuals Are Autocorrelated.<\/h3>\n<p><a href='http:\/\/rankexploits.com\/musings\/wp-content\/uploads\/2008\/03\/residuals.jpg' title='Residuals from Least Squares Fit to Global Mean Temperature Anomalies.'><img src='http:\/\/rankexploits.com\/musings\/wp-content\/uploads\/2008\/03\/residuals.thumbnail.jpg' alt='Residuals from Least Squares Fit to Global Mean Temperature Anomalies.' \/><\/a>It turns out that if I examine the values of the residuals, \u00ce\u00b5<sub>i<\/sub>, and calculate something called the &#8220;autocorrelation&#8221;, the residuals are strongly autocorrelated. (This is because weather trends tend to persist.)<\/p>\n<p>To calculate the residuals, I use the formula:<\/p>\n<p><equation><eqnumber>(2)<\/eqnumber> \u00ce\u00b5<sub>i<\/sub> = T<sub>i<\/sub>-( m t<sub>i<\/sub>+ b )<\/equation><\/p>\n<p>If I&#8217;ve found &#8220;m&#8221; and &#8220;b&#8221; with excel, this is easy to do.  I just put that in a column next to the (temperature, time) data ( T<sub>i<\/sub>, t<sub>i<\/sub>), enter the formula that matches (2) and create a column of residuals.<\/p>\n<p>I then look examine the autocorrelation of adjacent residuals by taking the ratio of two sums:<br \/>\n<equation><eqnumber>(3)<\/eqnumber> \u00cf\u0081 = \u00ce\u00a3\u00ce\u00b5<sub>i<\/sub>\u00ce\u00b5<sub>i-1<\/sub>\/ \u00ce\u00a3\u00ce\u00b5<sub>i<\/sub>\u00ce\u00b5<sub>i<\/sub>)<\/equation><\/p>\n<p>In Excel, is most easily done using the CORREL function. I did this for the &#8216;average&#8217; monthly GMST measured using four standard methods, and got \u00cf\u0081=0.78. (See cell E10, shown in green.)<\/p>\n<p>Now, it happens that there is a method to diagnose whether \u00cf\u0081=0.78 is statistically significant&#8211; but I haven&#8217;t learned it yet. Plus, for a correlation coefficient <i>this<\/i> large, I don&#8217;t need to. With 30 years worth of monthly data, I <em>know<\/em> \u00cf\u0081=0.78 is statistically significant. <\/p>\n<h3>Cochrane-Orcutt: Correction for Red Noise<\/h3>\n<p>I read about Cochrane-Orcutt. It appears to be very easy. <\/p>\n<p>The first step is to assume the errors in the residual are AR(1) noise with a serial autocorrelation of \u00cf\u0081.  If we know the &#8216;true&#8217; correlation for residuals, \u00cf\u0081, we can linearly transform the variables of interest (i.e. temperature and time) to new variables using some simple algebra.   Once we do this, we apply OLS to the <i>transformed<\/i> variables.   If we had really known the true correlation, \u00cf\u0081, we would now be done. The trend, m<sub>new<\/sub>, for the transformed variables is the same as for the original variables.  We can also obtain a new intercept,  b<sub>new<\/sub><\/p>\n<p>However, if we didn&#8217;t know the true \u00cf\u0081, we do something a bit more involved. It requires iteration, involving a number of relatively simple steps. <\/p>\n<p>The iteration: <\/p>\n<ol>\n<li>We <em>guess<\/em> for the &#8216;true&#8217; serial correlation for residuals,  \u00cf\u0081; I&#8217;ll call  the current guess \u00cf\u0081<sub>old<\/sub>. (It makes sense to pick the current guess from the OLS we already did. So, I pick \u00cf\u0081<sub>old<\/sub>=0.78 from above.) <\/li>\n<li>Using \u00cf\u0081<sub>old<\/sub>, transform the data set (T,t) into a new data set (X,Y). (Equation given later.) <\/li>\n<li>After doing this, we  obtain <i>new<\/i> estimates for slope and intercept (m<sub>new<\/sub>, b<sub>new<\/sub>).<\/li>\n<li>We then compute <i>new<\/i> residuals, using the updated slope and intercept. Calculate \u00cf\u0081<sub>new<\/sub> based on the <i>new<\/i> residuals.<\/li>\n<li>If \u00cf\u0081<sub>old<\/sub>=\u00cf\u0081<sub>new<\/sub> to some limit, we just decide that&#8217;s \u00cf\u0081, and use these current values of &#8220;m&#8221; and &#8220;b&#8221; as correct. Otherwise, we <\/li>\n<\/ol>\n<p>What I do involves a few steps:<br \/>\n<strong>Computational Step 1<\/strong>: Guess \u00cf\u0081<sub>old<\/sub>.  On my first try, I guessed \u00cf\u0081<sub>old<\/sub>=0.78 because that&#8217;s what I got for the OLS on T and t. (I  put this in cell E9 and named the variable Correl so I could later proof-read.)<\/p>\n<p><strong>Computational Step 2<\/strong>: Define  and calculate new transformed variables (X,Y) using these two formulas:<\/p>\n<p><equation><eqnumber>(4a&#038;b)<\/eqnumber><br \/>\nY<sub>i<\/sub>= T<sub>i<\/sub>-\u00cf\u0081<sub>old<\/sub>T<sub>i-1<\/sub> and X<sub>i<\/sub>= t<sub>i<\/sub>-\u00cf\u0081<sub>old<\/sub>t<sub>i-1<\/sub><\/equation><\/p>\n<p>To plug and chug, I just created columns for ( Y<sub>i<\/sub>, X<sub>i<\/sub>) adjacent to those for (T<sub>i<\/sub>,  t<sub>i<\/sub>) entered the formula and filled down. (Naturally, I have 1 less set of (Y,X) compared to (T,t). You can find Y and X in columns H and I. )<\/p>\n<p><strong>Computational Step 3:<\/strong> Perform a linear regression on (Y,X) to get new values for &#8220;m&#8221; and &#8220;\u00ce\u00b2&#8221;.  (I just use LINEST on (Y,X); m is the slope, \u00ce\u00b2 is the intercept.)<\/p>\n<p>That is, I assume Y and X obey:<\/p>\n<p><equation><eqnumber>(5)<\/eqnumber>Y<sub>i<\/sub>=( m X<sub>i<\/sub>+ \u00ce\u00b2 )+\u00ce\u00b5<sub>i<\/sub><\/equation><\/p>\n<p>I obtained the slope and intercept for Y vs. X using LINEST. The formula is in H364.<\/p>\n<p>It turns out that the best fit slope for equation (5) is expected to return the same value as equation (1) for (T,t) pairs. So, &#8220;m&#8221; from this new fit is the new improved &#8220;m<sub>new<\/sub>&#8220;.<\/p>\n<p>However, the new intercept is not &#8220;b<sub>new<\/sub>&#8220;.  The intercept from this linest is \u00ce\u00b2; this is related to the intercept in (1) as  \u00ce\u00b2= b*(1-\u00cf\u0081).   So, I to get a new improved &#8216;b<sub>new<\/sub>&#8216; . So, it can be calculated as b<sub>new<\/sub>=\u00ce\u00b2<sub>new<\/sub>\/(1-\u00cf\u0081<sub>old<\/sub>).<br \/>\n(This isn&#8217;t actually in a cell. I use it algebraically in step 5.)<br \/>\nNow, in principle, I have &#8220;new improved&#8221; values of &#8220;m&#8221; and &#8220;b&#8221;.<\/p>\n<p><strong>Computational Step 5<\/strong>: Now, using the <em>new<\/em> values of  &#8220;m<sub>new<\/sub>&#8221; and &#8220;b<sub>new<\/sub>&#8221; calculate use equation (2) and calculate <em>new<\/em> residuals, \u00ce\u00b5<sub>i<\/sub>,  using the original (T, t) pairs.  (I turned this into a new column, rather than replacing the old ones. It&#8217;s column F. )<\/p>\n<p><strong>Computational Step 6<\/strong>: Now, equation (3) to re-compute a new estimate for \u00cf\u0081<sub>new<\/sub>. (I used the &#8220;CORREL()&#8221; in Excel; see cell F10, in yellow.) <\/p>\n<p>Compare the new value of \u00cf\u0081 to the value you had before you began step 1.  If the new and old values agree withing some criteria you set, you are done! The most recent values of &#8220;m&#8221; and &#8220;b&#8221; are the converged values, and apply to this data sample.<\/p>\n<p>If the \u00cf\u0081 differ too much, guess a new value for \u00cf\u0081<sub>old<\/sub>. Your new guess should, of course be, \u00cf\u0081<sub>new<\/sub>!  <\/p>\n<p>Repeat computational steps 1-5 but starting with the new value of \u00cf\u0081. (I substituted the new \u00cf\u0081<sub>new<\/sub> for \u00cf\u0081<sub>old<\/sub> by copying the new value, and then pasting it into E9 using &#8220;paste special, pasting only values.).  <\/p>\n<p>It happens that this computation converged in one iteration. (I set the cells to read to 4 decimal places.)<\/p>\n<p>If a real statistician confirms this is correct, I&#8217;ll probably write a macro to simplify this. (I couldn&#8217;t find a free one for Excel.) But, I&#8217;m pretty sure that&#8217;s what all the various articles I found are telling me to do.<\/p>\n<h3>Results so far<\/h3>\n<p>Having done this, I now found m=1.5 C\/century and s<sub>m<\/sub>=0.3 C\/century for JAN, 1979-now.<\/p>\n<p>Now, I <i>think<\/i> that standard error <i>is<\/i> an honest to goodness standard error on the slope, &#8220;m&#8221;. I <i>think<\/i> I have 346 degrees of freedom for any t tests. The transformations (4 a&#038;b) were supposed to give me a set of independent uncorrelated variables. So, I think I could now go ahead and do t-test with this.<\/p>\n<h3>Question for Real Statisticians<\/h3>\n<p>Can I do hypothesis tests using s<sub>m<\/sub>=0.3 C\/century as the standard error to get confidence intervals? Are the number of degrees of freedom driven 346? (That&#8217;s three less than the 349 (T,t) data pairs I began with.)<\/p>\n<h3>But you aren&#8217;t <i>really<\/i> done.<\/h3>\n<p>Ok, that seems easy enough. Tedious, but easy.<\/p>\n<p>Unfortunately, there are a few more steps. Once you have the value of \u00cf\u0081, you should check the residuals on the <i>transformed<\/i> variables, X and Y, and see if those residuals are correlated. Mine had a correlation coefficient of -0.21.  <\/p>\n<p>If this second set of residuals are correlated to a level that is is statistically significant, you repeat to basically pretend your (X,Y) variables are &#8220;original&#8221; variables, and redo the fit. <\/p>\n<p>I skipped the test to see if \u00cf\u0081=-0.21 is statistically significant, and just assumed it was. (I will teach myself how to test later on. But for now, I figured, just assume it is.)<\/p>\n<p>When I finished this, my new results were:<\/p>\n<table style=\"width: 100%; text-align: left;\" border=\"2\" cellpadding=\"2\" cellspacing=\"2\">\n<caption>Temperature Trend and Standard Errors for &#8220;mean&#8221; GMST anomaly.<\/caption>\n<tbody>\n<tr>\n<td style=\"vertical-align: top;\"><\/td>\n<td style=\"text-align: center; vertical-align: top;\">No Correction<\/td>\n<td style=\"vertical-align: top;\">AR(1) correction.<\/td>\n<td style=\"vertical-align: top;\">AR(2) correction.<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top;\">m<\/td>\n<td style=\"vertical-align: top;\">1.6 C\/century<\/td>\n<td style=\"vertical-align: top;\">1.5 C\/century<\/td>\n<td style=\"vertical-align: top;\">1.5 C\/centuy<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top;\">s<sub>m<\/sub><\/td>\n<td style=\"vertical-align: top;\">\u00c2\u00b10.1 C\/century<\/td>\n<td style=\"vertical-align: top;\">\u00c2\u00b10.3 C\/century<\/td>\n<td style=\"vertical-align: top;\">\u00c2\u00b10.2 C\/century<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top;\">95% confidence intervals.<\/td>\n<td style=\"vertical-align: top;\">1.5 C\/century &lt; m< 1.8 C\/century<\/td>\n<td style=\"vertical-align: top;\">1.0 C\/century &lt; m< 2.1 C\/century<\/td>\n<td style=\"vertical-align: top;\">1.1 C\/century &lt; m< 2.0 C\/century<\/td>\n<\/tr>\n<tr>\n<td style=\"vertical-align: top;\">&rho; of residuals.<\/td>\n<td style=\"vertical-align: top;\">0.78<\/td>\n<td style=\"vertical-align: top;\">-0.21 <\/td>\n<td style=\"vertical-align: top;\">0.03<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Conclusions<\/h3>\n<p>I think I have applied Cochrane-Orcutt correctly to the monthly data from 1979-Jan. 2008.  My goal to day is simply to request feed back from statistician in the know: Did I do this correctly.<\/p>\n<p>I have done some reading, and understand that uncertainty intervals, while improved by using Cochrane-Orcut still tend to be too narrow. (I suspect this is because of the uncertainty in determining &rho;) <\/p>\n<p>So, if there are any real statisticians reading:<\/p>\n<ol>\n<li>Did I apply this technique correctly.<\/li>\n<li>Do I need to modify my uncertainty intervals? Of so, how do I do this?  <\/li>\n<\/ol>\n<p>To those wondering: Yes, I have done this for another more interesting data set. I have also attached the Excel spread sheet.  Obviously, you can modify to look at other data sets. But, before you fiddle, let&#8217;s wait to hear back from the econometricians to see if I understood the <i>method<\/i> correctly.<\/p>\n<p>&#8212;&#8211;<br \/>\nAttachment: <a href='http:\/\/rankexploits.com\/musings\/wp-content\/uploads\/2008\/03\/cochraneorcutt79_2008.xls' title='Excel SpreadSheet Cochrane Orcutt\u00e2\u20ac\u201c since 1979'>Excel SpreadSheet Cochrane Orcutt\u00e2\u20ac\u201c since 1979<\/a><\/p>\n<p>Question I asked at a blog: <a href=\"http:\/\/economistsview.typepad.com\/economics421\/2006\/02\/the_cochraneorc.html\">Standard Errors.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, I&#8217;m going to try to apply Cochrane-Orcutt a method that could be used to deal with serial autocorrelation in residuals to a linear regression. I hadn&#8217;t done this before, so I hunted down some references, and read how it&#8217;s supposed to be done. I have some result&#8211; but the problem is I really need &hellip; <a href=\"https:\/\/rankexploits.com\/musings\/2008\/correcting-for-serial-autocorrelation-cochrane-orcutt\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Correcting for Serial Autocorrelation: Cochrane Orcutt<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3],"tags":[],"class_list":["post-173","post","type-post","status-publish","format-standard","hentry","category-global-climate-change","category-statistics"],"_links":{"self":[{"href":"https:\/\/rankexploits.com\/musings\/wp-json\/wp\/v2\/posts\/173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rankexploits.com\/musings\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rankexploits.com\/musings\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rankexploits.com\/musings\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rankexploits.com\/musings\/wp-json\/wp\/v2\/comments?post=173"}],"version-history":[{"count":0,"href":"https:\/\/rankexploits.com\/musings\/wp-json\/wp\/v2\/posts\/173\/revisions"}],"wp:attachment":[{"href":"https:\/\/rankexploits.com\/musings\/wp-json\/wp\/v2\/media?parent=173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rankexploits.com\/musings\/wp-json\/wp\/v2\/categories?post=173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rankexploits.com\/musings\/wp-json\/wp\/v2\/tags?post=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}