Description Usage Arguments Details Value Source References See Also Examples
Define the posterior distribution function for π ( μ |x ) if we have a normal sampling distribution f( x | μ, σ^2 ) where μ is unknown and σ^2 is known, and the normal prior distribution π ( μ; m, s ) for unknown μ. Define the posterior distirbution π ( μ,τ |x ) if we have a normal sampling distribution where both μ and σ^2 are unknown, and the normal-gamma prior distribution π( μ,τ; m,s,α,β ) for unknown mean and precison τ = 1/σ^2.
1 |
x |
a vector of observations from a normal distribution with mean mu and variance sigma^2. |
m, s |
two parameters of the prior normal distribution. If mu is NULL, they are mean and standard deviation of prior normal distribution for mu. If both mu and sigma are NULL, they are mean and standard deviation of normal distribution π (μ | τ). |
alpha, beta |
two parameters of a gamma distribution. Only used when mu and sigma are both NULL, then the prior distribution on μ and precision τ has a Normal-Gamma distribution. The distribution of τ is gamma(τ; α, β) |
mu |
the mean of x vector from a normal distribution. If it is NULL, the mean of x is unknown. |
sigma |
the standard deviation of x vector from a normal distribution. If it is NULL, the standard deviation of x is unknown. |
Suppose we have a random sample x from normal distribution N(μ,σ^2) whose μ is assumed to be unknow, the likelihood of this is f (x | μ) and the conjugate prior for this unknown μ is a normal distributin π (μ; m, s ). Then the posterior distribution π (μ | x ), proportional to f (x | μ)π (μ; m, s ), is also a normal distribution N(μ_n, σ_n^2).
Suppose we have a random sample x from normal distribution N(μ,σ^2) whose μ and σ^2 both are assumed to be unknow, the likelihood of this is f (x | μ, σ^2). The pricision τ equals 1/σ^2, then the conjugate prior for unknown μ and τ is a normal-gamma distribution where NG(μ, τ; m, s, α,β)= N(μ | τ ; m, (sτ)^-1) G(τ; α,β). The posterior distribution is normal-gamma with four updated parameters m_n, s_n, α_n, β_n. In addtion, the marginal distribution of μ is student t distribution.
An object of class "g12post
" is returned.
prior |
the prior distribution. |
likelihood |
the likelihood function. |
posterior |
the posterior distribution. |
mu |
the mean of the x vector from a normal distribution. |
pri.mean |
the mean of the prior distribution. |
pri.std |
the standard deviation of the prior distribution. |
pri.precision |
the precision of the prior distribution. |
pos.mean |
the mean of the posterior distribution. |
pos.std |
the standard deviation of the posterior distribution. |
pos.precision |
the precision of the posterior distribution. |
model |
the prior and likelihood type to produce the posterior. |
If both both mu and sigma are NULL, the addtional returns will be
tau |
the precision of the x vector from a normal distribution. |
mu.prior |
the prior distribution for mu. |
tau.prior |
the prior distribution for tau. |
mu.posterior |
the posterior distribution for mu. |
tau.posterior |
the posterior distribution for tau. |
pos.m |
the parameter m in posteior normal-gamma distribution. |
pos.s |
the parameter s in posteior normal-gamma distribution. |
pos.alpha |
the parameter α in posteior normal-gamma distribution. |
pos.beta |
the parameter β in posteior normal-gamma distribution. |
Notice pri.mean
, pri.std
, pos.mean
and pos.std
will not return in this situation.
The slides 6 of STATG012 on Moodle
Hoff. 2010.Conjugate Priors for Normal Data, PowerPoint presentation, STA290: Bayesian and Modern Data Analysis, Duke University. Available from: Weblink.
Murphy, KP. 2007. Conjugate Bayesian analysis of the Gaussian distribution. Available from: Weblink.
summary.g12post
for summararies of prior
and posterior distribution.
plot.g12post
for plots of prior and posterior
distribution.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ## this example is from slides6 Example 5.7
## generate a sample of 9 from a normal distribution with sd=2
x <- rnorm(9, sd = 2)
## the observed sample mean is 20
xx <- x- mean(x) + 20
## find the posterior density
exmp1 <- normnorm(xx, m = 25, s = sqrt(10), sigma = 2)
## summay and plot the example
summary(exmp1)
plot(exmp1, leg_pos = "right", cex = 0.8)
## this example assumes both mu and sigma are unknown
y <- rnorm(9)
exmp2 <- normnorm(y, m = 1, s = 2, a = 1, b = 1)
summary(exmp2)
## show the first plot : Prior and Posterior Distribution of mu
plot(exmp2, which = 1, main = "Prior and Posterior Distribution of mu")
## show the second plot : Prior and Posterior Distribution of tau
plot(exmp2, which = 2, col = 1:2)
## show the third plot : Prior Contour
plot(exmp2, which = 3, main = "Prior Contour",
xlim = c(-1,3),ylim = c(0,5) )
## show the fourth plot : Posterior Contour
plot(exmp2, which = 4, main = "Posterior Contour",
xlim = c(-3,3), ylim = c(0,5))
## show the fifth plot : Prior and Posterior Contour
plot(exmp2, which = 5, main = "Prior and Posterior Contour",
xlim = c(-3,3), ylim = c(0,5))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.