Page 220 - Computational Statistics Handbook with MATLAB
P. 220

Chapter 6: Monte Carlo Methods for Inferential Statistics       207


                                                      H :     µ =  454
                                                        0
                                                      H 1 :   µ <  454.

                             We will perform our hypothesis test using simulation to get the critical val-
                             ues. We decide to use the following as our test statistic

                                                             x –  454
                                                         z =  ------------------  .
                                                             σ ⁄  n

                             First, we take care of some preliminaries.
                                % Load up the data.
                                load mcdata
                                n = length(mcdata);
                                % Population sigma is known.
                                sigma = 7.8;
                                sigxbar = sigma/sqrt(n);
                                % Get the observed value of the test statistic.
                                Tobs = (mean(mcdata)-454)/sigxbar;
                             The observed value of the test statistic is  t o =  – 2.56.   The next step is to
                             decide on a model for the population that generated our data. We suspect
                             that the normal distribution with σ =  7.8   is a good model, and we check this
                             assumption using a normal probability plot. The resulting plot in Figure 6.4
                             shows that we can use the normal distribution as the pseudo-population.
                                % This command generates the normal probability plot.
                                % It is a function in the MATLAB Statistics Toolbox.
                                normplot(mcdata)
                             We are now ready to implement the Monte Carlo simulation. We use 1000 tri-
                             als in this example. At each trial, we randomly sample from the distribution
                             of the test statistic under the null hypothesis (the normal distribution with
                             µ =  454   and σ =  7.8  ) and record the value of the test statistic.
                                M = 1000;% Number of Monte Carlo trials
                                % Storage for test statistics from the MC trials.
                                Tm = zeros(1,M);
                                % Start the simulation.
                                for i = 1:M
                                    % Generate a random sample under H_0
                                    % where n is the sample size.
                                    xs = sigma*randn(1,n) + 454;
                                    Tm(i) = (mean(xs) - 454)/sigxbar;
                                end






                             © 2002 by Chapman & Hall/CRC
   215   216   217   218   219   220   221   222   223   224   225