Page 320 - Computational Statistics Handbook with MATLAB
P. 320

Chapter 8: Probability Density Estimation                       309


                                2. First determine the component membership of each of the n random
                                   variables. We do this by generating n uniform (0,1) random vari-
                                           ). Component membership is determined as follows
                                   ables (U i
                                      If  0 ≤ U i <  p 1  , then  X i   is from component density 1.

                                      If  p 1 ≤  U <  p 1 +  p 2  , then  X i   is from component density 2.
                                              i
                                      . . .
                                        c –  1
                                      If  ∑ p j ≤  U ≤  1  , then  X i   is from component density c.
                                                i
                                        j =  1
                                                 from the corresponding  g i x;θ i )   using the compo-
                                                                        (
                                3. Generate the X i
                                   nent membership found in step 2.
                             Note that with this procedure, one could generate random variables from a
                             mixture of any component densities. For instance, the model could be a mix-
                             ture of exponentials, betas, etc.



                             Example 8.13
                             Generate a random sample of size n from a finite mixture estimate of the Old
                             Faithful Geyser data (geyser). First we have to load up the data and build a
                             finite mixture model.
                                load geyser
                                % Expects rows to be observations.
                                data = geyser';
                                % Get the finite mixture.
                                % Use a two term model.
                                % Set initial model to means at 50 and 80.
                                muin = [50, 80];
                                % Set mixing coefficients equal.
                                piesin = [0.5, 0.5];
                                % Set initial variances to 1.
                                varin = [1, 1];
                                max_it = 100;
                                tol = 0.001;
                                % Call the finite mixtures.
                                [pies,mus,vars]=...
                                    csfinmix(data,muin,varin,piesin,max_it,tol);
                             Now generate some random variables according to this estimated model.
                                % Now generate some random variables from this model.
                                % Get the true model to generate data from this.
                                n = 300;
                                x = zeros(n,1);


                            © 2002 by Chapman & Hall/CRC
   315   316   317   318   319   320   321   322   323   324   325