Message-ID: <CF3C3733-9154-4CA5-AC16-663AF08A5BFB@ysidro.econ.uiuc.edu>
Date: 2009-04-04T19:37:55Z
From: Roger Koenker
Subject: Help using smooth.spline with zoo object
In-Reply-To: <32E60B1D2CC.000001F9bearmarketsrule@inbox.com>
For equally spaced observations this is quite simple and available in
various packages
but I like Gabor Grothendieck's version (which didn't come up
immediately in my Rseek search:
hpfilter <- function(y,lambda=1600)
eye <- diag(length(y))
solve(eye+lambda*crossprod(diff(eye,d=2)),y)}
url: www.econ.uiuc.edu/~roger Roger Koenker
email rkoenker at uiuc.edu Department of Economics
vox: 217-333-4558 University of Illinois
fax: 217-244-6678 Champaign, IL 61820
On Apr 4, 2009, at 2:19 PM, Rob Denniker wrote:
> Can someone please show me how to smooth time series data that I
> have in the form of a zoo object?
>
> I have a monthly economies series and all I really need is to see a
> less jagged line when I plot it.
>
> If I do something like
>
> s <- smooth.spline(d.zoo$Y, spar = 0.2)
> plot(predict(s,index(d.zoo)), xlab = "Year")
> # not defined for Date objects
>
> and if I do something like
>
> plot(predict(s,as.numeric(index(d.zoo))), xlab = "Year")
> # one straight line, no matter the value of spar
>
> What am I doing wrong? (The unsmoothed series plots just fine - a
> noisy upward trend)
>
> Thanks in advance.
>
> P.S. I would really just like to keep varying the penalty parameter
> 'lambda' of a Hodrick-Prescott filter until I get a 'smooth enough'
> series, but an archive search suggests that if I ask for this, some
> smarty pants will reply saying that the HP filter is just the
> smooth.spline function applied with a particular choice of lambda
> and equally spaced observations.
>
> ____________________________________________________________
> Receive Notifications of Incoming Messages
> Easily monitor multiple email accounts & access them with a click.
> Visit http://www.inbox.com/notifier and check it out!
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.