Learn R Programming

bpp (version 1.0.4)

NormalNormalPosterior: Normal-Normal Posterior in conjugate normal model, for known sigma

Description

Compute the posterior distribution in a conjugate normal model for known variance: Let \(X_1, \ldots, X_n\) be a sample from a \(N(\mu, \sigma^2)\) distribution, with \(\sigma\) assumed known. We assume a prior distribution on \(\mu\), namely \(N(\nu, \tau^2)\). The posterior distribution is then \(\mu|x \sim N(\mu_p, \sigma_p^2)\) with

$$\mu_p = (1 / (\sigma^2 / n) + \tau^{-2})^{-1} (\bar{x} / (\sigma^2/n) + \nu / \tau^2)$$

and

$$\sigma_p = (1 / (\sigma^2/n) + \tau^{-2})^{-1}.$$

These formulas are available e.g. in Held (2014, p. 182).

Usage

NormalNormalPosterior(datamean, sigma, n, nu, tau)

Arguments

datamean

Mean of the data.

sigma

(Known) standard deviation of the data.

n

Number of observations.

nu

Prior mean.

tau

Prior standard deviation.

Value

A list with the entries:

postmean

Posterior mean.

postsigma

Posterior standard deviation.

References

Held, L., Sabanes-Bove, D. (2014). Applied Statistical Inference. Springer.

Examples

Run this code
# NOT RUN {
## data:
n <- 25
sd0 <- 3
x <- rnorm(n, mean = 2, sd = sd0)

## prior:
nu <- 0
tau <- 2

## posterior:
NormalNormalPosterior(datamean = mean(x), sigma = sd0, 
                      n = n, nu = nu, tau = tau)
# }

Run the code above in your browser using DataLab