Search code examples
rtime-seriesregressionlinear-regressionpolar-coordinates

Appropriate ways to smooth a periodic time series?


I have a periodic time series, of air temperature over several years, and I want to be able to predict future values for it.

I've calculated the average over the available years of the value at each hour of the year, which works ok, but it's clearly quite noisy, since I only have 4 years data.

  • One way forward could be to do gaussian smoothing, but a better option might be to fit a spline to it.
  • I searched and found lm.circular, which looks like a feasible solution candidate.
    • It doesn't have any way of specifying a formula, so no way of asking it to fit a spline.
    • I tried lm.circular using a 1-order polynomial, but a practical problem arose: it ran out of memory. Note that a standard lm is almost instantaneous, and uses no noticeable memory, on the same data
    • I also tried asking it to fit a Von Mises (type='c-l'), and it asked me for an 'init' parameter, and I couldn't really understand from the description what I was supposed to put into 'init'?
  • Using the normal lm is not really an option, since it gives terrible results at either end of the period.
  • I suppose another possibility is to use ets/HoltWinters, with a timeseries frequency equal to the number of hours in the year?

I'm not quite sure which way is the best way forward, but I suspect that this is a pretty common problem, and there are probably very standard ways of dealing with it?


Solution

  • Ok, I found a super-easy way in the end. You don't need any fancy packages, you simply use standard lm and apply cosine and sine to the timeline:

    model <- lm( y ~ I(sin(x/periodlength*2*pi) * I(cos(x/periodlength*2*pi)), trainingdata )
    

    ... .then you can tweak this formula to your heart's content.

    (Edit: oh yeah, and it's super fast and doesn't use much memory).