rnormmix: Generate Random Samples from a Normal Mixture Model

View source: R/rnormmix.R

rnormmixR Documentation

Generate Random Samples from a Normal Mixture Model

Description

Generate random samples from a normal mixture model.

Usage

   rnormmix(n, prop, mu, sigma)

Arguments

n

number of observations.

prop

a vector of proportions of different components.

mu

a vector of means of different components.

sigma

a vector of standard deviations of different components

Value

A matrix with each row corresponding to one sample. The first column are sample values from a normal mixture model; the second column are the components from which observations come.

Examples

  prop <- c(.17, .48, .35)
  mu <- c(-4, 0, 4)
  sigma <- rep(1, 3)
  y <- rnormmix(n=10000, prop, mu, sigma)
  hist(y[,1], breaks=50)

mritc documentation built on July 25, 2026, 9:06 a.m.