00:01
In this exercise, we want to simulate the geometric random variable using the inverse cdf method.
00:09
The cdf of the geometric random variable is given by this equation, and using the inverse cdf method, we want to find x such that this inequality holds.
00:31
Another way of stating this is to find x as the biggest integer that is less than or equal to the inverse cdf of u.
00:59
So the process for drawing a random variable from the geometric random variable is first you draw a uniform random variable and then two you find x to satisfy this statement.
01:30
So actually this should be greater than.
01:38
So now if we set f at x equal to you, we have 1 minus 1 minus p to the exponent x equals u, 1 minus p to the exponent x equals u minus 1.
02:11
1 minus p to the exponent x equals 1 minus u.
02:15
And now if we take the base 1 minus p logarithm of both sides, we have, and this is our inverse cdf.
02:44
So now i have made some code in r to achieve the simulation.
02:49
So the code looks like this.
02:57
So we start out by setting the number of simulations to some number, and we define the probability of success.
03:06
And then we run n uniform random variables.
03:11
So u is a vector that contains n uniform random variables.
03:16
And then for each of these random variables, we find the inverse cdf, so we find the value that we want to assign to x.
03:26
So x gives us a vector that is n values.
03:31
Each of these values are a random draw from the geometric random variable with probability success p.
03:38
And there should be one more bracket in here.
03:47
That's part a.
03:50
For part b we were asked to simulate the program using 10 ,000 values and probability of success, 0 .85 to determine three things.
04:00
The probability that x is at most of 2, the expected value for x and the standard deviation for x.
04:07
So i already have the probability of 0 .85 in here.
04:12
And so that would be 10 ,000 simulations...