Question

Q. 2 a) Using only Unif 0,1) random variates, use a Monte Carlo algorithm to approximate the value of the Gamma function 0 by

0 0
Add a comment Improve this question Transcribed image text
Answer #1

0 Then ri 2 a -,

R Program

f=function(n,alpha)
{
s1=0
s2=0
x=numeric(n)
for(i in 1:n)
{
x[i]=-log(1-runif(1,0,1))
s1=s1+x[i]^(alpha-1)
s2=s2+x[i]^(2*alpha-2)
}
est=s1/n
var_est=s2/n-est^2
se_est=sqrt(var_est/n)
cat(" ",c("Estimated=",est,"Actual=",gamma(alpha),"SE=",se_est))
}
# Values for Gamma(3)
f(100,3)
f(1000,3)
f(5000,3)
f(10000,3)

#Values for Gamma(6)
f(100,6)
f(1000,6)
f(5000,6)
f(10000,6)

R Output

> f(100,3)

Estimated= 2.39643722309558 Actual= 2 SE= 0.78419283402655> f(1000,3)

Estimated= 2.39853899997827 Actual= 2 SE= 0.184532664126924> f(5000,3)

Estimated= 1.91312239062837 Actual= 2 SE= 0.059122563425076> f(10000,3)

Estimated= 2.04307398594427 Actual= 2 SE= 0.0475782103374921>
> #Values for Gamma(6)
> f(100,6)

Estimated= 69.9108955051665 Actual= 120 SE= 50.9203707580712> f(1000,6)

Estimated= 109.469711149383 Actual= 120 SE= 23.651514011367> f(5000,6)

Estimated= 154.31873737748 Actual= 120 SE= 33.2707135100746> f(10000,6)

Estimated= 120.553249455824 Actual= 120 SE= 17.2548285523348

Comment

For fixed alpha, as we increase simulation number, the monte carlo estimate becomes closer to the actual with a substantial decrease in SE value. Only alpha=3 and 6 are considered here but works well for other choices also.

Add a comment
Know the answer?
Add Answer to:
Q. 2 a) Using only Unif 0,1) random variates, use a Monte Carlo algorithm to approximate...
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
  • [20 points] Problem 2 - Monte Carlo Estimation of Definite Integrals One really cool application of...

    [20 points] Problem 2 - Monte Carlo Estimation of Definite Integrals One really cool application of random variables is using them to approximate integrals/area under a curve. This method of approximating integrals is used frequently in computational science to approximate really difficult integrals that we never want to do by hand. In this exercise you'll figure out how we can do this in practice and test your method on a relatively simple integral. Part A. Let X be a random...

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