<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2650.12">
<TITLE>RE: [R] Code for Hodrick-Prescott Filter: Special Case of smooth.spline?</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>I've had a play with this and, due to my own short-comings, remain none the wiser.</FONT>
</P>
<P><FONT SIZE=2>In particular, I'm not sure what value of 'spar' is consistent with the magic lambda=1/1600 for quarterly data. </FONT>
</P>
<P><FONT SIZE=2>I initially interpreted spar as lambda and tried setting spar=1/1600. This results in almost no smoothing while spar=1600 causes an error. The smooth.spline function seems to want something in the region of 0 to 1. The closer spar is to 1, the greater the smoothing. A closer look at the R documentation revealed that:</FONT></P>
<P><FONT SIZE=2>The computational lambda used (as a function of `spar') is lambda = r * 256^(3*spar - 1) where r = tr(X' W^2 X) / tr(Sigma), Sigma is the matrix given by Sigma[i,j] = Integral B''[i](t) B''[j](t) dt, X is given by X[i,j] = B[j](x[i]), W^2 is the diagonal matrix of scaled weights, `W = diag(w)/n' (i.e., the identity for default weights), and B[k](.) is the k-th B-spline.</FONT></P>
<P><FONT SIZE=2>I admit to being a bit confused by the matrix algebra. It appears to come down to knowing 'r' so that 'spar' can be derived by imposing a constraint on lambda.</FONT></P>
<P><FONT SIZE=2>If anyone can shed some light on this it would be much appreciated. A general answer would be nice as I don't always work with quarterly data.</FONT></P>
<P><FONT SIZE=2>Thanks & Regards,</FONT>
</P>
<P><FONT SIZE=2>Nick Davis</FONT>
</P>
<P><FONT SIZE=2>-----Original Message-----</FONT>
<BR><FONT SIZE=2>From: Roger Koenker [<A HREF="mailto:roger@ysidro.econ.uiuc.edu">mailto:roger@ysidro.econ.uiuc.edu</A>]</FONT>
<BR><FONT SIZE=2>Sent: Thursday, 6 December 2001 11:03 a.m.</FONT>
<BR><FONT SIZE=2>To: Nick Davis</FONT>
<BR><FONT SIZE=2>Cc: r-help@stat.math.ethz.ch</FONT>
<BR><FONT SIZE=2>Subject: Re: [R] Code for Hodrick-Prescott Filter</FONT>
</P>
<BR>
<P><FONT SIZE=2>This is a special case of smooth.spline in modreg.</FONT>
</P>
<BR>
<P><FONT SIZE=2>url: <A HREF="http://www.econ.uiuc.edu" TARGET="_blank">http://www.econ.uiuc.edu</A> Roger Koenker</FONT>
<BR><FONT SIZE=2>email roger@ysidro.econ.uiuc.edu Department of Economics</FONT>
<BR><FONT SIZE=2>vox: 217-333-4558 University of Illinois</FONT>
<BR><FONT SIZE=2>fax: 217-244-6678 Champaign, IL 61820</FONT>
</P>
<P><FONT SIZE=2>On Thu, 6 Dec 2001, Nick Davis wrote:</FONT>
</P>
<P><FONT SIZE=2>> Has anyone written any code for the Hodrick-Prescott filter? I have a some</FONT>
<BR><FONT SIZE=2>> uncompiled FORTRAN code from Ed Prescott but I'd like to save myself some</FONT>
<BR><FONT SIZE=2>> programming time if possible. Thanks for your help.</FONT>
<BR><FONT SIZE=2>></FONT>
<BR><FONT SIZE=2>> Nick Davis</FONT>
<BR><FONT SIZE=2>> Crown Financial Policy</FONT>
<BR><FONT SIZE=2>> Asset and Liability Management Branch</FONT>
<BR><FONT SIZE=2>> The New Zealand Treasury</FONT>
<BR><FONT SIZE=2>></FONT>
<BR><FONT SIZE=2>> Direct: +64-4-471-5924</FONT>
<BR><FONT SIZE=2>> Fax: +64-4-499-0143</FONT>
<BR><FONT SIZE=2>> Email: <A HREF="mailto:nick.davis@treasury.govt.nz">mailto:nick.davis@treasury.govt.nz</A></FONT>
<BR><FONT SIZE=2>> Web: www.treasury.govt.nz</FONT>
<BR><FONT SIZE=2>> Research: www.treasury.govt.nz/workingpapers</FONT>
<BR><FONT SIZE=2>></FONT>
<BR><FONT SIZE=2>></FONT>
<BR><FONT SIZE=2>> Caution: The content of this email is the property of The New Zealand</FONT>
<BR><FONT SIZE=2>> Treasury. If you have received this message in error please notify the</FONT>
<BR><FONT SIZE=2>> sender immediately and delete. The content of this email does not</FONT>
<BR><FONT SIZE=2>> necessarily reflect the views of The New Zealand Treasury. If the recipient</FONT>
<BR><FONT SIZE=2>> has any concerns about the content of this email they should seek</FONT>
<BR><FONT SIZE=2>> alternative confirmation from The New Zealand Treasury.</FONT>
<BR><FONT SIZE=2>></FONT>
</P>
<P><FONT SIZE=2>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-</FONT>
<BR><FONT SIZE=2>r-help mailing list -- Read <A HREF="http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html" TARGET="_blank">http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html</A></FONT>
<BR><FONT SIZE=2>Send "info", "help", or "[un]subscribe"</FONT>
<BR><FONT SIZE=2>(in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch</FONT>
<BR><FONT SIZE=2>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._</FONT>
</P>
</BODY>
</HTML>