Follow ______ on twitter.

7.5.5 Advanced Topics in Time Series Analysis

Code

Vega-Lite Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "Comparison of Structural Breaks, Outliers, and Regime Switches in Time Series Data",
  "data": {
    "sequence": {
      "start": 0,
      "stop": 365,
      "step": 1,
      "as": "x"
    }
  },
  "transform": [
    {
      "calculate": "sin(datum.x / 58) * 20 + datum.x / 5 + (datum.x > 180 ? 30 : 0)",
      "as": "structural_break"
    },
    {
      "calculate": "sin(datum.x / 58) * 20 + datum.x / 5 + (random() < 0.05 ? 50 * random() : 0)",
      "as": "outliers"
    },
    {
      "calculate": "sin(datum.x / 58) * 20 + datum.x / 5 + (sin(datum.x / 30) > 0 ? 20 : 0)",
      "as": "regime_switch"
    }
  ],
  "hconcat": [
    {
      "width": 300,
      "height": 300,
      "title": "Structural Break",
      "mark": "line",
      "encoding": {
        "x": {
          "field": "x",
          "type": "quantitative",
          "title": "Time"
        },
        "y": {
          "field": "structural_break",
          "type": "quantitative",
          "title": "Value"
        }
      }
    },
    {
      "width": 300,
      "height": 300,
      "title": "Outliers",
      "mark": "point",
      "encoding": {
        "x": {
          "field": "x",
          "type": "quantitative",
          "title": "Time"
        },
        "y": {
          "field": "outliers",
          "type": "quantitative",
          "title": "Value"
        }
      }
    },
    {
      "width": 300,
      "height": 300,
      "title": "Regime Switch",
      "mark": "line",
      "encoding": {
        "x": {
          "field": "x",
          "type": "quantitative",
          "title": "Time"
        },
        "y": {
          "field": "regime_switch",
          "type": "quantitative",
          "title": "Value"
        }
      }
    }
  ]
}