r_cdf {rando}R Documentation

Generate Random Numbers Based on an arbitrary CDF

Description

Generates Random Numbers based on a distribution defined by any arbitrary cumulative distribution function

Usage

r_cdf(
  Fun,
  min = -Inf,
  max = Inf,
  ...,
  data = NULL,
  n = default_n(..., data),
  .seed = NULL
)

Arguments

Fun

function to use as the cdf. See details

min, max

range values for the domain of the Fun

...

arguments that can be passed to Fun

data

data set containing arguments to be passed to Fun

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()

Details

The Fun argument accepts purrr style inputs. Must be vectorised, defined on the whole Real line and return a single numeric value between 0 and 1 for any input. The random variable will be passed to Fun as the first argument. This means that R's argument matching can be used with named arguments in ... if a different positional argument is wanted.

Value

A numeric vector of length n

Examples


set_n(5)

my_fun <- function(x, beta = 1) {
  1 - exp(-beta * x)
}

r_cdf(my_fun)


r_cdf(~ 1 - exp(-.x), min = 0)

r_cdf(~ 1 - exp(-.x * beta), beta = 1:10, min = 0)

[Package rando version 0.2.0 Index]