0

As part of an assignment, I have been asked to write an Octave function that will generate m pseudorandom outcomes of a geometric RV X with parameter p = 0.55 in 2 separate ways:

  1. Directly using the cdf of the RV
  2. Using the fact that the variable is produced using independent Bernoulli experiments.

For 2, my thoughts are:

  • create a loop of m iterations
  • create an inner loop that repeats until there is a successful trial
  • have a counting variable in the inner loop that counts how many failures there are before a success, and store this count for each of the m iterations of the outer loop.

However, I am quite lost with part one, and am struggling to even understand what the question means by "directly using the cdf of the random variable".

EDIT

Here is what I have done so far:

function x = generate_geometric_cdf(p, m)
  % generate geometric RV X with parameter p, m times using the cdf

  emperical = zeros(1,m);         % allocate array for empirical results of m simulations
  for i = 1:m                     % iterate over m simulations
    u = rand;                     % generate a random number between 0-1
    emperical(i) = geocdf(u, p);  % store the outcome of the geometric distribution at u           
  end

end

EDIT 2

geoinv was the function I needed as opposed to geocdf. geocdf(u, p) returns the probability from the cdf for of value u, with parameter p whereas geoinv(u, p) does the inverse and returns a random value given the probability u and parameter p.

KOB
  • 4,084
  • 9
  • 44
  • 88
  • Show us what you have done so far. – NKN Mar 23 '17 at 23:43
  • @NKN no problem, see my edit. – KOB Mar 23 '17 at 23:52
  • You would need a `while` loop, not a `for`, because the required number of operations is unknown beforehand. Also, within the loop you would generate a Bernoulli random variable, say `b = rand

    – Luis Mendo Mar 24 '17 at 00:19
  • @LuisMendo I have done exactly that for part 2 of the question, it is part 1 I am trying to figure out. – KOB Mar 24 '17 at 00:24

0 Answers0