[R] Code for Hodrick-Prescott Filter: Special Case of smooth. spline?

Nick Davis Nick.Davis at treasury.govt.nz
Thu Dec 13 21:28:38 CET 2001

I've had a play with this and, due to my own short-comings, remain none the

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
> 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
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://stat.ethz.ch/pipermail/r-help/attachments/20011214/545123ae/attachment.html

More information about the R-help mailing list