draw_from_pdf | R Documentation |
draw_from_pdf
generates samples from a given probability density function
(PDF) using inverse transform sampling. This function takes in a numeric PDF
vector and a corresponding domain vector, then returns a specified number
of samples.
draw_from_pdf(a_pdf, x_def, k, seed = NULL)
a_pdf |
a numeric vector representing the PDF values. |
x_def |
a numeric vector defining the domain (or x-values) corresponding
to the values in |
k |
a single integer specifying the number of samples to generate. |
seed |
an optional single integer value used to set the seed for random number generation, allowing for reproducibility of results. |
This function implements inverse transform sampling by first constructing a
cumulative distribution function (CDF) from the given PDF. A uniform random
variable is then sampled for each of the k
samples, and the corresponding
value in x_def
is selected by locating the appropriate interval in the CDF.
A numeric vector of length k
containing the sampled values from
the specified PDF. If k
is 0, an empty numeric vector is returned.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.