Gibbs sampler examples in R [closed]

This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain.

Closed 6 years ago . The community reviewed whether to reopen this question 2 years ago and left it closed:
Original close reason(s) were not resolved

How can I implement Gibbs sampler for the posterior distribution, and estimating the marginal posterior distribution by making histogram?

asked Mar 10, 2017 at 12:51 sabuj bhowmick sabuj bhowmick 129 1 1 gold badge 1 1 silver badge 3 3 bronze badges

$\begingroup$ I wrote a book called Introducing Monte Carlo methods with R that you could check for such examples. $\endgroup$

Commented Mar 10, 2017 at 17:01

1 Answer 1

$\begingroup$

Problem

Suppose $Y \sim \text(\text = \mu, \text = \frac)$.

Based on a sample, obtain the posterior distributions of $\mu$ and $\tau$ using the Gibbs sampler.

Notation

$ \mu$ = population mean

$ \tau$ = population precision (1 / variance)

$\bar$ = sample mean

$s^2$ = sample variance

Gibbs sampler

[Casella, G. & George, E. I. (1992). Explaining the Gibbs Sampler. The American Statistician, 46, 167–174.]

The theory ensures that after a sufficiently large number of iterations, $T$, the set $\<(\mu^, \tau^ ) : i = T+1, \dots, 𝑁 \>$ can be seen as a random sample from the joint posterior distribution.

Priors

$f(\mu, \tau) = f(\mu) \times f(\tau)$, with

Conditional posterior for the mean, given the precision $$(\mu \,|\, \tau, \text) \sim \text\Big(\bar, \frac\Big)$$

Conditional posterior for the precision, given the mean $$(\tau \,|\, \mu, \text) \sim \text\Big(\frac, \frac)^2> \Big)$$

(quick) R implementation

# summary statistics of sample n mu  
hist(mu) hist(tau)