正态分布的贝叶斯推理,我使用以下r
代码获得后验分布。
install.packages(c("mvtnorm","loo","coda"), repos="https://cloud.r-project.org/",dependencies=TRUE)
options(repos=c(getOption('repos'), rethinking='http://xcelab.net/R'))
install.packages('rethinking',type='source')
library(rethinking)
set.seed(650)
x <- data.frame(x = rt(100,3))
fit <- rethinking::map(
alist(
x ~ dnorm(mu, sigma),
mu ~ dnorm(1, 10),
sigma ~ dunif(0, 50)
),
data=x)
precis(fit, corr=TRUE)
sim_post <- extract.samples(fit)
dim(sim_post)
post_mean <- apply(sim_post, 2, mean)
post_mean
quantile(sim_post$mu , c(.05, .95))
quantile(sim_post$sigma, c(0.05, 0.95))
我使用后验分布模拟了 10000 个样本。如何获得 mu 的覆盖概率?