0
$\begingroup$

I have a time-series of daily measurements of some quantity for 1995-2011. There's about one measurement every three days.

The data show a strong seasonality (annual cycle).

What I ultimately want is get an estimation for the underlying trend. STL decomposition works fine and gives me seperate trend, seasonality, and noise components of my original time series. But how do I get a quantitative measure for the trend component? A simple linear regression won't do due to the autocorrelation in the noise component. Gavin Simpson suggested using gls() from R's nlme package, but I'm not sure how I should do that. Which would be the inputs for gls()?

Or, are there other suggestions for tackling my problem?

Any help is greatly appreciated :)

$\endgroup$

1 Answer 1

3
$\begingroup$

You can't get a "slope" because STL allows for a nonlinear trend. But you can get the numerical values of the trend as follows:

require(fpp)
la10 <- log(a10)
fit <- stl(la10,s.window="periodic")
trend <- fit$time.series[,"trend"]
plot(la10)
lines(trend,col="red")

If you really want a linear trend, then don't use stl(). Instead, fit a linear trend with seasonal factors:

fit2 <- tslm(la10 ~ trend + season)
n <- length(la10)
plot(la10)
lines(ts(fit2$coef[1]+fit2$coef[2]*(1:n)+mean(fit2$coef[-(1:2)]),
  start=start(la10),f=12),col="red")

Then fit2$coef["trend"] gives the slope of the fitted trend.

I've chosen an example where the trend is relatively linear. In many examples, the trend will be non-linear and the linear model approach will not work.

I've ignored the serial correlation in the residuals, so the estimate of the trend is not efficient, but it is still unbiased.

You can do better using Arima() with xreg containing the trend and seasonal dummy variables.

$\endgroup$
2
  • $\begingroup$ Thanks, what you say makes sense. However, I'm missing something. The trend output from STL is a whole time-series in its own. If I want to describe it, I'll need to fit some model to it. (in my question I chose linear). Now I understand from your answer that I shouldn't fit a model to the trend output from STL. Or do I misunderstand you? $\endgroup$
    – andreas-h
    Commented May 16, 2012 at 16:30
  • $\begingroup$ stl is a nonparametric procedure. The trend component is a numerical estimate of the nonlinear trend. If you want a parametric model, don't use stl. $\endgroup$ Commented May 16, 2012 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.