<!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.&nbsp; This results in almost no smoothing while spar=1600 causes an error.&nbsp; The smooth.spline function seems to want something in the region of 0 to 1.&nbsp; The closer spar is to 1, the greater the smoothing.&nbsp; 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.&nbsp; 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.&nbsp; A general answer would be nice as I don't always work with quarterly data.</FONT></P>

<P><FONT SIZE=2>Thanks &amp; 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:&nbsp;&nbsp;&nbsp; <A HREF="http://www.econ.uiuc.edu" TARGET="_blank">http://www.econ.uiuc.edu</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Roger Koenker</FONT>
<BR><FONT SIZE=2>email&nbsp;&nbsp; roger@ysidro.econ.uiuc.edu&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Department of Economics</FONT>
<BR><FONT SIZE=2>vox: &nbsp;&nbsp; 217-333-4558&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; University of Illinois</FONT>
<BR><FONT SIZE=2>fax:&nbsp;&nbsp;&nbsp; 217-244-6678&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Champaign, IL 61820</FONT>
</P>

<P><FONT SIZE=2>On Thu, 6 Dec 2001, Nick Davis wrote:</FONT>
</P>

<P><FONT SIZE=2>&gt; Has anyone written any code for the Hodrick-Prescott filter?&nbsp; I have a some</FONT>
<BR><FONT SIZE=2>&gt; uncompiled FORTRAN code from Ed Prescott but I'd like to save myself some</FONT>
<BR><FONT SIZE=2>&gt; programming time if possible.&nbsp; Thanks for your help.</FONT>
<BR><FONT SIZE=2>&gt;</FONT>
<BR><FONT SIZE=2>&gt; Nick Davis</FONT>
<BR><FONT SIZE=2>&gt; Crown Financial Policy</FONT>
<BR><FONT SIZE=2>&gt; Asset and Liability Management Branch</FONT>
<BR><FONT SIZE=2>&gt; The New Zealand Treasury</FONT>
<BR><FONT SIZE=2>&gt;</FONT>
<BR><FONT SIZE=2>&gt; Direct:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +64-4-471-5924</FONT>
<BR><FONT SIZE=2>&gt; Fax:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +64-4-499-0143</FONT>
<BR><FONT SIZE=2>&gt; Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A HREF="mailto:nick.davis@treasury.govt.nz">mailto:nick.davis@treasury.govt.nz</A></FONT>
<BR><FONT SIZE=2>&gt; Web:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; www.treasury.govt.nz</FONT>
<BR><FONT SIZE=2>&gt; Research:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; www.treasury.govt.nz/workingpapers</FONT>
<BR><FONT SIZE=2>&gt;</FONT>
<BR><FONT SIZE=2>&gt;</FONT>
<BR><FONT SIZE=2>&gt; Caution: The content of this email is the property of The New Zealand</FONT>
<BR><FONT SIZE=2>&gt; Treasury. If you have received this message in error please notify the</FONT>
<BR><FONT SIZE=2>&gt; sender immediately and delete.&nbsp; The content of this email does not</FONT>
<BR><FONT SIZE=2>&gt; necessarily reflect the views of The New Zealand Treasury.&nbsp; If the recipient</FONT>
<BR><FONT SIZE=2>&gt; has any concerns about the content of this email they should seek</FONT>
<BR><FONT SIZE=2>&gt; alternative confirmation from The New Zealand Treasury.</FONT>
<BR><FONT SIZE=2>&gt;</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 &quot;info&quot;, &quot;help&quot;, or &quot;[un]subscribe&quot;</FONT>
<BR><FONT SIZE=2>(in the &quot;body&quot;, not the subject !)&nbsp; To: r-help-request@stat.math.ethz.ch</FONT>
<BR><FONT SIZE=2>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._</FONT>
</P>

</BODY>
</HTML>