Follow ______ on twitter.

6.1.5 Interpreting correlation and regression results

Code

Vega-Lite Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "width": 300,
  "height": 300,
  "data": {
    "values": [
      {
        "variable1": "Unemployment Rate",
        "variable2": "Unemployment Rate",
        "correlation": 1
      },
      {
        "variable1": "Unemployment Rate",
        "variable2": "GDP",
        "correlation": -0.7
      },
      {
        "variable1": "Unemployment Rate",
        "variable2": "Housing Starts",
        "correlation": -0.6
      },
      {
        "variable1": "Unemployment Rate",
        "variable2": "Household Income",
        "correlation": -0.4
      },
      {
        "variable1": "Unemployment Rate",
        "variable2": "Avg Credit Score",
        "correlation": -0.5
      },
      {
        "variable1": "GDP",
        "variable2": "Unemployment Rate",
        "correlation": -0.7
      },
      {
        "variable1": "GDP",
        "variable2": "GDP",
        "correlation": 1
      },
      {
        "variable1": "GDP",
        "variable2": "Housing Starts",
        "correlation": 0.8
      },
      {
        "variable1": "GDP",
        "variable2": "Household Income",
        "correlation": 0.75
      },
      {
        "variable1": "GDP",
        "variable2": "Avg Credit Score",
        "correlation": 0.6
      },
      {
        "variable1": "Housing Starts",
        "variable2": "Unemployment Rate",
        "correlation": -0.6
      },
      {
        "variable1": "Housing Starts",
        "variable2": "GDP",
        "correlation": 0.8
      },
      {
        "variable1": "Housing Starts",
        "variable2": "Housing Starts",
        "correlation": 1
      },
      {
        "variable1": "Housing Starts",
        "variable2": "Household Income",
        "correlation": 0.5
      },
      {
        "variable1": "Housing Starts",
        "variable2": "Avg Credit Score",
        "correlation": 0.45
      },
      {
        "variable1": "Household Income",
        "variable2": "Unemployment Rate",
        "correlation": -0.4
      },
      {
        "variable1": "Household Income",
        "variable2": "GDP",
        "correlation": 0.75
      },
      {
        "variable1": "Household Income",
        "variable2": "Housing Starts",
        "correlation": 0.5
      },
      {
        "variable1": "Household Income",
        "variable2": "Household Income",
        "correlation": 1
      },
      {
        "variable1": "Household Income",
        "variable2": "Avg Credit Score",
        "correlation": 0.55
      },
      {
        "variable1": "Avg Credit Score",
        "variable2": "Unemployment Rate",
        "correlation": -0.5
      },
      {
        "variable1": "Avg Credit Score",
        "variable2": "GDP",
        "correlation": 0.6
      },
      {
        "variable1": "Avg Credit Score",
        "variable2": "Housing Starts",
        "correlation": 0.45
      },
      {
        "variable1": "Avg Credit Score",
        "variable2": "Household Income",
        "correlation": 0.55
      },
      {
        "variable1": "Avg Credit Score",
        "variable2": "Avg Credit Score",
        "correlation": 1
      }
    ]
  },
  "layer": [
    {
      "mark": "rect",
      "encoding": {
        "x": {
          "field": "variable2",
          "type": "nominal",
          "axis": {
            "title": null,
            "labelFontSize": 14
          }
        },
        "y": {
          "field": "variable1",
          "type": "nominal",
          "axis": {
            "title": null,
            "labelFontSize": 14
          }
        },
        "color": {
          "field": "correlation",
          "type": "quantitative",
          "scale": {
            "domain": [
              -1,
              1
            ],
            "range": [
              "#ff6665",
              "white",
              "#00497688"
            ]
          },
          "legend": {
            "title": "Correlation",
            "labelFontSize": 14
          }
        }
      }
    },
    {
      "mark": {
        "type": "text",
        "baseline": "middle",
        "fontSize": 14
      },
      "encoding": {
        "x": {
          "field": "variable2",
          "type": "nominal"
        },
        "y": {
          "field": "variable1",
          "type": "nominal"
        },
        "text": {
          "field": "correlation",
          "type": "quantitative"
        },
        "color": {
          "condition": {
            "test": "datum.correlation > 0.5 || datum.correlation < -0.5",
            "value": "white"
          },
          "value": "black"
        }
      }
    }
  ],
  "config": {
    "view": {
      "stroke": "transparent"
    },
    "axis": {
      "domain": false,
      "ticks": false,
      "grid": false
    }
  }
}