View source: R/simulation.R View source: R/original/Additional file 2.R
rmix | R Documentation |
Generates a random sample by mixing two distributions.
rmix(n, p, rdist1, rdist2)
n |
Number of samples to draw. |
p |
Proportion of samples to draw from rdist1 vs rdist2 (true proportion taken as the fraction of random uniform values smaller than p). |
rdist1 |
User-defined function for generating random samples
(must take |
rdist2 |
User-defined function for generating random samples
(must take |
A vector of n
values sampled from rdist1
and
rdis2
.
rdist1 <- function(n) {rnorm(n, -1, 0.5)}
rdist2 <- function(n) {rnorm(n, 1, 0.5)}
out <- rmix(10000, 0.3, rdist1, rdist2)
print(summary(out))
hist(out, 20, xlim = c(-2, 2), probability = TRUE,
main = '', xlab = 'Random variable value')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.