Learn R Programming

mixpack (version 0.3.6)

rmixnorm: Random sample generated from an specified gaussian mixture model.

Description

Random sample generated from an specified gaussian mixture model.

Usage

rmixnorm(n, Pi, Mu, S, labels = F)

Arguments

n
Sample size
Pi
A vector indicating the mixing proportions
Mu
A two dimensional array where second component indicates the mean of each gaussian component
S
A three dimensional array where third component indicates the variance of each gaussian component
labels
A logical indicating whether or not a label shoud be returned indicating the component from where observation has been generated (default FALSE)

Value

A matrix with n row and columns given by the dimension of Mu and S. If labels = T another column is included indicating the component from where the observation was generated.

Examples

Run this code
Pi = c(0.5, 0.3, 0.2)
Mu = array(c(## Mu first component
             5, 5,
             ## Mu second component
             1, 1,
             ## Mu third component
             0, 0), dim = c(2,3))
S = array(c(## Sigma first component
            1, 0,
            0, 1,
            ## Sigma second component
            0.2, 0,
            0, 0.2,
            ## Sigma third component
            0.05, 0,
            0, 0.05), dim = c(2, 2, 3))
X = rmixnorm(100, Pi = Pi, Mu = Mu, S = S, labels = TRUE)
plot(X[,1:2], col=X[,3])

Run the code above in your browser using DataLab