Learn R Programming

SSLfmm (version 0.1.0)

rmix: Draw from a Gaussian Mixture Model

Description

Generate i.i.d. samples from a finite Gaussian mixture with either a shared covariance matrix or component-specific covariance matrices.

Usage

rmix(n, pi, mu, sigma, seed_number)

Value

A list with:

Y

Numeric matrix \(n \times p\) of generated features.

Z

Numeric matrix \(n \times g\) of one-hot component indicators.

clust

Integer vector \(n\), the component labels in 1:g.

Arguments

n

Integer. Number of observations to generate.

pi

Numeric vector of length \(g\). Mixing proportions (must sum to 1).

mu

Numeric matrix \(p \times g\). Column \(j\) is the mean for component \(j\).

sigma

Either a numeric matrix \(p \times p\) (shared covariance), or a numeric array \(p \times p \times g\) (component-specific covariances).

seed_number

Integer. Seed for reproducibility.

Examples

Run this code
  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