Follow ______ on twitter.

5.1.2 Probability Distributions in Simulation Modeling

Code

Vega-Lite Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "Demonstration of skewing a normal distribution using beta distribution",
  "hconcat": [
    {
      "width": 250,
      "height": 250,
      "data": {
        "sequence": {
          "start": -3,
          "stop": 3,
          "step": 0.01,
          "as": "x"
        }
      },
      "transform": [
        {
          "calculate": "exp(-pow(datum.x, 2) / 2) / sqrt(2 * PI)",
          "as": "normal_pdf"
        }
      ],
      "mark": "line",
      "encoding": {
        "x": {
          "field": "x",
          "type": "quantitative",
          "title": "Value"
        },
        "y": {
          "field": "normal_pdf",
          "type": "quantitative",
          "title": "Density"
        },
        "color": {
          "value": "blue"
        }
      },
      "title": "Standard Normal Distribution"
    },
    {
      "width": 50,
      "height": 250,
      "mark": {
        "type": "text",
        "align": "center",
        "baseline": "middle",
        "fontSize": 30,
        "text": "+"
      }
    },
    {
      "width": 250,
      "height": 250,
      "data": {
        "sequence": {
          "start": 0,
          "stop": 1,
          "step": 0.01,
          "as": "x"
        }
      },
      "transform": [
        {
          "calculate": "densityBeta(datum.x, 1.2, 1)",
          "as": "beta_pdf"
        }
      ],
      "mark": "line",
      "encoding": {
        "x": {
          "field": "x",
          "type": "quantitative",
          "title": "Value"
        },
        "y": {
          "field": "beta_pdf",
          "type": "quantitative",
          "title": "Density"
        },
        "color": {
          "value": "green"
        }
      },
      "title": "Beta Distribution (α=1.2, β=1)"
    },
    {
      "width": 50,
      "height": 250,
      "mark": {
        "type": "text",
        "align": "center",
        "baseline": "middle",
        "fontSize": 30,
        "text": "="
      }
    },
    {
      "width": 250,
      "height": 250,
      "data": {
        "sequence": {
          "start": 0,
          "stop": 200,
          "step": 1,
          "as": "index"
        }
      },
      "transform": [
        {
          "calculate": "random()",
          "as": "random"
        },
        {
          "calculate": "quantileBeta(datum.random, 1.2, 1)",
          "as": "beta_draw"
        },
        {
          "calculate": "quantileNormal(datum.beta_draw)",
          "as": "skewed_draw"
        }
      ],
      "layer": [
        {
          "mark": "bar",
          "encoding": {
            "x": {
              "field": "skewed_draw",
              "type": "quantitative",
              "bin": {
                "maxbins": 30
              },
              "title": "Value"
            },
            "y": {
              "aggregate": "count",
              "type": "quantitative",
              "title": "Count"
            }
          }
        }
      ],
      "title": "Resulting Skewed Distribution"
    }
  ]
}