Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions Bayes_factor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"The Bayes factor quantifies the relative evidence for two competing model families $\\text{M}_1$ and $\\text{M}_2$ given observed data $\\text{D}$. It compares the marginal likelihoods by integrating over all possible parameter values weighted by their prior distributions:\n",
"\n",
"$$\n",
"\\text{BF}_{21} = \\frac{P(\\text{D}|\\text{M}_2)}{P(\\text{D}|\\text{M}_1)} = \\frac{\\int P(\\text{D}|\\theta_{2}, \\text{M}_{2}) P(\\theta_{2}|\\text{M}_{2})\\,d\\theta_{2}}{\\int P(\\text{D}|\\theta_{1},\\text{M}_{1}) P(\\theta_{1}|\\text{M}_{1})\\,d\\theta _{1}}\n",
"\\text{BF}_{12} = \\frac{P(\\text{D}\\mid \\text{M}_1)}{P(\\text{D}\\mid \\text{M}_2)} = \\frac{\\int P(\\text{D}\\mid \\theta_{1}, \\text{M}_{1}) \\, P(\\theta_{1}\\mid \\text{M}_{1}) \\, d\\theta_{1}}{\\int P(\\text{D}\\mid \\theta_{2}, \\text{M}_{2}) \\, P(\\theta_{2}\\mid \\text{M}_{2}) \\, d\\theta_{2}}\n",
"$$\n",
"\n",
"where:\n",
Expand Down Expand Up @@ -65,11 +65,13 @@
"## Interpretation Guidelines\n",
"\n",
"Following [Kass and Raftery (1995)](https://www.tandfonline.com/doi/abs/10.1080/01621459.1995.10476572), Bayes factors are typically interpreted as:\n",
"- $\\text{BF}_{21} < 1$: Evidence favors $\\text{M}_1$\n",
"- $1 < \\text{BF}_{21} < 3$: Weak evidence for $\\text{M}_2$\n",
"- $3 < \\text{BF}_{21} < 10$: Moderate evidence for $\\text{M}_2$\n",
"- $10 < \\text{BF}_{21} < 100$: Strong evidence for $\\text{M}_2$\n",
"- $\\text{BF}_{21} > 100$: Decisive evidence for $\\text{M}_2$"
"\n",
"| $\\text{BF}_{12}$ | Strength of evidence (for $\\text{M}_1$ over $\\text{M}_2$) |\n",
"|------------------|--------------------------------------------|\n",
"|1 to 3.2 | Not worth more than a bare mention |\n",
"|3.2 to 10 | Substantial |\n",
"|10 to 100 | Strong |\n",
"|> 100 | Decisive |"
]
},
{
Expand Down Expand Up @@ -119,7 +121,9 @@
"cell_type": "markdown",
"id": "708774c1",
"metadata": {},
"source": "## Setup"
"source": [
"## Setup"
]
},
{
"cell_type": "code",
Expand Down Expand Up @@ -246,7 +250,7 @@
"text": [
"Marginal Likelihood (Model Family 1, beta=0): 0.00192103 \n",
"Marginal Likelihood (Model Family 2, beta~N(0,1)): 0.001008886 \n",
"Bayes Factor (BF_21): 0.5251796 \n",
"Bayes Factor (BF_12): 1.90411 \n",
"Interpretation: Evidence favors Model Family 1 (no effect)\n"
]
}
Expand Down Expand Up @@ -285,18 +289,18 @@
"marginal_lik_model_family_1 <- likelihood(beta = 0, sd = true_sd, X = X, Y = Y) # Point mass at beta = 0\n",
"marginal_lik_model_family_2 <- marginal_likelihood(X, Y, true_sd, prior_mean, prior_sd)\n",
"\n",
"# Calculate Bayes Factor (BF_21 = Model 2 vs Model 1)\n",
"bf_21 <- marginal_lik_model_family_2 / marginal_lik_model_family_1\n",
"# Calculate Bayes Factor (BF_12 = Model 1 vs Model 2)\n",
"bf_12 <- marginal_lik_model_family_1 / marginal_lik_model_family_2\n",
"\n",
"cat(\"Marginal Likelihood (Model Family 1, beta=0):\", marginal_lik_model_family_1, \"\\n\")\n",
"cat(\"Marginal Likelihood (Model Family 2, beta~N(0,1)):\", marginal_lik_model_family_2, \"\\n\")\n",
"cat(\"Bayes Factor (BF_21):\", bf_21, \"\\n\")\n",
"cat(\"Bayes Factor (BF_12):\", bf_12, \"\\n\")\n",
"\n",
"# Interpretation\n",
"if (bf_21 > 1) {\n",
" cat(\"Interpretation: Evidence favors Model Family 2 (some effect exists)\\n\")\n",
"} else {\n",
"if (bf_12 > 1) {\n",
" cat(\"Interpretation: Evidence favors Model Family 1 (no effect)\\n\")\n",
"} else {\n",
" cat(\"Interpretation: Evidence favors Model Family 2 (some effect exists)\\n\")\n",
"}"
]
},
Expand Down Expand Up @@ -415,7 +419,7 @@
"id": "be1c0b37",
"metadata": {},
"source": [
"**Exercise**: Here the Bayes factor between the two models is ~0.52, which doesn't suggest very strong evidence. This is mainly because of the fact that there are only five samples in the data. Try to increase the number of samples and see how Bayes factor changes."
"**Exercise**: Here the Bayes factor between the two models is 1.90, which doesn't suggest very strong evidence. This is mainly because of the fact that there are only five samples in the data. Try to increase the number of samples and see how Bayes factor changes."
]
},
{
Expand Down Expand Up @@ -448,4 +452,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
Binary file modified graphical_summary/slides.pptx
Binary file not shown.
Binary file modified graphical_summary/slides/Slide1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide26.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide27.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide28.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide29.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide30.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide31.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphical_summary/slides/Slide32.png
Binary file modified graphical_summary/slides/Slide4.png
Binary file modified graphical_summary/slides/Slide5.png
Binary file modified graphical_summary/slides/Slide6.png
Binary file modified graphical_summary/slides/Slide7.png
Binary file modified graphical_summary/slides/Slide8.png
Binary file modified graphical_summary/slides/Slide9.png
6 changes: 3 additions & 3 deletions notations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@
"| $\\boldsymbol{\\Sigma}$ | Known covariance matrix | Residual covariance between height and weight |\n",
"| **Prior Parameters** | | |\n",
"| $\\beta_0$ | Prior mean (scalar) | Expected effect = 0 before seeing data |\n",
"| $\\boldsymbol{\\beta}_0$ | Prior mean vector | Expected effects = $\\begin{pmatrix} 0 \\\\ 0 \\end{pmatrix}$ before data |\n",
"| $\\boldsymbol{\\beta}_0$ | Prior mean vector | Expected effects = $\\begin{pmatrix} 0 \\\\ 0 \\end{pmatrix}$ before seeing data |\n",
"| $\\sigma_0^2$ | Prior variance (scalar) | Prior uncertainty = 0.25 for effect size |\n",
"| $\\boldsymbol{\\Sigma}_0$ | Prior covariance matrix | Prior uncertainty about joint effects |\n",
"| **Posterior Parameters** | | |\n",
"| $\\beta_1$ | Posterior mean (scalar) | Updated effect = 0.3 after seeing data |\n",
"| $\\boldsymbol{\\beta}_1$ | Posterior mean vector | Updated effects = $\\begin{pmatrix} 0.3 \\\\ 0.2 \\end{pmatrix}$ after data |\n",
"| $\\sigma_1^2$ | Posterior variance (scalar) | Reduced uncertainty = 0.1 after data |\n",
"| $\\boldsymbol{\\beta}_1$ | Posterior mean vector | Updated effects = $\\begin{pmatrix} 0.3 \\\\ 0.2 \\end{pmatrix}$ after seeing data |\n",
"| $\\sigma_1^2$ | Posterior variance (scalar) | Reduced uncertainty = 0.1 after seeing data |\n",
"| $\\boldsymbol{\\Sigma}_1$ | Posterior covariance matrix | Reduced uncertainty about joint effects |\n",
"| **Mixed Models** | | |\n",
"| $\\mathbf{g}$ | Random effect vector in linear mixed models | Individual-specific genetic effects |\n",
Expand Down