# Detrend Data

Regression Analysis > Detrend Data

## What does it mean to Detrend Data?

Detrending is removing a trend from a time series; a trend usually refers to a change in the mean over time. When you detrend data, you remove an aspect from the data that you think is causing some kind of distortion. For example, you might detrend data that shows an overall increase, in order to see subtrends. Usually, these subtrends are seen as fluctuations on a time series graph.

## Detrending Methods

You must know the underlying structure of the trend in order to detrend it. For example, if you have a simple linear trend for the mean, calculate the least squares regression line to estimate the growth rate, r. Then subtract the deviations from the least squares fit line (i.e. the differences) from your data.

Many other methods exist, some of which are very complex. For example:

• Quadratic detrending is similar to linear detrending with one major difference: you assume the data follows an exponential patterns and add a time2.
• Moving average trend lines can be detrended with the Baxter-King filter.
• Cyclical components of time series can be removed with the Hodrick-Prescott filter.

Detrending techniques are often very specific to your field of study; if you have data that isn’t linearly correlated, you may want to look for subject-specific detrending methods.

## Using Technology

Most statistical software packages have options to detrend. For example:
In Matlab:
Use one of the following commands:

• y = detrend(x) to remove the best straight-line fit from vector x.
• y = detrend(x,’constant’) to remove the mean value from vector x.
• y = detrend(x,’linear’,bp) to remove a continuous, piecewise linear trend from vector x.