Chapter 5. Bayesian Statistics (II)
Chapter 5. Bayesian Statistics (II)
Chapter 5. Bayesian Statistics (II)
Remark: To simulate from the posterior distribution p(θ, σ 2|y), one can first
simulate σ 2 from marginal posterior distribution p(σ 2 |y), then simulate θ from
the conditional posterior distribution p(θ|σ 2 , y).
Example. Suppose a stock’s daily return Y was recorded for n =
22 consecutive business days, with ȳ = 5% and s = 4%. Assume
that the daily return Y follows N (θ, σ 2) with prior π(θ, σ 2) ∝
1/σ 2. Find the 95% posterior interval for θ. Also use simulation
to approximate E[θ/σ|y].
Solution: Since
θ − ȳ
√ y = t(n − 1)
s/ n
The 95% posterior interval is (in %)
s 4
ȳ ± t0.025 (n − 1) √ = 5 ± 2.080 ∗ √ = [3.2, 6.8]
n 21
Below is the histogram of 1000 draws of θ/σ. For each draw, p we (1) draw a
sample of σ: draw a sample say u from χ2(n − 1), then let σ = (n − 1)s2 /u;
(2) given σ, draw a sample θ from N (ȳ, σ 2 /n); (3) θ/σ is a data point. The
sample average of θ/σ is 1.23.
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4
0.0
0.5
1.0
1.5
2.0
2.5
3.0
Multinomial model. Let Y = (Y1, . . . , Yd) be multinomial with
parameter (n; θ1, . . . , θd) where
θ1 + · · · + θd = 1.
Consider prior distribution (Dirichlet distribution)
d
Y α −1
π(θ) ∝ θi i
i=1
restricted to non-negative θi’s with θ1 + · · · + θd = 1.
The joint posterior distribution p(θ|y).
d
Y d
Y d
Y
αi−1 yi αi+yi−1
p(θ|y) ∝ π(θ) · p(y|θ) ∝ θi · θi = θi
i=1 i=1 i=1
That is, p(θ|y) is a Dirichlet distribution with parameter (α1 +
y1, . . . , αd + yd).
The histograms are attached below, the sample means are 0.099 and 0.100
respectively. None of the sample points of θ1 − θ2 are below zero.
15
15
10
10
5
5
0
0.0 0.05 0.10 0.15 0.20 0.0 0.05 0.10 0.15 0.20
where
(n − 1)s2 + (n − 1)s2
1 x 2 y
n = n1 + n2, s2p =
(n1 − 1) + (n2 − 2)
Analogously, one have the marginal posterior distribution
− n (n−2)s2p
2 −
p(σ 2|x, y) ∝ σ 2 e 2σ2
or !
(n − 2)s2p
2 x, y = χ2(n − 2).
σ
Remark on simulation. To draw samples of (θ1 , θ2 , σ). One can draw u from
χ2(n − 2) and let σ 2 = (n − 2)s2p /u, then draw θ1, θ2 independently from
N (x̄, σ 2/n1 ) and N (ȳ, σ 2/n2 ) respectively. If one is interested in θ1 − θ2, for
each sample point of (θ1 , θ2 , σ) compute θ1 − θ2 . If one is interested θ1 θ2, for
each sample point compute θ1 θ2 . And so on so forth.
Solution: We consider the hits, and leave the home runs as exercise. Let θ1 be
the hit proportion for T.W. and θ2 for that of J.D. Assume a non-informative
prior π(θ1 , θ2) ∝ 1. Then the posterior is
p(θ1 , θ2 |y) ∝ θ12654 (1 − θ1 )5052 · θ22214 (1 − θ2)4607
We are interested in P (θ1 − θ2 > 0|y). We simulate 1000 draws of θ1 − θ2 [we
simulate θ1 and θ2 independently from Beta(2655,5053) and Beta(2215, 4608),
respectively, and compute θ1 − θ2 for each (θ1 , θ2 ).]
Below is the histogram of θ1 − θ2. Among 1000 draws, 995 are positive. There-
fore the posterior probability P (θ1 − θ2 > 0|y) ≈ 0.995.
0.06
0.04
T.W. − J.D.
0.02
0.0
−0.02
50 40 30 20 10 0
2
1
Smokes − Quit
0
−1
−2
1.0 0.8 0.6 0.4 0.2 0.0
An example of generalized linear model
Statistical model. Assume that yi is Binomial (ni , θi), with θi the population
death rate for animals receiving dose xi. We would like θi to be dependent
on xi, and by definition θi ∈ [0, 1]. The following logistic regression model is
adopted.
logit(θi ) = α + βxi
.
where logit(θ) = log(θ/(1 − θ)). The inverse function of logit(·) is
logit−1 (u) = eu/(1 + eu).
Note that in this model xi’s are explanatory variables and regarded as fixed.
Prior and likelihood. We use a flat prior π(α, β) ∝ 1 and the likelihood
−1
yi −1
ni−yi
p(yi |α, β) ∝ logit (α + βxi) · 1 − logit (α + βxi) .
The posterior p(α, β|y). We have
Y
4 Y
4
p(α, β|y) ∝ π(α, β) · p(yi |α, β) ∝ p(yi |α, β)
i=1 i=1
30
20
beta
10
0
−2 0 2 4 6
alpha
The quantities of interest. The sign of β is important. For all the 1000 samples
we have β > 0, which indicates the compound is harmful. Another quantity of
interest in LD50 – the dose level at which the probability of death is 50%, or
α + β · LD50 = logit−1 (0.5) = 0 ⇒ LD50 = −α/β.
The histogram of LD50 is attached.
30
5
4
20
3
beta
10
2
1
0
alpha LD50