# Determining trend significance in a time series

I have some time series data and want to test for the existence of and estimate the parameters of a linear trend in a dependent variable w.r.t. time, i.e. time is my independent variable. The time points cannot be considered IID under the null of no trend. Specifically, the error terms for points sampled near each other in time are positively correlated. Error terms for samples obtained at sufficiently different times can be considered IID for all practical purposes.

I do not have a well-specified model of how the error terms are correlated for points close to each other in time. All I know from domain knowledge is that they are positively correlated to some degree or another. Other than this issue, I believe the assumptions of ordinarly least squares linear regression (homoskedasticity, linearity, normally distributed error terms) are met. Modulo the correlated error term issue, OLS would solve my problem.

I am a complete novice at dealing with time series data. Is there any "standard" way to proceed in these circumstances?

What you are describing is commonly referred to as auto correlated errors. I would suggest you look up resources on ARIMA modelling. ARIMA modelling will allow you to model the correlation in your error term, and hence allow you to assess your trend variable independent of this auto correlation (or other independent variables you are interested in).

My suggested reading for an into to ARIMA modelling would be Applied Time Series Analysis for the Social Sciences 1980 by R McCleary ; R A Hay ; E E Meidinger ; D McDowall

But there are plenty of resources (time series analysis is a massive field of study). You would probably be able to turn up some good online resources with just a google search if you don't have access to an academic library. I just turned up this page, Statistica ARIMA, it has a brief but very concise description of ARIMA modelling as well as other methods for time series analysis.

To add to the existing answers, if you are using R a simple way to proceed is to allow the ARMA errors to be modelled automatically using auto.arima(). If x is your time series, then you can proceed as follows.

t <- 1:length(x)
auto.arima(x,xreg=t,d=0)


This will fit the model $x_t = a + bt + e_t$ where $e_t\sim\text{ARMA}(p,q)$ and $p$ and $q$ are selected automatically using the AIC.

The resulting output will give the value of $b$ and its standard error. Here is an example:

Series: x
ARIMA(3,0,0) with non-zero mean

Call: auto.arima(x = x, xreg = t)

Coefficients:
ar1     ar2      ar3  intercept       t
-0.3770  0.1454  -0.2351   563.9654  0.0376
s.e.   0.1107  0.1190   0.1145    11.4725  0.2378

sigma^2 estimated as 5541:  log likelihood = -475.85
AIC = 963.7   AICc = 964.81   BIC = 978.21


In this case, $p=3$ and $q=0$. The first three coefficients give the autoregressive terms, $a$ is the intercept and $b$ is in the t column. In this (artificial) example, the slope is not significantly different from zero.

The auto.arima function is using MLE rather than GLS, but the two are asymptotically equivalent.

The use of a Cochrane-Orcutt procedure only works if the error is AR(1). So the above is much more general and flexible.

• auto.arima is in the forecast package, isn't it? – Wayne Dec 6 '10 at 22:19
• @Wayne. Yes. Sorry I omitted that information. – Rob Hyndman Dec 6 '10 at 23:36

Generalised least squares (GLS) is one potential option here. The OLS estimates of the parameters are given by:

$$\hat{\beta} = (X^{T}\Sigma^{-1}X)^{-1}X^{T}\Sigma^{-1}y$$

Normally we leave out $\Sigma$ as in OLS it is defined as $\sigma^2 \mathbf{I}$, i.e. an identity matrix multiplied by the estimated residual standard error. $\mathbf{I}$ is the assumption of uncorrelated errors; an observation is perfectly correlated with itself and is uncorrelated with any other observation.

GLS relaxes this indepence assumption by allowing $\Sigma$ to take different forms. Usually we choose a simple process to parametrise $\Sigma$, such as an AR(1). In an AR(1) the correlation between two errors at times $t$ and $s$ is

$$\mathrm{cor}(\varepsilon_s \varepsilon_t) = \left\lbrace \begin{array}{ll} 1 & \mathrm{if} \; s = t \\ \rho^{|t-s|} & \mathrm{else} \\ \end{array} \right.$$

Which would give us the following error covariance matrix:

$$\mathbf{\Sigma} = \sigma^2 \left( \begin{array}{ccccc} 1 & \rho & \rho^2 & \cdots & \rho^{n-1} \\ \rho & 1 & \rho & \cdots & \rho^{n-2} \\ \rho^2 & \rho & 1 & \cdots & \rho^{n-3} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ \rho^{n-1} & \rho^{n-2} & \rho^{n-3} & \cdots & 1 \\ \end{array} \right)$$

An additional parameter estimate is required, $\rho$.

More complex processes for $\Sigma$ can be employed, including ARMA models. In R, these sorts of model s can be fitted using the gls() function in package nlme.

If you are an R user, you might also take a look at the sandwich package which allows for something similar to the above, but where you estimate the OLS model and then afterwards, estimate $\Sigma$ and use that as a plug-in value to correct the standard errors of the OLS parameters.

Along the lines of a previous answer, if all assumptions for OLS are met except for the fact that errors are correlated, maybe something as simple as a Cochrane-Orcutt correction would be enough to solve your problem.