| Library: | distribs |
| See also: | normalmixselect normalmixdens normal |
| Quantlet: | normalmix | |
| Description: | generates normal mixture pseudo-variates |
| Usage: | x = normalmix(n,w,mu,sigma) | |
| Input: | ||
| n | scalar, length of vector x, number of variates generated | |
| w | p x 1 vector, weights of the mixture components | |
| mu | p x 1 vector, means of the mixture components | |
| sigma | p x 1 vector, standard deviations of the mixture components | |
| Output: | ||
| x | n x 1 vector, normal mixture variates | |
- components with w <= 0 are ignored;
- negative standard deviations are not accepted
library("distribs")
library("plot")
library("smoother")
n=1000
w=#(1,2,3)
mu=#(0,5,10)
sig=#(1,1.2,1.4)
x=normalmix(n,w,mu, sig)
fhx=denxest(x)
p1=setmask(fhx,"line")
plot(p1)
1000 pseudo-variates are created. then the density is estimated using a kernel estimate, and the result (a mixture of three normal distributions) is plotted.