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 🙂

**Contents**hide

#### Best Answer

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.

### Similar Posts:

- Solved – Calculate trend slope after STL decomposition
- Solved – Calculate trend slope after STL decomposition
- Solved – Why do we detrend or remove seasonality from a data when doing time series analysis
- Solved – Why do we detrend or remove seasonality from a data when doing time series analysis
- Solved – Why Time series decomposition is performed