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 time
^{2}. - 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. For example, Dave Meko of The University of Arizona has detailed notes about various types of detrending techniques used in tree-ring research. You can find those notes here.

## 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.

**Need help with a homework or test question?** With Chegg Study, you can get step-by-step solutions to your questions from an expert in the field. If you rather get 1:1 study help, Chegg Tutors offers 30 minutes of free tutoring to new users, so you can try them out before committing to a subscription.

If you prefer an **online interactive environment** to learn R and statistics, this *free R Tutorial by Datacamp* is a great way to get started. If you're are somewhat comfortable with R and are interested in going deeper into Statistics, try *this Statistics with R track*.

**Comments? Need to post a correction?** Please post a comment on our *Facebook page*.

Check out our updated Privacy policy and Cookie Policy