Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Re: Generating a sample from a two-Gaussian mixture


From   Ali Hashemi <hashemi@vt.edu>
To   Stata listserv <statalist@hsphsun2.harvard.edu>
Subject   st: Re: Generating a sample from a two-Gaussian mixture
Date   Fri, 1 Mar 2013 15:35:22 -0500

Sorry, I just noticed a typo in the code. Here is the correct code:

drawnorm x1 y1, n(1000) means(3,-1) sds(.2,.4) corr(1, -.1 \ -.1, 1)
drawnorm x2 y2, n(1000) means(-1,1) sds(.3,.3) corr(1, .1 \ .1, 1)
g p=uniform()<.4
g x=p*x1+(1-p)*x2
g y=p*y1+(1-p)*y2

Thanks
a.

On Fri, Mar 1, 2013 at 2:36 PM, Ali Hashemi <hashemi@vt.edu> wrote:
> Dear Statalist,
>
> I'm trying to generate a sample from the following mixture of two
> normal distributions:
>
> 0.4*N ([3,-1];sigma=061) + 0.6*N ([-1,1];sigma=062)
> where
> sigma1=3D[0.2  -0.1 ; -0.1  0.4]
> sigma2=3D[0.3   0.1 ;  0.1  0.3]
>
>
> Here is my code:
> drawnorm x1 y1, n(1000) means(3,-1) sds(.2,.4) corr(1, -.1 \ -.1, 1)
> drawnorm x2 y2, n(1000) means(-1,1) sds(.3,.3) corr(1, .1 \ .1, 1)
> g p=3Duniform()<.4
> g x=3Dp*x1+(1-p)*x2
> g y=3Dp*y1+(1-p)*y2
>
> I'm not sure whether this is the right way to do it. Is there a better
> method for generating this sample? I would appreciate your help.
>
> Thanks
> Ali Hashemi
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index