# NU Simulation using R Density Functions Worksheet

I have done part (a) of the question and require some assistance on the rest of the question. Part (g) is to be done in R code please. Reference textbook would be Simulation by Sheldon M Ross

(QI)

X₁₂X₂X₁

~ N (0,0) where On Gamma (3,0.5) that

2-8/2

p(0) = 0² e

oso.

(

23 (3)

(a) find P(0|X₁, X₂,…, Xn)

subject to a constant Cp.

P/O|X₁, X₂, Xn

· P(X₁,… Xn \e) x P (e)

likelihood

prior

likelihood:

n

n

P ( X₁ X₂ 10) = π P(xile)

Xn

– ( + )”^ *x² 10 2 × ² ) – (20) ³ – 4 [ 1 2 ]

(one)

exp

ΣΧ

-exp

20

2011

i=1

X

3-1 -0.50

(0.5)

Prior:p/B) x (03²-

0.125

.

0

e

да

8²₁ exp(- 120) = 1/12 0²ª exp[-1/10)

F(3)

16

0

П(3)

_n/2

2

Hence, Ti (01 X₁, X₂2 – Xx₁) = (211).”

– exp(-2/10 2/2 X ₁ ² – 1/10)

16

_n/2 ta

0²1. Suppose X₁, X2, Xn~ N(0,0) where ~ Gamma(3, 0.5), that

e/2

p(0) =

0 > 0.

2³1 (3)

Note. For this question, you can use any random variable generation function in R, such

as rnorm(), rgamma() and so on. You can also use gamma() to calculate I'(z) for any z.

(a) Find the posterior distribution that p(0|₁,2,,n), subject to a constant cp-

(b) We are interested in the mean of the posterior distribution, which is

=

– 1.²00.

0p(01₁, I2, In) do.

The posterior distribution is hard to sample even with the rejection algorithm. So

we want to use the importance sampling algorithm.

Suppose we have the random variables Y₁, Y2, ,Ymq, where q is a distribution.

Please write out the estimation in terms of m, p(0) = p(0|₁, 22, In), q, and Y’s.

1

(e) To get rid of the constants, let p = cppo

and po, o are kernel functions. Prove that

and q = 90. where Cp

and care constants

14

ƒ(@)p(0)q(0)d

9(0)

f(@)po(0)

90(0)

S10P(0)

S

(90)do

9(0)9(0)de f q(0)d0

Po(0)

90 (0)

q(0)d0

(d) According to part (b) and (c), find the estimation in terms of m, Po, 90, and Y’s.

Further, express them in terms of log po, log go and Yi’s.

(e) We set the function q to be Gamma(cs², c), i.e.

-1-

g(0) =

0 > 0.

[(c8²)

Here, s² is the sample variance and c> 0 is a parameter to decide. We use c to make

the function flat.

With the density functions of p and q, write R functions to calculate log po and log go-

(f) With all the previous definitions of p, q and the discussion, write a pseudo-code to

estimate E.

(g) Generate 100 data points with distribution N(0,5), denoted by ₁,2,,100. It

means the ground truth is 0 = 5.

With your generated data, run your code to estimate E with c ranges from 0.04 to

20 with step size 0.04, m= 1000. Draw one plot of Ê versus c and comment.