powered by
Generate i.i.d. samples from a finite Gaussian mixture with either a shared covariance matrix or component-specific covariance matrices.
rmix(n, pi, mu, sigma, seed_number)
A list with:
Numeric matrix \(n \times p\) of generated features.
Numeric matrix \(n \times g\) of one-hot component indicators.
Integer vector \(n\), the component labels in 1:g.
1:g
Integer. Number of observations to generate.
Numeric vector of length \(g\). Mixing proportions (must sum to 1).
Numeric matrix \(p \times g\). Column \(j\) is the mean for component \(j\).
Either a numeric matrix \(p \times p\) (shared covariance), or a numeric array \(p \times p \times g\) (component-specific covariances).
Integer. Seed for reproducibility.
set.seed(1) g <- 2; p <- 2 pi <- c(0.5, 0.5) mu <- cbind(c(1,0), c(-1,0)) Sigma <- diag(p) out <- rmix(500, pi, mu, Sigma, seed_number = 123) str(out)
Run the code above in your browser using DataLab