Course contentsShow
← Data Science
Lesson 739 of 2,14519. Time Series FoundationsFree lesson

Moving Average Detrending

Estimate and remove trends using rolling averages to smooth out fluctuations and isolate residuals.

Moving Average Detrending

You'll learn how to remove trends from time series data using rolling averages to reveal underlying patterns and random fluctuations.

The Core Idea

Moving average detrending is a smoothing technique that estimates the trend in your time series by calculating rolling averages over a window of data points. Once you've identified this smooth trend line, you subtract it from your original data to get residuals—what's left after removing the trend component.

Think of it like removing a steady hill from a bumpy road. The hill represents the long-term upward or downward direction (the trend), while the bumps are the short-term fluctuations you want to study. By "flattening" the hill, you can focus on just the bumps.

How It Works

  1. Choose a window size (e.g., 7 days, 12 months) based on how much smoothing you want
  2. Calculate the rolling average at each point using that window
  3. Subtract the moving average from the original series to get detrended data

The moving average acts as your trend estimate. Larger windows create smoother trends; smaller windows track changes more closely but may retain some fluctuations you wanted to remove.

Why Use This Method?

Unlike linear detrending (which assumes a straight-line trend), moving average detrending can capture non-linear trends that curve or change direction over time. It's particularly useful when your data's long-term pattern isn't a simple upward or downward slope.

The residuals you extract help you analyze seasonality, cycles, and irregular components without the trend masking these patterns.

Key Takeaway: Moving average detrending removes flexible, non-linear trends by smoothing the data with rolling averages and subtracting that smooth trend to isolate meaningful fluctuations and residuals.