rmix: Mix random samples

Description Usage Arguments Value Examples

View source: R/original/Additional file 2.R View source: R/simulation.R

Description

Generates a random sample by mixing two distributions.

Usage

1
rmix(n, p, rdist1, rdist2)

Arguments

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 n as only argument).

rdist2

User-defined function for generating random samples (must take n as only argument).

Value

A vector of n values sampled from rdist1 and rdis2.

Examples

1
2
3
4
5
6
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')

ssokolen/metcourse documentation built on May 30, 2019, 8:43 a.m.