Generates a set of Negative Binomial distributed values. Only two of r, prob and mu can be provided.

r_nbinom(
  r = NULL,
  prob = 0.5,
  ...,
  mu = NULL,
  n = default_n(r, prob, mu),
  .seed = NULL
)

Arguments

r

number of failure trials until stopping, strictly positive

prob

vector of probabilities of success on each trial, between 0 & 1

...

Unused

mu

vector of means

n

number of observations to generate. The default_n() function will provide a default value within context

.seed

One of the following:

  • NULL (default) will not change the current seed. This is the usual case for generating random numbers.

  • A numeric value. This will be used to set the seed before generating the random numbers. This seed will be stored with the results.

  • TRUE. A random seed value will be generated and set as the seed before the results are generated. Again, this will be stored with the results.

To extract the random seed from a previously generated set of values, use pull_seed()

Value

A numeric vector of length n

Note

It is important to note that this is the number of failures, and not the number of successes, as in rnbinom(), so rnbinom(prob = x,...) is equivalent to r_nbinom(prob=1-x,...)

Examples

set_n(5) r_nbinom(10, 0.5)
#> [1] 8 4 11 10 14
r_nbinom(1:10, mu = 2)
#> [1] 4 0 1 0 0 3 2 2 2 1
#' r_nbinom(10, 0.2, n = 10)
#> [1] 1 2 1 4 2 1 3 2 1 4