Reputation: 11
I am asked to Write a code to generate a geometric RV with p=0.25 and use it to calculate the probability that the RV takes a value greater than or equal to 4. Basically, I am not aware of matlab but I tried using help in matlab. And I came to know that I should use geornd function. Can anyone help me how to use the function and how I should enter the parameters to get the required results?
Upvotes: 1
Views: 1684
Reputation: 112659
See the doc for this function: http://www.mathworks.es/es/help/stats/geornd.html.
For example, if you want a 1x10000 vector of geometric samples with parameter p=0.25, use
values = geornd(.25,1,10000);
To estimate the probability that the RV exceeds or equals 4:
mean(values>=4)
Explanation: values>=4
is a vector which contains 1 or 0 according to whether the condition is fulfilled or not. Its sample mean (function mean
) is an estimation of the probability of that event.
Anyway, in this case it would be easier to compute that probability exactly:
>> p = .25; N = 4; 1 - p*sum((1-p).^[0:N-1])
ans =
0.3164
or using geocdf
:
p = .25; N = 4; 1-geocdf(N-1,p)
Upvotes: 2