[R] Code for Hodrick-Prescott Filter: Special Case of smooth. spline?
Roger Koenker
roger at ysidro.econ.uiuc.edu
Thu Dec 13 23:09:58 CET 2001
A general answer would be to forget the Hodrick-Prescott numerology for
lambda=1600, and use the spar parameter produced by smooth.spline's
GCV functionality. Nevertheless, it would be nice for reproducibility
(comparison) reasons to be able to get the actual lambda corresponding
to spar. My quick look at the code didn't yield an easy way to extract the
ratio: r = tr(X' W^2 X) / tr(Sigma), and thereby get back to lambda.
Maybe Brian could suggest something for this.
I might also note that the Hodrick Prescott setup would require that
you set all.knots=TRUE, since the default in smooth.spline
is to chose fewer knots. The HP penalty assumes equally spaced x's
so the penalty is just the sum of the second differences of ghat.
For those of you (if any) who are wondering what the Hodrick-Prescott
filter is: in effect it is the special case of the (Reinsch) cubic
smoothing spline for an equally spaced time series. HP claim that
for (typical quarterly economic time-series) lambda can be chosen
to be 1600, and (amazingly) this has become a default smoother in some
circles of macroeconometrics.
url: http://www.econ.uiuc.edu Roger Koenker
email roger at ysidro.econ.uiuc.edu Department of Economics
vox: 217-333-4558 University of Illinois
fax: 217-244-6678 Champaign, IL 61820
On Fri, 14 Dec 2001, Nick Davis wrote:
> I've had a play with this and, due to my own short-comings, remain none the
> wiser.
>
> In particular, I'm not sure what value of 'spar' is consistent with the
> magic lambda=1/1600 for quarterly data.
>
> 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:
>
> 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.
>
> 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.
>
> 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.
>
> Thanks & Regards,
>
> Nick Davis
>
> -----Original Message-----
> From: Roger Koenker [mailto:roger at ysidro.econ.uiuc.edu]
> Sent: Thursday, 6 December 2001 11:03 a.m.
> To: Nick Davis
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] Code for Hodrick-Prescott Filter
>
>
> This is a special case of smooth.spline in modreg.
>
>
> url: http://www.econ.uiuc.edu Roger Koenker
> email roger at ysidro.econ.uiuc.edu Department of Economics
> vox: 217-333-4558 University of Illinois
> fax: 217-244-6678 Champaign, IL 61820
>
> On Thu, 6 Dec 2001, Nick Davis wrote:
>
> > Has anyone written any code for the Hodrick-Prescott filter? I have a
> some
> > uncompiled FORTRAN code from Ed Prescott but I'd like to save myself some
> > programming time if possible. Thanks for your help.
> >
> > Nick Davis
> > Crown Financial Policy
> > Asset and Liability Management Branch
> > The New Zealand Treasury
> >
> > Direct: +64-4-471-5924
> > Fax: +64-4-499-0143
> > Email: mailto:nick.davis at treasury.govt.nz
> > Web: www.treasury.govt.nz
> > Research: www.treasury.govt.nz/workingpapers
> >
> >
> > Caution: The content of this email is the property of The New Zealand
> > Treasury. If you have received this message in error please notify the
> > sender immediately and delete. The content of this email does not
> > necessarily reflect the views of The New Zealand Treasury. If the
> recipient
> > has any concerns about the content of this email they should seek
> > alternative confirmation from The New Zealand Treasury.
> >
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list