Skip to contents

This function will generate n random points from a negative binomial distribution with a user provided, .size, .prob, and number of random simulations to be produced. The function returns a tibble with the simulation number column the x column which corresponds to the n randomly generated points, the d_, p_ and q_ data points as well.

The data is returned un-grouped.

The columns that are output are:

  • sim_number The current simulation number.

  • x The current value of n for the current simulation.

  • y The randomly generated data point.

  • dx The x value from the stats::density() function.

  • dy The y value from the stats::density() function.

  • p The values from the resulting p_ function of the distribution family.

  • q The values from the resulting q_ function of the distribution family.

Usage

tidy_negative_binomial(
  .n = 50,
  .size = 1,
  .prob = 0.1,
  .num_sims = 1,
  .return_tibble = TRUE
)

Arguments

.n

The number of randomly generated points you want.

.size

target for number of successful trials, or dispersion parameter (the shape parameter of the gamma mixing distribution). Must be strictly positive, need not be integer.

.prob

Probability of success on each trial where 0 < .prob <= 1.

.num_sims

The number of randomly generated simulations you want.

.return_tibble

A logical value indicating whether to return the result as a tibble. Default is TRUE.

Value

A tibble of randomly generated data.

Details

This function uses the underlying stats::rnbinom(), and its underlying p, d, and q functions. For more information please see stats::rnbinom()

Author

Steven P. Sanderson II, MPH

Examples

tidy_negative_binomial()
#> # A tibble: 50 × 7
#>    sim_number     x     y     dx       dy     p     q
#>    <fct>      <int> <int>  <dbl>    <dbl> <dbl> <dbl>
#>  1 1              1     2 -8.06  0.000221 0.271     2
#>  2 1              2     1 -6.55  0.00109  0.190     1
#>  3 1              3    11 -5.04  0.00404  0.718    11
#>  4 1              4     4 -3.52  0.0113   0.410     4
#>  5 1              5    16 -2.01  0.0243   0.833    16
#>  6 1              6     7 -0.499 0.0411   0.570     7
#>  7 1              7     0  1.01  0.0559   0.1       0
#>  8 1              8     2  2.53  0.0632   0.271     2
#>  9 1              9     0  4.04  0.0621   0.1       0
#> 10 1             10     1  5.55  0.0566   0.190     1
#> # ℹ 40 more rows