0

Bayesian Inference for the Normal Distribution, I use the following r code to obtain the posterior distribution.

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))

I have simulated 10000 samples using the posterior distribution. How can I obtain the coverage probability for mu?

score324
  • 687
  • 10
  • 18
  • I don't see a package named "rethinking" in CRAN. You should tell us where you got it and how to install it. – IRTFM Sep 26 '18 at 02:20
  • `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')` , Here is the link, https://xcelab.net/rm/software/ – score324 Sep 26 '18 at 02:28
  • [This related question](https://stats.stackexchange.com/questions/284179/coverage-probability-of-credible-intervals-if-we-take-bayesian-model-literally) might be of interest. Seems like the approach is the standard empirical one: repeatedly generate random samples from the prior, then count how often the posterior interval encompasses the true parameter values. – merv Sep 26 '18 at 02:29
  • Are there any `r` function can be used for this purpose? – score324 Sep 26 '18 at 02:31
  • @score324, not that I am aware. It's not something typically computed/reported - though that doesn't mean it shouldn't be. – merv Sep 26 '18 at 02:47
  • Coverage probability is a concept related to a frequentist interpretation of probability. In Bayes' analysis the posterior tells you everything. A x% posterior interval will contain, by definition, x% of the times the true value (provided that your model is correct). – nicola Sep 27 '18 at 08:05
  • @nicola, why I am getting 100% always? – score324 Sep 27 '18 at 16:24
  • Are you getting 100% from what? If you want to make Bayesian analysis just forget about coverage probability. It's a concept that has its scope within frequentism. – nicola Sep 28 '18 at 07:42
  • @nicola Thank you. – score324 Sep 28 '18 at 16:42

0 Answers0