| realize | R Documentation |
realize draws n samples from a distribution and wraps
them in an empirical_dist.
This is the universal fallback that lets any dist object be
converted to a discrete approximation on which methods like
cdf, density, and conditional
are always available.
realize(x, n = 10000, ...)
## S3 method for class 'dist'
realize(x, n = 10000, ...)
## S3 method for class 'empirical_dist'
realize(x, ...)
## S3 method for class 'realized_dist'
realize(x, n = 10000, ...)
x |
A distribution object (inheriting from |
n |
Number of samples (default: 10000). |
... |
Additional arguments passed to methods. |
For non-empirical distributions, the result is a
realized_dist that preserves the source distribution
as provenance metadata. This enables re-sampling via
realize(x$source, n = ...) and informative printing.
The empirical_dist method is a no-op: the distribution is
already materialized.
The realized_dist method re-samples from the original source
distribution, allowing cheap regeneration with a different sample size.
An empirical_dist (or realized_dist)
object.
set.seed(1)
x <- normal(0, 1)
rd <- realize(x, n = 1000)
mean(rd)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.