Bayes Notes1
Bayes Notes1
Loukia Meligkotsidou
f (µ, τ | x) ∝ f (µ, τ ) f (x | µ, τ )
n
( " #)
n+1
+a−1 1X c
∝ τ 2 exp −τ (xi − µ)2 + (µ − ξ)2 + b .
2 2
i=1
Z Z
f (x) = f (x | µ, τ )f (µ | τ )f (τ )dµdτ
τ µ
n
Z Z ( )
n+1 n τ X
= (2π)− 2 τ 2 exp − (xi − µ)2
τ µ 2
i=1
b a a−1 τc
× τ exp{−τ b}(2π)−1/2 (cτ )1/2 exp{− (µ − ξ)2 }dµdτ
Γ(a) 2
Z Z
f (x) = f (x | µ, τ )f (µ | τ )f (τ )dµdτ
τ µ
n
Z Z ( )
n+1 n τ X
= (2π)− 2 τ 2 exp − (xi − µ)2
τ µ 2
i=1
b a a−1 τc
× τ exp{−τ b}(2π)−1/2 (cτ )1/2 exp{− (µ − ξ)2 }dµdτ
Γ(a) 2
n b
a Z
n τ X τc 2
= (2π)− 2 c 1/2 τ 2 +a−1 exp{− xi2 − ξ − τ b}
Γ(a) τ 2 2
n
"Z #
1 1 τ (n + c) X
× (2π)− 2 τ 2 exp{− µ2 + τ ( xi + c)µ}dµ dτ
µ 2
i=1
Therefore,
ba 1 n 1
f (x) = (2π)− 2 c 2 (n + c)− 2
Γ(a)
n
1 X 2 cξ 2 (nx̄ + cξ)2
Z
n
+a−1
× τ 2 exp{−τ [ xi + +b ]}dτ
τ 2 2 2(n + c)
i=1
Therefore,
ba 1 n 1
f (x) = (2π)− 2 c 2 (n + c)− 2
Γ(a)
n
1 X 2 cξ 2 (nx̄ + cξ)2
Z
n
+a−1
× τ 2 exp{−τ [ xi + +b ]}dτ
τ 2 2 2(n + c)
i=1
ba 1 − n2 1
= (2π) c 2 (n + c)− 2
Γ(a)
" n #−( n +a)
2
n 1 X 2 cξ 2 (nx̄ + cξ)2
× Γ( + a) xi + +b− .
2 2 2 2(n + c)
i=1
It is also known that rock type A occurs about four times as often
as type B. If a sample is taken, and the fossil found to be present,
calculate the posterior distribution of rock types.
If the geologist always classifies as A when the fossil is found to be
present, and classifies as B when it is absent, what is the
probability she will be correct in a future classification?
Loukia Meligkotsidou, University of Athens Bayesian Inference
Solution
Denote
A: rock stratum A, B: rock stratum B and F: fossil is present.
Denote
A: rock stratum A, B: rock stratum B and F: fossil is present.
Denote
A: rock stratum A, B: rock stratum B and F: fossil is present.
Solution.
(i.) The likelihood function is
2 2
f (X = 2 | θ) = θ (1 − θ)2−2 = θ2
2
Solution.
R
Since f (θ | x) dθh = 1,ithus,
R∞ 1 ∞
cθ−2
1 c θ3 dθ = 1 ⇔ −2 = 1 ⇔ c = 2.
1
Solution.
R
Since f (θ | x) dθh = 1,ithus,
R∞ 1 ∞
cθ−2
1 c θ3 dθ = 1 ⇔ −2 = 1 ⇔ c = 2.
1
dL(θ) x n−x
= −
dθ θ 1−θ
d 2 L(θ) x n−x
=− 2 −
dθ 2 θ (1 − θ)2
Since E (x) = nθ ⇒ I (θ) = − nθ
θ2
− n−nθ
(1−θ)2
= n 1−θ+θ
θ(1−θ) =
nθ−1 1 − θ−1 ⇒ J (θ) ∝ θ−1/2 (1 − θ)−1/2
dL(θ) x n−x
= −
dθ θ 1−θ
d 2 L(θ) x n−x
=− 2 −
dθ 2 θ (1 − θ)2
Since E (x) = nθ ⇒ I (θ) = − nθ
θ2
− n−nθ
(1−θ)2
= n 1−θ+θ
θ(1−θ) =
nθ−1 1 − θ−1 ⇒ J (θ) ∝ θ−1/2 (1 − θ)−1/2
c.
1 n−x
n −x
f (x | φ) = φ 1−
x φ
n
with E (X ) = φ
Loukia Meligkotsidou, University of Athens Bayesian Inference
Solution
L (φ) = −x log (φ) + (n − x) log φ−1φ +c =
−n log (φ) + (n − x) log (φ − 1) + c
dL(φ) x −x n
= −
dφ φ−1 φ
2
d L(φ) n−x n
2
=− 2
+ 2
dφ (φ − 1) φ
2
d L(φ) n − n/φ n nφ − n (φ − 1) −1
I (φ) = −E 2
= 2
− 2 = 2
∝ φ3 − φ2
dφ (φ − 1) φ φ (φ − 1)
−1/2
⇒ J (φ) ∝ φ3 − φ2
dL(φ) x −x n
= −
dφ φ−1 φ
2
d L(φ) n−x n
2
=− 2
+ 2
dφ (φ − 1) φ
2
d L(φ) n − n/φ n nφ − n (φ − 1) −1
I (φ) = −E 2
= 2
− 2 = 2
∝ φ3 − φ2
dφ (φ − 1) φ φ (φ − 1)
−1/2
⇒ J (φ) ∝ φ3 − φ2
b. Likewise, Pn
xi
e −θ θxi e −nθ
f (x | θ) = ni=1 Qnθ i=1
Q
xi ! = i=1 xi !
and
Pn Pn
f (θ|x) ∝ e −nθ θ i=1 xi e −θ = e −(n+1)θ θ i=1 xi ≡ Gamma(p, q).
Note:Y ∼ Beta(p, q) ⇔ f (y ) = 1
B(p,q)
y p−1 (1 − θ)q−1 and
q
p
Y ∼ Gamma (p, q) ⇔ f (y ) = Γ(p)
e −qy y p−1 .
P
Let θ | x ∼ Beta (P, Q) ⇔ E (θ | x) = P+Q = 4/102 and V (θ |
x) = (P+Q)2PQ
(P+Q+1)
= 0.0003658
After some straight forward algebra: P = 4 and Q = 98.
Also, P = p + x =⇒ 4 = p + 3 =⇒ p = 1 and
Q = q + n − x =⇒ 98 = q + 3 − 100 =⇒ q = 1.
=⇒ The statistician used Beta(1, 1) ≡ U(0, 1) prior distribution.
Solution. 2
−θ)
For known σ: f (xi | θ) = √ 1 exp{− (xi2σ 2 } ∝
2πσ 2
θ2
xi θ
exp{− 2σ1 2 xi2 + σ2
2σ 2
} ∝ exp{− 2σ1 2 θ2 + σ12 xi θ}
−
Likelihood: f (x | θ) = ni=1 f (xi | θ) ∝
Q
Qn θ2 1 n 2 θ Pn
i=1 exp{− 2σ 2 + σ 2 xi θ} = exp{− 2σ 2 θ + σ 2 i=1 xi }
Prior distribution:
f (θ) ∝ exp{− 2d1 2 (θ − b)2 } ∝ exp{− 2d1 2 θ2 + 1
d2
bθ}
Prior distribution:
f (θ) ∝ exp{− 2d1 2 (θ − b)2 } ∝ exp{− 2d1 2 θ2 + 1
d2
bθ}
Posterior distribution:
f (θ | x) ∝ f (θ) f (x | θ) ∝ Pn
exp − 2σn 2 − 2d1 2 θ2 + d12 b + 1
σ2 i=1 θ =
exp − 2D1 2 θ2 + DB2 θ
Prior distribution:
f (θ) ∝ exp{− 2d1 2 (θ − b)2 } ∝ exp{− 2d1 2 θ2 + 1
d2
bθ}
Posterior distribution:
f (θ | x) ∝ f (θ) f (x | θ) ∝ Pn
exp − 2σn 2 − 2d1 2 θ2 + d12 b + 1
σ2 i=1 θ =
exp − 2D1 2 θ2 + DB2 θ
In our problem: Pn
xi
d 2 = 0.25, b = 10, i=1
n = 31
3
Substituting, B = 10.25 and D = 16−1 = 0.0625
R∞
Calculate P(θ > 10) = 10 f (θ | x) dθ.
Solution.
Prior:
q p p−1 −qθ
f (θ) = Γ(p) θ e
Solution.
Prior:
q p p−1 −qθ
f (θ) = Γ(p) θ e
Likelihood: Q
x −θ
f (x | θ) = ni=1 θ ixei !
Solution.
Prior:
q p p−1 −qθ
f (θ) = Γ(p) θ e
Likelihood: Q
x −θ
f (x | θ) = ni=1 θ ixei !
Posterior:
−qθ e −nθ θ ni=1 xi = e −(q+n)θ θ ni=1 xi +p−1 ≡
P P
f (θ | x) ∝ θp−1 e
Gamma (p + ni=1 xi , q + n) = Gamma(16, 6)
P
(ii) Given the prior distribution for the unknown coefficient θ may
be described as normal with mean b and variance σ 2 /α2 ,
show that the posterior distribution of θ is proportional to
n n
( " ! # " ! # )
1 X X
exp − a2 + xi2 /σ 2 θ2 + a2 b + yi xi /σ 2 θ
2
i=1 i=1
(iii) Use this to write down the posterior mean of θ. Show that it
may be written as
Pn
yi xi
θ̂ = wb + (1 − w ) Pi=1
n n
i=1 xi
(iii) Use this to write down the posterior mean of θ. Show that it
may be written as
Pn
yi xi
θ̂ = wb + (1 − w ) Pi=1
n n
i=1 xi
(ii)Prior: n o n o
a2 2 a2 2 a2
f (θ) = √ 1 2 exp − 2σ 2 (θ − b) ∝ exp − 2σ 2
θ + σ2
bθ
2πσ
Likelihood: Q
f (y | θ) = ni=1 f (yi | θ) ∝ ni=1 exp − 2σ1 2 xi2 θ2 + 1
Q
yxθ
σ2 i i
=
n o
θ2 Pn 2+ θ
Pn
exp − 2σ 2 x
i=1 i σ i=1 xi yi
Posterior: Pn Pn
xi2
n 2 o
2 + a2 b + i=1 xi yi
f (θ | y ) ∝ exp − 21 σa 2 + i=1 σ 2 θ σ 2 σ 2 θ ≡
2 Pn 2
−1
xi
N(B, D) where D = σa 2 + i=1 σ2
and
xi2 −1 a2
Pn n
a2 b+ ni=1 xi yi
2 P P
i=1 xi yi
B = σa 2 + i=1 σ2 σ2
b + σ2
= a2 + n x 2
P =
Pn i=1 i
yi xi
wb + (1 − w ) Pi=1
n n
i=1 xi
a 2
where w = a2 + ni=1 xi2
P
Solution.
A density belongs to Exponential Family of distributions if it can
be written in the form of f (x | θ) = h (x) g (θ) exp {t(x)c(θ)}
Solution.
A density belongs to Exponential Family of distributions if it can
be written in the form of f (x | θ) = h (x) g (θ) exp {t(x)c(θ)}
f1 (x | θ) = θ2θ exp {− (θ + 1) log x}
Exponential family with:
h(x) = 1
g (θ) = θ2θ
t(x) = log x
c(θ) = − (θ + 1)
Loukia Meligkotsidou, University of Athens Bayesian Inference
Exercise 3.1-Solution
f2 (x | x) = θ exp (θ − 1) log x − x θ
⇓
Does not belong to the Exponential family.
Solution.
J (θ) ∝ |I (θ)|1/2 ,
2
d 2 L(θ) dL(θ)
where I (θ) = −E dθ2
=E dθ
Solution.
J (θ) ∝ |I (θ)|1/2 ,
2
d 2 L(θ) dL(θ)
where I (θ) = −E =E dθ2
and L (θ) =
dθ
h i
log f (x | θ) = log (1 − θ)x−1 θ = (x − 1) log (1 − θ) + log θ
Solution.
J (θ) ∝ |I (θ)|1/2 ,
2
d 2 L(θ) dL(θ)
where I (θ) = −E =E dθ2
and L (θ) = dθ
h i
log f (x | θ) = log (1 − θ)x−1 θ = (x − 1) log (1 − θ) + log θ
dL(θ) 1 (x−1)
dθ = θ − (1−θ)
Solution.
J (θ) ∝ |I (θ)|1/2 ,
2
d 2 L(θ) dL(θ)
where I (θ) = −E =E dθ2
and L (θ) =
dθ
h i
log f (x | θ) = log (1 − θ)x−1 θ = (x − 1) log (1 − θ) + log θ
dL(θ) 1 (x−1)
dθ = θ − (1−θ)
d 2 L(θ) (x−1)
dθ2
= − θ12 − (1−θ)2
Solution.
J (θ) ∝ |I (θ)|1/2 ,
2
d 2 L(θ) dL(θ)
where I (θ) = −E =E dθ2
and L (θ) =
dθ
h i
log f (x | θ) = log (1 − θ)x−1 θ = (x − 1) log (1 − θ) + log θ
dL(θ) 1 (x−1)
dθ = θ − (1−θ)
d 2 L(θ) (x−1)
dθ2
= − θ12 − (1−θ)2
1
1 (x−1) 1 −1 1
I (θ) = E θ2
+ (1−θ)2 = θ 2 +
θ
(1−θ)2
= θ2 (1−θ)
⇒ Jeffrey’s prior
∝ 1
= (1 − θ)−1/2 θ−1 .
θ(1−θ)1/2
Loukia Meligkotsidou, University of Athens Bayesian Inference
Exercise 3.3
Solution.
d` 1
= + log a − log x
db b
d` 1
= + log a − log x
db b
2 d 2`
d ` 1 1
2
=− 2 ⇒E − 2 = 2
db b db b
d` 1
= + log a − log x
db b
2 d 2`
d ` 1 1
2
=− 2 ⇒E − 2 = 2
db b db b
2
d `
Jeffreys’ prior: J(b) ∝ |E − db 2 |1/2 = b1
d` 1
= + log a − log x
db b
2 d 2`
d ` 1 1
2
=− 2 ⇒E − 2 = 2
db b db b
2
d `
Jeffreys’ prior: J(b) ∝ |E − db 2 |1/2 = b1
Posterior:
1
f (b | x) ∝ f (x|b)J(b) ∝ bab x −b−1 = ab x −b−1
b
a b x
∝ ab x −b = = exp{−b log( )}.
x a
The posterior distribution is exponential with rate log( xa ).
Let X denote the number of times that the drawing pin lands
point up.
X ∼ Binomial(n, θ)
Likelihood: f (x | θ) ∝ θx (1 − θ)n−x
Let X denote the number of times that the drawing pin lands
point up.
X ∼ Binomial(n, θ)
Likelihood: f (x | θ) ∝ θx (1 − θ)n−x
Let X denote the number of times that the drawing pin lands
point up.
X ∼ Binomial(n, θ)
Likelihood: f (x | θ) ∝ θx (1 − θ)n−x
Posterior:
α Γ(A + B) A−1
f (θ | x) = θ (1 − θ)B−1
α + β Γ(A)Γ(B)
β Γ(P + Q) P−1
+ θ (1 − θ)Q−1 ,
α + β Γ(P)Γ(Q)
where A = x + a, B = b + n − x, P = p + x and Q = q + n − x.
Posterior:
α Γ(A + B) A−1
f (θ | x) = θ (1 − θ)B−1
α + β Γ(A)Γ(B)
β Γ(P + Q) P−1
+ θ (1 − θ)Q−1 ,
α + β Γ(P)Γ(Q)
where A = x + a, B = b + n − x, P = p + x and Q = q + n − x.
x
e −θ θx1 e −θφ (θφ) 2
(a) f (x1 , x2 | θ) = x1 ! x2 ! ∝ e −θ(1+φ) θx1 +x2
x
e −θ θx1 e −θφ (θφ) 2
(a) f (x1 , x2 | θ) = x1 ! x2 ! ∝ e −θ(1+φ) θx1 +x2
Prior:
q p p−1 −qθ
f (θ) = Γ(p) θ e ∝ θp−1 e −qθ ≡ Gamma(p, q)
x
e −θ θx1 e −θφ (θφ) 2
(a) f (x1 , x2 | θ) = x1 ! x2 ! ∝ e −θ(1+φ) θx1 +x2
Prior:
q p p−1 −qθ
f (θ) = Γ(p) θ e ∝ θp−1 e −qθ ≡ Gamma(p, q)
Posterior:
f (θ | x1 , x2 ) = θx1 +x2 +p−1 e −(1+φ+q)θ ≡
Gamma(x1 + x2 + p, 1 + φ + q) =⇒ Gamma family is
conjugate for this model.
Posterior Mean = x1+φ+q 1 +x2 +p
x
e −θ θx1 e −θφ (θφ) 2
(a) f (x1 , x2 | θ) = x1 ! x2 ! ∝ e −θ(1+φ) θx1 +x2
Prior:
q p p−1 −qθ
f (θ) = Γ(p) θ e ∝ θp−1 e −qθ ≡ Gamma(p, q)
Posterior:
f (θ | x1 , x2 ) = θx1 +x2 +p−1 e −(1+φ+q)θ ≡
Gamma(x1 + x2 + p, 1 + φ + q) =⇒ Gamma family is
conjugate for this model.
Posterior Mean = x1+φ+q 1 +x2 +p
Marginal Posterior:
Z
f (φ, x1 , x2 ) = f (φ, θ | x1 , x2 ) dθ
∞
φx2
Z
∝ θp+x1 +x2 −1 φx2 e −(1+φ+1)θ dθ
0 (1 + φ)2
φx2 Γ(p + x1 + x2 )
=
(1 + φ) (1 + φ + q)x1 +x2 +p
2
φx2 1
∝ .
(1 + φ) (1 + φ + q)x1 +x2 +p
2
θ1 θ2
f (x1 |θ) 0.70 0.20
Likelihoods f (x2 |θ) 0.30 0.80
θ1 θ2
f (x1 |θ) 0.70 0.20
Likelihoods f (x2 |θ) 0.30 0.80
Prior f (θ) 0.50 0.50
θ1 θ2
f (x1 |θ) 0.70 0.20
Likelihoods f (x2 |θ) 0.30 0.80
Prior f (θ) 0.50 0.50
f (x1 , θ) 0.35 0.10 0.45 f (x1 )
Joints f (x2 , θ) 0.15 0.40 0.55 f (x2 )
θ1 θ2
f (x1 |θ) 0.70 0.20
Likelihoods f (x2 |θ) 0.30 0.80
Prior f (θ) 0.50 0.50
f (x1 , θ) 0.35 0.10 0.45 f (x1 )
Joints f (x2 , θ) 0.15 0.40 0.55 f (x2 )
a1 a2
f (θ|x1 ) 7/9 2/9 -1200/9 0 Expected
Posteriors f (θ|x2 ) 3/11 8/11 200/11 0 Losses
Bayes Risk:
1200
BR(d) = ρ(d(x1 ), x1 )f (x1 )+ρ(d(x2 ), x2 )f (x2 ) = − ×0.45+0×0.55 = −60
9
Bayes Risk:
1200
BR(d) = ρ(d(x1 ), x1 )f (x1 )+ρ(d(x2 ), x2 )f (x2 ) = − ×0.45+0×0.55 = −60
9
That is the profit associated with our decision rule is £60. The
gain of £10 does not worth the £30 cost of the expert’s services.
Prior:
f (θ) = 1, 0 ≤ θ ≤ 1
Likelihood:
f (x | θ) = nθ θx (1 − θ)n−x
Prior:
f (θ) = 1, 0 ≤ θ ≤ 1
Likelihood:
f (x | θ) = nθ θx (1 − θ)n−x
Posterior:
f (θ | x) ∝ θx (1 − θ)n−x ≡ Beta(x + 1, n − x + 1)
Prior:
f (θ) = 1, 0 ≤ θ ≤ 1
Likelihood:
f (x | θ) = nθ θx (1 − θ)n−x
Posterior:
f (θ | x) ∝ θx (1 − θ)n−x ≡ Beta(x + 1, n − x + 1)
Prior:
f (θ) = 1, 0 ≤ θ ≤ 1
Likelihood:
f (x | θ) = nθ θx (1 − θ)n−x
Posterior:
f (θ | x) ∝ θx (1 − θ)n−x ≡ Beta(x + 1, n − x + 1)
Prior:
f (θ) = 1, 0 ≤ θ ≤ 1
Likelihood:
f (x | θ) = nθ θx (1 − θ)n−x
Posterior:
f (θ | x) ∝ θx (1 − θ)n−x ≡ Beta(x + 1, n − x + 1)
Solution.
f (θ | x) ∝ θP−1 (1 − θ)Q−1
log f (θ | x) = (P − 1) log θ + (Q − 1) log(1 − θ) + c
Solution.
f (θ | x) ∝ θP−1 (1 − θ)Q−1
log f (θ | x) = (P − 1) log θ + (Q − 1) log(1 − θ) + c
d log f (θ|x) Q−1
dθ = 0 ⇒ P−1
θ − 1−θ = 0 ⇒
P−1 Q−1
θ = 1−θ ⇒ P − 1 − (P − 1)θ = (Q − 1)θ ⇒
P−1
(P + Q − 2)θ = P − 1 ⇒ θ = P+Q−2 [posterior mode]
Solution.
f (θ | x) ∝ θP−1 (1 − θ)Q−1
log f (θ | x) = (P − 1) log θ + (Q − 1) log(1 − θ) + c
d log f (θ|x) Q−1
dθ = 0 ⇒ P−1
θ − 1−θ = 0 ⇒
P−1 Q−1
θ = 1−θ ⇒ P − 1 − (P − 1)θ = (Q − 1)θ ⇒
P−1
(P + Q − 2)θ = P − 1 ⇒ θ = P+Q−2 [posterior mode]
P
Posterior mean: E (θ | x) = P+Q [closer to 1/2 than mode]
Solution.
Solution.
R region Cα (x) is a 100(1 − α)% credible region for θ if
A
Cα (x)
f (θ | x) dθ = 1 − α. It is an HPD region if Cα (x) = {θ : f (θ | x) ≥ γ}.
Solution.
R region Cα (x) is a 100(1 − α)% credible region for θ if
A
Cα (x)
f (θ | x) dθ = 1 − α. It is an HPD region if Cα (x) = {θ : f (θ | x) ≥ γ}.
1
In our case, f (θ | x) = B(3,2) θ2 (1 − θ) = 12θ2 (1 − θ) , θ ∈ [0, 1] .
h ib
2 (1 − θ) dθ = 0.943 ⇔ 12 θ3 − θ4
Rb
a 12θ 3 4 = 0.943 ⇔
a
4b 3 − 3b 4 − 4a3 + 3a4 = 0.943.
Solution.
R region Cα (x) is a 100(1 − α)% credible region for θ if
A
Cα (x)
f (θ | x) dθ = 1 − α. It is an HPD region if Cα (x) = {θ : f (θ | x) ≥ γ}.
1
In our case, f (θ | x) = B(3,2) θ2 (1 − θ) = 12θ2 (1 − θ) , θ ∈ [0, 1] .
h ib
2 (1 − θ) dθ = 0.943 ⇔ 12 θ3 − θ4
Rb
a 12θ 3 4 = 0.943 ⇔
a
4b 3 − 3b 4 − 4a3 + 3a4 = 0.943.
Moreover, 12a2 (1 − a) = 12b 2 (1 − b) = γ.
Solution.
R region Cα (x) is a 100(1 − α)% credible region for θ if
A
Cα (x)
f (θ | x) dθ = 1 − α. It is an HPD region if Cα (x) = {θ : f (θ | x) ≥ γ}.
1
In our case, f (θ | x) = B(3,2) θ2 (1 − θ) = 12θ2 (1 − θ) , θ ∈ [0, 1] .
h ib
2 (1 − θ) dθ = 0.943 ⇔ 12 θ3 − θ4
Rb
a 12θ 3 4 = 0.943 ⇔
a
4b 3 − 3b 4 − 4a3 + 3a4 = 0.943.
Moreover, 12a2 (1 − a) = 12b 2 (1 − b) = γ.
Solving the two-equation system, we derive a = 5/21 and
b = 20/21.
Solution.
The posterior density of θ is decreasing (Exponential(1)). Thus,
the 95% HPD region is an interval of the form [0,b] satisfying
R b −θ
0 e = 0.95 ⇔ 1 − e −b = 0.95 =⇒ C0.05 (x) = [0, 3] .
Solution.
The posterior density of θ is decreasing (Exponential(1)). Thus,
the 95% HPD region is an interval of the form [0,b] satisfying
R b −θ
0 e = 0.95 ⇔ 1 − e −b = 0.95 =⇒ C0.05 (x) = [0, 3] .
√ 2
Now, we have that φ = 2θ ⇔ θ = φ2 . Posterior density of φ:
dθ 1 2
fφ (φ | x) = fθ (φ) = φe − 2 φ .
dφ
Solution.
The posterior density of θ is decreasing (Exponential(1)). Thus,
the 95% HPD region is an interval of the form [0,b] satisfying
R b −θ
0 e = 0.95 ⇔ 1 − e −b = 0.95 =⇒ C0.05 (x) = [0, 3] .
√ 2
Now, we have that φ = 2θ ⇔ θ = φ2 . Posterior density of φ:
dθ 1 2
fφ (φ | x) = fθ (φ) = φe − 2 φ .
dφ
Since the posterior density of φ is not monotonic, the credibility
interval will be of the form [a, b] with a 6= 0. Hence, it is not a
transformation of the credibility interval for θ.
Loukia Meligkotsidou, University of Athens Bayesian Inference
Exercise 5.8
H0 : θ = 1
H1 : θ 6= 1
under H1 .
(a) Calculate the posterior probability of H0 .
p
P
q Γ( xP
i +p)
Let α = 0.95e −n and β = 0.05 Γ(p) (n+q) xi +p
.
α
Then P(H0 | x) = α+β .
p
P
q Γ( xP
i +p)
Let α = 0.95e −n and β = 0.05 Γ(p) (n+q) xi +p
.
α
Then P(H0 | x) = α+β .
p
P
q Γ( xP
i +p)
Let α = 0.95e −n and β = 0.05 Γ(p) (n+q) xi +p
.
α
Then P(H0 | x) = α+β .
Solution R
f (y | x) = f (y | θ) f (x | θ) dθ
Solution R
f (y | x) = f (y | θ) f (x | θ) dθ
−θ x hg g −1
Posterior: f (θ | x) ∝ ni=1 e xi !θ i
Q
Γ(g ) θ exp {−hθ}
Solution R
f (y | x) = f (y | θ) f (x | θ) dθ
−θ x hg g −1
Posterior: f (θ | x) ∝ ni=1 e xi !θ i Γ(g
Q
)θ exp {−hθ}
Mariginal likelihood:
R ∞ Qn e −θ θxi hg g −1
f (x) = 0 i=1 xi ! Γ(g ) θ exp {−hθ} dθ =
Pn Pn
e −nθ θ i=1 ∞
i=1 xi +g −1 dθ
R
Q n
xi !Γ(g ) 0 exp {− (n + h) θ} θ
i=1
Pn Pn
e −nθ θ i=1 Γ i=1 x +g
Pn i
= Q n x +g
i=1 xi !Γ(g ) (n+h) i=1 i
Qn e −θ θxi hg g −1
i=1 xi ! Γ(g ) θ exp {−hθ}
⇒ f (θ | x) = Pn Pn
e −nθQ θ i=1 Γ( i=1 xi +g )
Γ(g ) ni=1 xi ! (n+h) ni=1 xi +g
P
Pn
(n + h) i=1 xi +g Pni=1 xi +g −1
= θ exp {− (h + n) θ}
Γ ( ni=1 xi + g )
P
Predictive distribution
R
f (y | Px) = f (y | θ)f (θ | x)dθ =
n
(n+h) i=1 xi +g R ∞ e −θ θy
Pn
Pn θ i=1 xi +g −1 exp {− (h + n) θ} =
Γ( i=1 xi +g ) 0 y !
Predictive distribution
R
f (y | Px) = f (y | θ)f (θ | x)dθ =
n
(n+h) i=1 xi +g R ∞ e −θ θy
Pn
Pn θ i=1 xi +g −1 exp {− (h + n) θ} =
Γ( i=1 xi +g ) 0 y !
Pn
(n+h) i=1 xi +g R ∞
Pn
Pn θ i=1 xi +g +y −1 exp {− (h + n + 1) θ} =
Γ( i=1 xi +g )y ! 0
Predictive distribution
R
f (y | Px) = f (y | θ)f (θ | x)dθ =
n
(n+h) i=1 xi +g R ∞ e −θ θy
Pn
Pn θ i=1 xi +g −1 exp {− (h + n) θ} =
Γ( i=1 xi +g ) 0 y !
Pn
(n+h) i=1 xi +g R ∞
Pn
Pn θ i=1 xi +g +y −1 exp {− (h + n + 1) θ} =
Γ( i=1 xi +g )y ! 0
Pn Pn
(n+h) i=1 xi +g Γ( i=1P xi +g +y )
Pn n
Γ( i=1 xi +g )y ! (h+n+1) i=1 xi +g +y
=
y Pni=1 xi +g
( ni=1 xi +g +y −1)!
P
1 n+h
=
( ni=1 xi +g −1)y ! h+n+1 n+h+1
P
G −1+y
1 y
1
G
1
G −1 1+H 1 − H+1 ≡ NegativeBinomial 1+H , G
Solution
√ 1 exp − 2D1 2 (θ − B)2
Posterior: f (θ | x) =
2πD 2
R
Predictive: f (y | x) = f (y | θ)f (θ | x)dθ
R∞
= −∞ √ 1 2 exp − 2σ1 2 (y − θ)2 √ 1 2 exp − 2D1 2 (θ − B)2 dθ
2πσ 2πD
R∞
√ 1 exp − 2σ1 2 (y − θ)2 √ 1
exp − 2D1 2 (θ − B)2 dθ
= −∞ 2πσ 2 2πD 2
R∞
√ 1 exp − 2σ1 2 (y − θ)2 √ 1 2 exp − 2D1 2 (θ − B)2 dθ
= −∞ 2πσ 2 2πD
n o
1 y2
1
R∞ yθ θ2 θ2 θB B2
= 2πσD −∞ exp − [
2 σ2 − 2 σ2
+ σ2
+ D2
− 2 D2
+ D2
] dθ
R∞
√ 1 exp − 2σ1 2 (y − θ)2 √ 1 2 exp − 2D1 2 (θ − B)2 dθ
= −∞ 2πσ 2 2πD
n o
1 y2
1
R∞ yθ θ2 θ2 θB B2
= 2πσD −∞ exp − [
2 σ2 − 2 σ2
+ σ2
+ D2
− 2 D2
+ D2
] dθ
n −2 −2 o
2 − 2θ y σ −2 +BD −2 + ( y σ −2 +BD −2 )2 ] dθ
R∞ σ +D
= −∞ exp − 2 [θ σ −2 +D −2 σ −2 +D −2
(σ −2 y +BD −2 )2
n o
1 y2 B2
× 2πσD exp − 2σ 2 − 2D 2
+ 2(σ −2 +D −2 )
R∞
√ 1 exp − 2σ1 2 (y − θ)2 √ 1 2 exp − 2D1 2 (θ − B)2 dθ
= −∞ 2πσ 2 2πD
n o
1 y2
1
R∞ yθ θ2 θ2 θB B2
= 2πσD −∞ exp − [
2 σ2 − 2 σ2
+ σ2
+ D2
− 2 D2
+ D2
] dθ
n −2 −2 o
2 − 2θ y σ −2 +BD −2 + ( y σ −2 +BD −2 )2 ] dθ
R∞ σ +D
= −∞ exp − 2 [θ σ −2 +D −2 σ −2 +D −2
(σ −2 y +BD −2 )2
n o
1 y2 B2
× 2πσD exp − 2σ 2 − 2D 2
+ 2(σ −2 +D −2 )
√
2π 1
= √
σ −2 +D −2
× 2πσD ×
n 2 2
o
B 2 σ2
exp − 2σ2 D 2 (σ1−2 +D −2 ) [ y σD2 + y 2 + D2
+ B 2 − σ 2 D 2 (σ −2 y + BD −2 )2 ]
2 2
B 2 σ2
=√ 1
exp{− 2(D 21+σ2 ) [ y σD2 + y 2 + D2
+ B2
2π(D 2 +σ 2 )
− σ 2 D 2 σ −4 y 2 − σ 2 D 2 B 2 D −4 − 2σ 2 D 2 σ −2 yBD −2 ]}
2 2
B 2 σ2
=√ 1
exp{− 2(D 21+σ2 ) [ y σD2 + y 2 + D2
+ B2
2π(D 2 +σ 2 )
− σ 2 D 2 σ −4 y 2 − σ 2 D 2 B 2 D −4 − 2σ 2 D 2 σ −2 yBD −2 ]}
1
=√ exp{− 2(D 21+σ2 ) (y 2 + B 2 − 2yB)}
2π(D 2 +σ 2 )
1
=√ exp{− 2(D 21+σ2 ) (y − B)2 }
2π(D 2 +σ 2 )
Therefore y | x ∼ N(B, D 2 + σ 2 )
(a) Likelihood:Q
f (x | θ) = θ1n ni=1 I (0 ≤ xi ≤ θ) = 1
θn I (0 ≤ M ≤ θ),
where M = max(x1 , . . . , xn )
Prior: f (θ) = 1θ
1
Posterior: f (θ | x) = cf (x | θ)f (θ) = c θn+1 I (θ ≥ M)
(a) Likelihood:Q
f (x | θ) = θ1n ni=1 I (0 ≤ xi ≤ θ) = 1
θn I (0 ≤ M ≤ θ),
where M = max(x1 , . . . , xn )
Prior: f (θ) = 1θ
1
Posterior: f (θ | x) = cf (x | θ)f (θ) = c θn+1 I (θ ≥ M)
−n ∞
R∞ 1 h i
dθ = 1 ⇒ c θ−n
R
f (θ | x)dθ = 1 ⇒ c M θn+1 =1⇒
M
(a) Likelihood:Q
f (x | θ) = θ1n ni=1 I (0 ≤ xi ≤ θ) = 1
θn I (0 ≤ M ≤ θ),
where M = max(x1 , . . . , xn )
Prior: f (θ) = 1θ
1
Posterior: f (θ | x) = cf (x | θ)f (θ) = c θn+1 I (θ ≥ M)
−n ∞
R∞ 1 h i
dθ = 1 ⇒ c θ−n
R
f (θ | x)dθ = 1 ⇒ c M θn+1 =1⇒
M
−n nM n
c Mn = 1 ⇒ c = nM n ⇒ f (θ | x) = θn+1
, θ ≥ M.
(a) Likelihood:Q
f (x | θ) = θ1n ni=1 I (0 ≤ xi ≤ θ) = 1
θn I (0 ≤ M ≤ θ),
where M = max(x1 , . . . , xn )
Prior: f (θ) = 1θ
1
Posterior: f (θ | x) = cf (x | θ)f (θ) = c θn+1 I (θ ≥ M)
−n ∞
R∞ 1 h i
dθ = 1 ⇒ c θ−n
R
f (θ | x)dθ = 1 ⇒ c M θn+1 =1⇒
M
−n nM n
c Mn = 1 ⇒ c = nM n ⇒ f (θ | x) = θn+1
, θ ≥ M.
1
Pr(θ > t M|x) = for any t ≥ 1.
tn
(d) A further, independent, observation Y is made from the same
distribution as X . Show that the predictive distribution of Y
has density
1 n 1
f (y |x) = ; y ≥ 0.
M n + 1 [max(1, y /M)]n+1
nM n
Z Z
1
f (y | x) = f (y | θ)f (θ | x)dθ = I (θ ≥ y ) n+1 I (θ ≥ M)dθ
θ θ
nM n
Z Z
1
f (y | x) = f (y | θ)f (θ | x)dθ = I (θ ≥ y ) n+1 I (θ ≥ M)dθ
θ θ
Z ∞ n
n
∞
nM nM
= n+2
dθ = θ−n−1
max(M,y ) θ −n − 1 max(M,y )
nM n
Z Z
1
f (y | x) = f (y | θ)f (θ | x)dθ = I (θ ≥ y ) n+1 I (θ ≥ M)dθ
θ θ
Z ∞ n
n
∞
nM nM
= n+2
dθ = θ−n−1
max(M,y ) θ −n − 1 max(M,y )
nM n 1
=
n + 1 [max(M, y )]n+1
nM n
Z Z
1
f (y | x) = f (y | θ)f (θ | x)dθ = I (θ ≥ y ) n+1 I (θ ≥ M)dθ
θ θ
Z ∞ n
n
∞
nM nM
= n+2
dθ = θ−n−1
max(M,y ) θ −n − 1 max(M,y )
nM n 1
=
n + 1 [max(M, y )]n+1
nM n 1
= n+1
n+1M [max(M/M, y /M)]n+1
nM n
Z Z
1
f (y | x) = f (y | θ)f (θ | x)dθ = I (θ ≥ y ) n+1 I (θ ≥ M)dθ
θ θ
Z ∞ n
n
∞
nM nM
= n+2
dθ = θ−n−1
max(M,y ) θ −n − 1 max(M,y )
nM n 1
=
n + 1 [max(M, y )]n+1
nM n 1
= n+1
n+1M [max(M/M, y /M)]n+1
1 n 1
= , y ≥ 0.
M n + 1 [max(1, y /M)]n+1