You are on page 1of 3

STATS LAB 10: Monte Carlo Integration and Random Number Generation. Gamma Distribution.

Some MATLAB functions: diff(); exp(); hist(); if-then-else; linspace(); mean(); median(); rand(); solve(); std(); syms; var(); while... Gamma distribution is often used in modeling of catastrophic events and (logically enough) the size of insurance claim. An example is distribution of the extent of ooding, where most ooding tends to be relatively small, but there is a possibility of large oods as well. Recall that the p.d.f. of a Gamma(k, ) is fX (x) =
k k1 x e (k) x

for x 0 for x < 0

k k and Var(X ) = so that E(X ) = 2 . However, there is no analytical form for the c.d.f. FX (x) and thus also no formula for the median.

Consider a Gamma(2, 1) distribution. We will now use simulation methods to see, what its median is. 1 Write out its pdf, and plot it on a suitable interval. (you might want to create a MATLAB function evaluating fX (x) for the ease of coding. The Gamma distribution generally does not lend itself to inverse sampling (why?), so we are going to use rejection sampling. One simple proposal distribution g (x) is a uniform on some reasonable interval. The lower bound of this interval is obviously 0, the upper bound should be chosen so, that the probability of a variable going beyond that is negligible. (Note, that this bound may somewhat depend on a sample size). 2 Choose a suitable interval, and write down your g (x). Evaluate the resulting (x) b = supx f g (x) (i.e. found absolute maximum of this ratio on your interval) and check that the proposal function is acceptable. 3 Perform rejection sampling to generate 1000 observations: Sample x from your uniform distribution g (x) Sample u from a uniform U[0, 1] If ubg (x) f (x) then accept x. 2

f(x)

0.0 0

0.1

0.2

0.3

0.4

4 x

10

Figure 1: Gamma(2, 1) probability density function. How many iterations did you need to obtain your sample? Plot it. Does it look like the rst gure? Write down the mean and variance of your sample. . Are they far from the theoretical values? Write down the median estimate M Now, lets use Monte Carlo integration to see how good your estimate is. Since median is such a value that 50% of the pdf lie to the left of it, we need to calculate an integral under the Gamma pdf curve on the interval from 0 to your . In order to choose a suitable rectangular domain D, look estimated median M at your plot of the gamma distribution: what is the good interval? Remember, that it should enclose the area of interest, but should not be too large. 4 Perform MC integration to estimate the area under the Gamma(2, k ) curve ]. on the interval [0, M ] Sample 5000 observations uniformly from the interval [0, M Sample 5000 observations uniformly from the chosen interval on y -axis. Calculate the proportion of points under the curve Multiply the proportion by the area of your rectangular domain D. 3

What is your evaluation of the integral? Is it close to .5? What would be your conclusion as to the performance of both algorithms in this case? How can it be improved?

You might also like