Follow ______ on twitter.

8.1.3 Bayesian Networks

Code

Vega-Lite Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {
        "id": "Economic Downturn",
        "x": 1,
        "y": 4,
        "probability": 0.2,
        "parent": ""
      },
      {
        "id": "Credit Risk",
        "x": 2,
        "y": 3,
        "probability": 0.4,
        "parent": "Economic Downturn"
      },
      {
        "id": "Operational Risk",
        "x": 3,
        "y": 2,
        "probability": 0.5,
        "parent": "Credit Risk"
      },
      {
        "id": "External Fraud",
        "x": 4,
        "y": 1,
        "probability": 0.3,
        "parent": "Operational Risk"
      }
    ]
  },
  "layer": [
    {
      "mark": "rule",
      "encoding": {
        "x": {
          "field": "x",
          "type": "quantitative"
        },
        "y": {
          "field": "y",
          "type": "quantitative"
        },
        "x2": {
          "field": "parent_x"
        },
        "y2": {
          "field": "parent_y"
        },
        "color": {
          "value": "slategray"
        }
      },
      "transform": [
        {
          "lookup": "parent",
          "from": {
            "data": {
              "values": [
                {
                  "id": "Economic Downturn",
                  "x": 1,
                  "y": 4
                },
                {
                  "id": "Credit Risk",
                  "x": 2,
                  "y": 3
                },
                {
                  "id": "Operational Risk",
                  "x": 3,
                  "y": 2
                },
                {
                  "id": "External Fraud",
                  "x": 4,
                  "y": 1
                }
              ]
            },
            "key": "id",
            "fields": [
              "x",
              "y"
            ]
          },
          "as": [
            "parent_x",
            "parent_y"
          ]
        }
      ]
    },
    {
      "mark": {
        "type": "circle",
        "size": 400
      },
      "encoding": {
        "x": {
          "field": "x",
          "type": "quantitative"
        },
        "y": {
          "field": "y",
          "type": "quantitative"
        },
        "color": {
          "field": "id",
          "type": "nominal"
        },
        "tooltip": {
          "field": "id",
          "type": "nominal"
        }
      }
    },
    {
      "mark": {
        "type": "text",
        "align": "left",
        "dx": 10
      },
      "encoding": {
        "x": {
          "field": "x",
          "type": "quantitative"
        },
        "y": {
          "field": "y",
          "type": "quantitative"
        },
        "text": {
          "field": "id",
          "type": "nominal"
        },
        "color": {
          "value": "black"
        }
      }
    },
    {
      "mark": {
        "type": "text",
        "dx": -15,
        "dy": -15
      },
      "encoding": {
        "x": {
          "field": "x",
          "type": "quantitative"
        },
        "y": {
          "field": "y",
          "type": "quantitative"
        },
        "text": {
          "field": "probability",
          "type": "quantitative",
          "format": ".2f"
        },
        "color": {
          "value": "blue"
        }
      }
    }
  ]
}