[R] Simulate Mixture Model data

Martin Maechler maechler at stat.math.ethz.ch
Tue Mar 21 09:57:51 CET 2006

>>>>> "Goeland" == Goeland  <goeland at gmail.com>
>>>>>     on Tue, 21 Mar 2006 00:21:12 -0500 writes:

    Goeland> Dear R Users$A#,(BI woould like to generate mixture
    Goeland> model data.

Look at package "nor1mix"  which deals with univariate (aka
'one-dimensional') mixtures of normals ("Gaussians").

    Goeland> I try two type method as followings two method, can
    Goeland> anyone tell me which is right? or better?

    Goeland> 1. generate two vectors data y1 and y2 from f1 and
    Goeland> f2 seperately, and calculate y=alpha1*y1+alpha2*y2,
that's clearly wrong.

    Goeland> 2. generate prob=unif(1), if prob <alpha1 y=y1,
    Goeland> else y=y2.

    Goeland> Can anyone give me some idea?

Look at the short function   rnorMix()  in the package nor1mix.

It shows you how to implement a generalization of your version
"2" efficiently.

    Goeland> Thanks so much!

    Goeland> Goeland goeland at gmail.com 2006-03-21

Hmm, I hope I haven't just helped a student do his homework.
(Now I think I did...)
I'm still very reluctant to help anonymous people, and consider
this one as a big exception..

Martin Maechler, ETH Zurich

More information about the R-help mailing list