STAT 462/862 Final Exam Page 2 of 3
1. Consider the following model
f (x | θ) = x exp x2 + θ2 − 2
I0(x θ), x > 0, θ > 0 ,
where I0(·) is called modified Bessel function of the first kind and can be called in R
using
BesselI. Assume the improper prior π(θ) = 1 for θ ∈ R+.
(a) Computes and plot the logarithm of posterior distribution using R for the observed vector
x = (1.6, 1.7, 3.1, 1.3, 1.9, 1, 3, 0.7, 2.4, 2) .
(b) Give a general formula for the predictive distribution of new observation xn+1 based on
observed vector x = (x1, · · · , xn). 4 Furthermore, compute and plot f (x11 | x) based on
part (a) by using simulation. (Hint: You can use the following code to generate a sample
for f (x | θ).
rpdf<-function(n , theta){
x <- rnorm(n=n, mean=0, sd=1)
y <- rnorm(n=n, mean= theta, sd=1)
return(sqrt(x^2+y^2))
2. Consider the following model yi = β0 + β1xi + si, i = 1, . . . , n, where
si i∼id
N (0, σ2) and
β0, β1, σ2 are unknown parameters. In addition, suppose the prior densities are:
β0 ∼ N (γ0, τ 2)
β1 ∼ N (γ1, τ 2)
σ2 ∼ Itt(δ/2, δν2/2).
where Itt(δ/2, δν2/2) represents the inverse gamma distribution with mean δ/2 and variance
δν2/2, the hyperparameters γ0, τ0, γ1, τ1, δ, ν are known constants. Let θ = (β0, β1, σ2) and
x = (11.2, 24.6, 10.3, 2.2, 17.2, 2.7, 13.9, 6.9, 15.1, 2.6, 6, 7, , 14.1, 9.9, 10.3, 1.4, 11.4, 9.7, 10.4, 5.5)
(a) Obtain posterior distribution of θ.
(b) Obtain full conditional distribution of β0,β1,σ2, respectively.
4You don’t need to compute any integral, just give a general formula for f (xn+1 | x).
(c) Estimate the parameters β0, β1, σ2 using the samples generated via Gibbs
sampling. The
hyperparameters are chosen to be γ0 = 0, τ 2 = 5, γ1 = 0, τ 2 = 5, δ = 3, ν = 1. 0 1
3. Consider the problem of generating sample from a Beta distribution Bet(α, β).
(a) One result is, if two Gamma random variables are X1 ∼ ttam(α, 1) and
X2 ∼ ttam(β, 1), then X
X = X + X ∼ Be(α, β).
Use this result to construct an algorithm to generate a Beta random
sample. Provide a density histogram to emulate the performance.
(b) Compare the algorithm in (a) with the rejection method based on (i)
the uniform. dis- tribution; (ii) the truncated normal distribution.
4. Let X i∼id be a sample from a following mixture model:
f (x | θ) = π N(x |µ, σ2) + (1 − π) c ,
where c = 1 ( i.e. the pdf of a uniform. distribution on (−a, a)).
(a) Generate a sample of size n using sample, rnorm, runif and draw
the corresponding histogram and box plot of the data. Take:
pi<-0.90; mu<-2; sigma<- 1; a=6;
(b) Write the EM algorithm and apply it to the data in order to estimate θ = (µ, σ2, π).