The plotBayes
package illustrates Bayesian inference, showing how the prior distribution and the likelihood of the data combine to produce a posterior distribution.
This is mostly a toy package useful for teaching.
You need the devtools
package to install this from github.
install.packages("devtools")
Then install plotBayes
.
devtools::install_github("mcbeem/plotBayes")
And then load it.
library(plotBayes)
library(plotBayes)
Normal prior with $\mu=0$, $\sigma=0.5$:
set.seed(1) data <- rnorm(n=10, mean=1, sd=1) plotBayes(data, prior.type="normal", prior.parameters=c(0, .5), min=-2, max=2)
You can request a different credible interval with with argument credible=
.
plotBayes(data, prior.parameters=c(.0, .5), prior.type="normal", min=-2, max=2, credible=.68)
Uniform prior with $a=.7$, $b=1.5$:
plotBayes(data, prior.type="uniform", prior.parameters=c(.7, 1.5), min=-2, max=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.