Skip to main content
2 of 4
added 197 characters in body
Glen_b
  • 290.5k
  • 37
  • 652
  • 1.1k

[The underlying issue here is not to do with R, but with the geometric distribution itself (so you could quite reasonably drop "in R" from your title; R simply revealed the problem to you).]

Note that there are two ways of writing the geometric distribution; one as the number of failures to the first success, and the other as the number of trials to the first success.

(Wikipedia gives both forms).

It's important to make sure you're dealing with the right one!

You can see that the first code you gave produces a minimum value of 1, so it's of the "number of trials" form. R's geometric random number function produces a minimum value of 0, which is of the "number of failures" form.

To convert from the "number of failures" form to the "number of trials" form, you simply add 1.

An identical issue occurs more generally with the negative binomial distribution -- again you have to be careful to use the right one.

Glen_b
  • 290.5k
  • 37
  • 652
  • 1.1k