Follow ______ on twitter.

7.3.2 Exponential Smoothing Methods

Code

Vega-Lite Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "Differentiated Exponential Smoothing Methods Applied to Synthetic Time Series Data",
  "data": {
    "sequence": {
      "start": 1,
      "stop": 365,
      "step": 1,
      "as": "day"
    }
  },
  "transform": [
    {
      "calculate": "0.1 * datum.day + 0.0007 * pow(datum.day, 2)",
      "as": "trend"
    },
    {
      "calculate": "15 * sin(2 * PI * datum.day / (365 / 4))",
      "as": "seasonality"
    },
    {
      "calculate": "20 * sin(2 * PI * datum.day / (365 / 2))",
      "as": "cyclicality"
    },
    {
      "calculate": "sampleNormal(0, 10)",
      "as": "noise"
    },
    {
      "calculate": "120 + datum.trend + datum.seasonality + datum.cyclicality + datum.noise",
      "as": "value"
    },
    {
      "window": [
        {
          "op": "mean",
          "field": "value",
          "as": "prev_smoothing"
        }
      ],
      "frame": [
        -1,
        -1
      ]
    },
    {
      "calculate": "0.2 * datum.value + 0.8 * datum.prev_smoothing",
      "as": "single_exponential"
    },
    {
      "window": [
        {
          "op": "mean",
          "field": "single_exponential",
          "as": "prev_double_smoothing"
        }
      ],
      "frame": [
        -1,
        -1
      ]
    },
    {
      "calculate": "datum.single_exponential + 0.2 * (datum.single_exponential - datum.prev_double_smoothing)",
      "as": "double_exponential"
    },
    {
      "window": [
        {
          "op": "mean",
          "field": "double_exponential",
          "as": "prev_triple_smoothing"
        }
      ],
      "frame": [
        -1,
        -1
      ]
    },
    {
      "calculate": "datum.double_exponential + 0.2 * (datum.double_exponential - datum.prev_triple_smoothing) + datum.seasonality",
      "as": "triple_exponential"
    }
  ],
  "hconcat": [
    {
      "title": "Single Exponential Smoothing",
      "layer": [
        {
          "mark": "line",
          "encoding": {
            "x": {
              "field": "day",
              "type": "quantitative",
              "title": "Day"
            },
            "y": {
              "field": "value",
              "type": "quantitative"
            },
            "color": {
              "value": "lightgray"
            }
          }
        },
        {
          "mark": "line",
          "encoding": {
            "x": {
              "field": "day",
              "type": "quantitative",
              "title": "Day"
            },
            "y": {
              "field": "single_exponential",
              "type": "quantitative",
              "title": "Value"
            },
            "color": {
              "value": "blue"
            }
          }
        }
      ]
    },
    {
      "title": "Double Exponential Smoothing",
      "layer": [
        {
          "mark": "line",
          "encoding": {
            "x": {
              "field": "day",
              "type": "quantitative",
              "title": "Day"
            },
            "y": {
              "field": "value",
              "type": "quantitative"
            },
            "color": {
              "value": "lightgray"
            }
          }
        },
        {
          "mark": "line",
          "encoding": {
            "x": {
              "field": "day",
              "type": "quantitative",
              "title": "Day"
            },
            "y": {
              "field": "double_exponential",
              "type": "quantitative",
              "title": "Value"
            },
            "color": {
              "value": "green"
            }
          }
        }
      ]
    },
    {
      "title": "Triple Exponential Smoothing",
      "layer": [
        {
          "mark": "line",
          "encoding": {
            "x": {
              "field": "day",
              "type": "quantitative",
              "title": "Day"
            },
            "y": {
              "field": "value",
              "type": "quantitative"
            },
            "color": {
              "value": "lightgray"
            }
          }
        },
        {
          "mark": "line",
          "encoding": {
            "x": {
              "field": "day",
              "type": "quantitative",
              "title": "Day"
            },
            "y": {
              "field": "triple_exponential",
              "type": "quantitative",
              "title": "Value"
            },
            "color": {
              "value": "red"
            }
          }
        }
      ]
    }
  ]
}