Está en la página 1de 4

STAT 462/862 Final Exam solution Dec 09, 2017.

Exam rules

Please read these rules carefully:

1. the exam will be emailed to you on Dec 09 at 12 noon.

2. You have exactly 24 hours to solve the exam. It has to be received by 12 noon on Dec 10 in
person and in a hard copy. Please drop your hard copy in my mailbox in Jeff 518.1

3. Send the electronic copy of your pure2 codes in R.Script3 to a.sadeghkhani@queensu.ca

4. Write your answers in order, clear, in details and readable. Severe readability issues may be
penalized by grade. Enclose your codes and printouts related to each question in your hard
copy.

5. Absolutely no extensions. Late submission will not be grading.

6. The exam must be taken completely alone. Showing it or discussing it with anybody is
totally forbidden, including (but not limited to) the other students in the course in current
or previous years. It is also forbidden to use any solutions to similar problems from previous
years as reference material. Any similar work will result in reduced marks.

7. You may use any publicly available material you want, including books, the internet and . . .

8. You are NOT allowed to submit questions to internet or email them.

9. If you find a solution of a test problem in a book or online, cite it in your submission and do
not copy it as-is, but make changes which demonstrate you understand what you are writing.
Otherwise I might not accept it.

1
Jeffery Hall is unlocked on weekends during the exam period.
2
No comments, no justification, no output, only executable codes should be emailed to me
3
or SAS if you wish
STAT 462/862 Final Exam solution Page 2 of 4

1. Consider the following model


 x2 + θ 2 
f (x | θ) = x exp − I0 (x θ), x > 0, θ > 0 ,
2

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))

Solution: R codes

iid
2. Consider the following model yi = β0 + β1 xi + i , i = 1, . . . , n, where i ∼ N (0, σ 2 ) and
β0 , β1 , σ 2 are unknown parameters. In addition, suppose the prior densities are:

β0 ∼ N (γ0 , τ02 )

β1 ∼ N (γ1 , τ12 )

σ 2 ∼ IG(δ/2, δν 2 /2).

where IG(δ/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)
4
You don’t need to compute any integral, just give a general formula for f (xn+1 | x).

Cont.
STAT 462/862 Final Exam solution Page 3 of 4

(a) Obtain posterior distribution of θ.

(b) Obtain full conditional distribution of β0 ,β1 ,σ 2 , respectively.

(c) Estimate the parameters β0 , β1 , σ 2 using the samples generated via Gibbs sampling. The
hyperparameters are chosen to be γ0 = 0, τ02 = 5, γ1 = 0, τ12 = 5, δ = 3, ν = 1.

Solution: Here.

3. Consider the problem of generating sample from a Beta distribution Bet(α, β).

(a) One result is, if two Gamma random variables are X1 ∼ Gam(α, 1) and X2 ∼ Gam(β, 1),
then
X1
X= ∼ Be(α, β).
X1 + X2
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.

Solution: R codes

iid
4. Let Xi ∼ be a sample from a following mixture model:

f (x | θ) = π N(x |µ, σ 2 ) + (1 − π) c ,

1
where c = 2a ( 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 , π).

Solution: R codes

Cont.
STAT 462/862 Final Exam solution Page 4 of 4

5. (Only for STAT 862)

(a) Use Metropolis–Hastings methods for generating random samples from f (x) = x/σ 2 exp (−x2 /2σ 2 );
x > 0, using the proposal distribution Chi-Square.

(b) Plot samples from 5, 000 − 10, 000.

(c) Plot the density based on the sample obtained in (b).

Hint: Take σ = 4. Draw initial x(1) from χ2 (1) density. Take the next initial candidate from
q
2
χ2 ( σ2 π). Draw later candidates x(t) from χ2 (x(t−1) ) density.
Solution: R codes

Best of Luck!
Nasser Sadeghkhani

The End.

También podría gustarte