rmixnorm: Random variables from normal mixture

Description Usage Arguments Details Value Author(s) References Examples

View source: R/dgp__rmixmorm.R

Description

Generate random variables from univariate and multivariate mixture normal distribution

Usage

1
rmixnorm(n, means, sigmas, weights)

Arguments

n

An positive integer. Numbers of samples to be generated.

means

A 'q-by-k' matrix. Mean value vector within each component in total k components.

sigmas

A 'q-by-q-by-k' array. Variance covariance matrix with in each component.

weights

A 'k'-length vector. The weight in each component.

Details

Random variables from mixture of normals.

Value

An 'n-by-q' matrix

Author(s)

Feng Li, Central University of Finance and Economics.

References

Villani et al 2009

Examples

1
2
3
4
5
6
7
require("mvtnorm")
n <- 1000
means <- matrix(c(-5, 0, 5), 1)
sigmas <- array(c(1, 1, 1), c(1, 1, 3))
weights <- c(0.3, 0.4, 0.3)
out <- rmixnorm(n, means, sigmas, weights)
hist(out, breaks = 100, freq = FALSE)

feng-li/flutils documentation built on Oct. 1, 2020, 9:09 p.m.