Question
Really short question! Please help me to solve! It also needs the R code, thank you!
(25%)Q2: Please use the accept-reject method to generate 5000 samples from f(x) = 02 n which gfx) - 3e-3) and M f(x) M.g() an
Requirements:
algorithm proof R code
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Algorithm: 1. Generate zo from the proposal density g 2. Calculate M and f(xo)/(Mg(xo)) 3. Generate u from Uniform(0,1), inde

R Code

n=5000
f=function()
{
M=exp(-4.5)/(3*sqrt(2*pi)*(1-pnorm(3)))
y=numeric(n)
for(i in 1:n)
{
repeat
{
x=3+rexp(1,rate=3)
r=(dnorm(x)/(1-pnorm(3)))/(M*3*exp(-3*x+9))

u=runif(1,0,1)
if(u<=r) break
}
y[i]=x
}
return(y)
}

Add a comment
Know the answer?
Add Answer to:
Really short question! Please help me to solve! It also needs the R code, thank you!...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT