rgeom function
The rgeom function generates a vector of geometric distributed random variables. In other words, we can say that this function generates a list of random values that represent the number of failures before the first success,
Syntax: rgeom(n, prob)
Parameters:
- n: number of values to generate
- prob: probability of success on a given trial
Example:
In this example, we are calculating the probability of a man asking for help, and the probability of getting the help is 0.5(p=0.5) so with the use of the rgeom() function we are simulating 15 scenarios for how many “failures” the person will experience until she finds someone who helps.
R
rgeom (n=15, prob=.5) |
Output:
[1] 0 0 0 3 1 0 1 1 0 3 0 6 1 0 1
A Guide to dgeom, pgeom, qgeom, and rgeom in R
In this article, we will be looking at a guide to the dgeom, pgeom, qgeom, and rgeom methods of the geometric distribution in the R programming language.