Learn R Programming

mclust (version 6.1.3)

simulate.Mclust: Simulate from Gaussian mixture models

Description

Generic method for simulating from Gaussian mixture models via base `simulate()` function.

Usage

# S3 method for Mclust
simulate(object, nsim = 1, seed = NULL, ...)
# S3 method for densityMclust
simulate(object, nsim = 1, seed = NULL, ...)

Value

For an input object of class `Mclust` returns a matrix in which the first column is the mixture component label and the remaining columns are the simulated data observations. For an input object of class `densityMclust` only the simulated data observations are returned.

Arguments

object

An object of either `Mclust` or `densityMclust` class.

nsim

An integer specifying the number of data points to be simulated.

seed

An optional integer argument to set.seed for reproducible random class assignment. By default the current seed will be used. Reproducibility can also be achieved by calling set.seed before calling sim.

...

Catches unused arguments in indirect or list calls via do.call.

See Also

simulate, sim, ..., Mclust, densityMclust

Examples

Run this code
mod <- Mclust(iris[,-5])
iris_sim <- simulate(mod, n = 1000)
str(iris_sim)
clPairs(iris_sim[,-1], iris_sim[,1])

x <- iris$Petal.Length
mod <- densityMclust(x, plot = FALSE)
x_sim <- simulate(mod, n = 1000)
str(x_sim)
hist(x_sim, breaks = 31, main = NULL, probability = TRUE)
rug(x_sim)
x0 = seq(0.5, 9, length = 101)
lines(x0, predict(mod, newdata = x0))

Run the code above in your browser using DataLab