Generate random samples from normal mixture

rnormix(n, lambda, mu, sigma, method = c("standard", "montecarlo", "fix"))

Arguments

n

`numeric(1)` - number of samples

lambda

`numeric` - Vector of mixing proportions of each normal component

mu

`numeric` - Vector of means of each normal component

sigma

`numeric` - Vector of standard deviations of each normal component

method

"standard" behaves like [rnorm]. "montecarlo" is more efficient and recommended for Monte Carlo computation based on mixture samples; the samples are ordered based on each component. "fixed" will use expected number of samples in each component and produce a `data.frame`.

Value

`numeric` if "standard" or "montecarlo"; `data.frame` if "fixed"

Examples

set.seed(42)
rnormix(10, c(0.5, 0.5), c(-10, 10), c(1, 1), "standard")
#>  [1]  -9.952115   8.812359  -8.469323  10.151813 -11.104599  -9.460976
#>  [7] -10.657503  11.554896  -9.419794  -9.044064
rnormix(10, c(0.5, 0.5), c(-10, 10), c(1, 1), "montecarlo")
#>  [1] -10.284253 -12.656455 -12.440467  -8.679887 -10.306639 -11.781308
#>  [7]   9.828083  11.214675  11.895193   9.569531
rnormix(10, c(0.5, 0.5), c(-10, 10), c(1, 1), "fix")
#>             x y
#> 1   -9.211859 0
#> 2   -9.329296 0
#> 3  -10.949181 0
#> 4   -9.963864 0
#> 5   -7.884244 0
#> 6   10.167441 1
#> 7    9.120163 1
#> 8   10.946913 1
#> 9    9.295449 1
#> 10   8.921831 1