Description Usage Arguments Details Value References See Also Examples
Generates random values from a univariate and multivariate continuous distribution by using kernel density estimation based on a sample. The function uses the Accept-Reject method.
1 2 3 4 5 6 7 8 9 |
x |
a numeric vector, matrix or data frame; data. |
n |
integer; the number of random values will be generated. |
distr |
character; instrumental or candidate distribution name. See details. |
const.only |
logical; if |
seed |
a single value, interpreted as an integer, or |
parallel |
logical; if |
... |
other parameters for functions |
Such function uses the function kde
as kernel density estimator.
The Accept-Reject method is used to simulate random variables.
Following code named distributions can be used as a value of the argument distr
and an instrumental or candidate distribution of the simulation method.
For univariate distributions:
normal distribution (default), (-∞,+∞)
Cauchy distribution, (-∞,+∞)
log-normal distribution, (0,+∞)
exponential distribution, (0,+∞)
gamma distribution, (0,+∞)
Weibull distribution, (0,+∞)
uniform distribution, (a,b)
And you can choose the best fitting instrumental distribution to simulate random variables more effectively by using find_best_fit
. See examples.
For multivariate distributions, "norm" (multivariate normal distribution) is used.
list of given data, simulated values, kernel density estimation and the constant of the Accept-Reject method when const.only
is FALSE
(default).
Tarn Duong (2018). ks: Kernel Smoothing. R package version 1.11.2. https://CRAN.R-project.org/package=ks
Christian P. Robert and George Casella (2010) Introducing Monte Carlo Methods with R. Springer. Pages 51-57.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ## 1-dimensional data
data(faithful)
hist(faithful$eruptions)
res <- simukde::simulate_kde(x = faithful$eruptions, n = 100, parallel = FALSE)
hist(res$random.values)
## Simulation with the best fitting instrumental distribution
data(faithful)
par(mfrow = c(1, 3))
hist(faithful$eruptions)
fit <- simukde::find_best_fit(x = faithful$eruptions, positive = TRUE)
res <- simukde::simulate_kde(
x = faithful$eruptions, n = 100,
distr = fit$distribution, parallel = FALSE
)
hist(res$random.values)
par(mfrow = c(1, 1))
## 2-dimensional data
data(faithful)
res <- simukde::simulate_kde(x = faithful, n = 100)
plot(res$kde, display = "filled.contour")
points(x = res$random.values, cex = 0.25, pch = 16, col = "green")
points(x = faithful, cex = 0.25, pch = 16, col = "black")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.