{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Visual representation of prior, likelihood, and posterior distributions.",
"width": 400,
"height": 300,
"data": {
"sequence": {
"start": -20,
"stop": 40,
"step": 0.1,
"as": "x"
}
},
"transform": [
{
"calculate": "0.1 * exp(-0.5 * pow((datum.x + 10) / 5, 2))",
"as": "Prior"
},
{
"calculate": "0.1 * exp(-0.5 * pow((datum.x - 15) / 5, 2))",
"as": "Likelihood"
},
{
"calculate": "0.15 * exp(-0.5 * pow((datum.x - 10) / 5, 2))",
"as": "Posterior"
},
{
"fold": [
"Prior",
"Likelihood",
"Posterior"
],
"as": [
"Distribution",
"Probability"
]
}
],
"layer": [
{
"mark": "line",
"encoding": {
"x": {
"field": "x",
"type": "quantitative"
},
"y": {
"field": "Probability",
"type": "quantitative"
},
"color": {
"field": "Distribution",
"type": "nominal",
"legend": {
"title": "Distributions"
}
}
}
},
{
"transform": [
{
"filter": "datum.Distribution === 'Prior'"
},
{
"window": [
{
"op": "max",
"field": "Probability",
"as": "maxProbability"
}
],
"frame": [
null,
null
]
}
],
"layer": [
{
"mark": {
"type": "rule",
"color": "#e41a1c",
"strokeDash": [
4,
2
],
"strokeWidth": 1
},
"encoding": {
"x": {
"datum": -10
},
"y": {
"field": "maxProbability"
}
}
},
{
"mark": {
"type": "text",
"fontSize": 16,
"font": "Helvetica",
"fontWeight": 100
},
"encoding": {
"x": {
"datum": -10
},
"y": {
"field": "maxProbability"
},
"text": {
"value": "Historic Data"
}
}
}
]
},
{
"transform": [
{
"filter": "datum.Distribution === 'Likelihood'"
},
{
"window": [
{
"op": "max",
"field": "Probability",
"as": "maxProbability"
}
],
"frame": [
null,
null
]
}
],
"layer": [
{
"mark": {
"type": "rule",
"color": "royalblue",
"strokeDash": [
4,
2
],
"strokeWidth": 1
},
"encoding": {
"x": {
"datum": 15
},
"y": {
"field": "maxProbability"
}
}
},
{
"mark": {
"type": "text",
"fontSize": 16,
"font": "Arial",
"fontWeight": 200
},
"encoding": {
"x": {
"datum": 15
},
"y": {
"field": "maxProbability"
},
"text": {
"value": "Current Conditions"
}
}
}
]
},
{
"transform": [
{
"filter": "datum.Distribution === 'Posterior'"
},
{
"window": [
{
"op": "max",
"field": "Probability",
"as": "maxProbability"
}
],
"frame": [
null,
null
]
}
],
"layer": [
{
"mark": {
"type": "rule",
"color": "orange",
"strokeDash": [
4,
2
],
"strokeWidth": 1
},
"encoding": {
"x": {
"datum": 10
},
"y": {
"field": "maxProbability"
}
}
},
{
"mark": {
"type": "text",
"fontSize": 16,
"font": "Arial",
"fontWeight": 200
},
"encoding": {
"x": {
"datum": 10
},
"y": {
"field": "maxProbability"
},
"text": {
"value": "Predicted Outcomes"
}
}
}
]
}
],
"encoding": {
"x": {
"field": "x",
"type": "quantitative"
},
"y": {
"field": "Probability",
"type": "quantitative",
"title": "Probability"
}
}
}