Is sampling all distributions n times and then talking out i numbers from each sample, where i is probability of that distribution * n, wrong?
Suppose $$ 0.3\!\times\mathcal{N}(0,1)\; + \;0.5\!\times\mathcal{N}(10,1)\; + \;0.2\!\times\mathcal{N}(3,.1) $$ being my problem to sample 100 numbers. Should I take 100 or say 1000 samples each of the three normal distributions and then take 30, 50 and 20 respectively, randomly out of them?
Or going by another approach, Should I take 30, 50 and 20 random samples respectively, directly from the three distributions?
The correct algorithm seems to be:
- generate a number, say k according to the probabilities of all distributions which corresponds to a particular k-th one.
- generate a number from the above k-th distribution.
Repeat for N numbers. See it at sampling from a mixture of two Gamma distributions .
Are all these three approaches same?
fwiw, I am using python and I am not familiar with R. And the reason I am asking this question is this comment:
[..]The notation suggests that to sample, you need to sample all three normals and weigh the results by those coefficients which would obviously not be correct. [..]