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]

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


From   Joerg Luedicke <joerg.luedicke@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: Generating a sample from a two-Gaussian mixture
Date   Fri, 1 Mar 2013 18:53:17 -0500

If I understand you correctly, you would like to generate two normal
mixture distributions with two components each, where the first
components (both with weight 0.4) of each of the two mixtures are
correlated with r = -0.1, and the two second components are correlated
with r = 0.1, right? Then this looks good to me. You can quickly check
it by typing:

bys p : sum x y // check M and SD of components
bys p : corr x y // check correlations

Joerg

On Fri, Mar 1, 2013 at 3:35 PM, Ali Hashemi <hashemi@vt.edu> wrote:
> 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/
*
*   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