Simulate a two-component mixture model following the probability density function (pdf) l such that l = p*f + (1-p)*g, with f and g the mixture component distributions, and p the mixing weight.
Arguments
- n
Number of observations to be simulated.
- weight
Weight of the first component distribution (distribution f) in the mixture.
- comp.dist
A list of two elements corresponding to the component distributions (specified with R native names) involved in the mixture model. These elements respectively refer to the two component distributions f and g.
- comp.param
A list of two elements corresponding to the parameters of the component distributions, each element being a list itself. The names used in each list must correspond to the native R argument names for these distributions. These elements respectively refer to the parameters of f and g distributions of the mixture model.
Value
An object of class twoComp_mixt, containing eight attributes: 1) the number of simulated observations, 2) the simulated mixture data, 3) the support of the distributions, 4) the name of the component distributions, 5) the name of the parameters of the component distributions and their values, 6) the mixing proportion, 7) the observations coming from the first component, 8) the observations coming from the second component.
Author
Xavier Milhaud xavier.milhaud.research@gmail.com
Examples
## Mixture of continuous random variables:
sim.X <- twoComp_mixt(n = 2000, weight = 0.5,
comp.dist = list("norm", "norm"),
comp.param = list(list("mean"=3, "sd"=0.5),
list("mean"=0, "sd"=1)))
sim.Y <- twoComp_mixt(n = 1200, weight = 0.7,
comp.dist = list("norm", "exp"),
comp.param = list(list("mean"=-3, "sd"=0.5),
list("rate"=1)))
print(sim.X)
#>
#> Call:twoComp_mixt(n = 2000, weight = 0.5, comp.dist = list("norm",
#> "norm"), comp.param = list(list(mean = 3, sd = 0.5), list(mean = 0,
#> sd = 1)))
#>
#> Component distributions: norm norm
#> Support of the component distributions: Continuous Continuous
#>
#> Value of the component parameters:
#> mean sd mean sd
#> 3.0 0.5 0.0 1.0
#>
#> Mixing proportion: 0.5
#>
#> Number of observations: 2000
#>
#> Simulated data (first 10 obs.):
#> 2.93475 2.692277 0.6343698 3.718913 0.9463694 3.622782 2.175062 2.664207 -0.4500302 1.158445
#>
#> Simulated observations coming from the 1st component (first 10 obs.):
#> 2.93475 2.692277 3.718913 3.622782 2.175062 2.664207 3.03669 2.584259 3.011138 3.701056
#>
#> Simulated observations coming from the 2nd component (first 10 obs.):
#> 0.6343698 0.9463694 -0.4500302 1.158445 -0.09883099 0.4869106 -0.320834 0.2575842 0.1839459 -0.24402
#>
plot(sim.X, xlim=c(-5,5), ylim=c(0,0.5))
plot(sim.Y, add.plot = TRUE, xlim=c(-5,5), ylim=c(0,0.5), col = "red")
## Mixture of discrete random variables:
sim.X <- twoComp_mixt(n = 2000, weight = 0.5,
comp.dist = list("multinom", "multinom"),
comp.param = list(list("size"=1, "prob"=c(0.3,0.4,0.3)),
list("size"=1, "prob"=c(0.1,0.2,0.7))))
print(sim.X)
#>
#> Call:twoComp_mixt(n = 2000, weight = 0.5, comp.dist = list("multinom",
#> "multinom"), comp.param = list(list(size = 1, prob = c(0.3,
#> 0.4, 0.3)), list(size = 1, prob = c(0.1, 0.2, 0.7))))
#>
#> Component distributions: multinom multinom
#> Support of the component distributions: Discrete Discrete
#>
#> Value of the component parameters:
#> size prob1 prob2 prob3 size prob1 prob2 prob3
#> 1.0 0.3 0.4 0.3 1.0 0.1 0.2 0.7
#>
#> Mixing proportion: 0.5
#>
#> Number of observations: 2000
#>
#> Obtained multinomial mixture distribution:
#> 401 599 1000
#>
plot(sim.X)