Sample from a density object using rejection sampling

sampleDensity(n, dens, lower = 0)

Arguments

n

Number of values to sample

dens

Density object to sample from

lower

Lower x-axis bound on sampled values

Value

Vector of sampled values

Details

Random points (x and y) are generated inside the range of the density object. If they value is less than the density for that x value (and x is greater than lower) then that x value is retained. Ten thousand points are generated at a time until enough valid values have been sampled.