Skip to content

Instantly share code, notes, and snippets.

@ljcolling
Created September 11, 2023 18:42
Show Gist options
  • Select an option

  • Save ljcolling/241baefa92a0e48e9cc6dd2af1ffdc2d to your computer and use it in GitHub Desktop.

Select an option

Save ljcolling/241baefa92a0e48e9cc6dd2af1ffdc2d to your computer and use it in GitHub Desktop.
Bayes quartet
install.packages("bayesplay")
install.packages("tidyverse")
install.packages("patchwork")
require(bayesplay)
require(tidyverse)
require(patchwork)
# version 1
l <- bayesplay::likelihood("normal", 0, 1)
p1 <- bayesplay::prior("normal", 10, 1)
post <- bayesplay::extract_posterior(l * p1)
v1 <- plot(post, add_prior = TRUE) +
geom_function(fun = l[["likelihood_function"]]) +
xlim(-5, 15) +
theme(legend.position = "none")
v1
# version 2
l <- bayesplay::likelihood("student_t", 0, 1, 2)
p1 <- bayesplay::prior("student_t", 10, 1, 2)
post <- bayesplay::extract_posterior(l * p1)
v2 <- plot(post, add_prior = TRUE) +
geom_function(fun = l[["likelihood_function"]]) +
xlim(-5, 15) +
theme(legend.position = "none")
# version 3
l <- bayesplay::likelihood("normal", 0, 1)
p1 <- bayesplay::prior("student_t", 10, 1, 2)
post <- bayesplay::extract_posterior(l * p1)
v3 <- plot(post, add_prior = TRUE) +
geom_function(fun = l[["likelihood_function"]]) +
xlim(-5, 15) +
theme(legend.position = "none")
# version 4
l <- bayesplay::likelihood("student_t", 0, 1, 2)
p1 <- bayesplay::prior("normal", 10, 1)
post <- bayesplay::extract_posterior(l * p1)
v4 <- plot(post, add_prior = TRUE) +
geom_function(fun = l[["likelihood_function"]]) +
xlim(-5, 15) +
theme(legend.position = "none")
(v1 + v2) / (v3 + v4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment