Chapter 2: plotting sampling surfaces
Chapter 2: plotting sampling surfaces
It will be useful to gain some experience with creating sampling surfaces such as those shown in Figs. 2.5 and 2.6. These figures are produced by the BuildLikelihoodBin.m and the BuildLikelihoodNBin.m functions. To use these functions, we simply need to provide the observed data and null hypothesis. The help file tells us that the outputs are the likelihood function (‘lx’), the sampling distribution (‘px’) and the pvalue (‘pval’).
To generate Figs. 2.5 and 2.6 the observed data are N=34 and S=12. Thus we write:
N=34; S=12; H0=.5;
[lx px pval]=BuildLikelihoodBin(S,N,H0); pval
[lx px pval]=BuildLikelihoodNBin(S,N,H0); pval
The two p-val outputs should match those shown on the figures. You can manually generate the likelihood and sampling probabilities with the commands:
figure; plot(lx(:,2),lx(:,1),'k.')
figure; plot(px(:,2),px(:,1),'.')
We can also verify that the p-values are correct by first generating the 3 plots:
[lx px pval]=BuildLikelihoodBin(S,N,H0); pval
and comparing the sum:
sum(px(px(:,2)<=S),1)
and similarly for the negative binomial:
[lx px pval]=BuildLikelihoodBin(S,N,H0); pval
and comparing the sum:
sum(px(px(:,2)<=S),1)
Use these functions to find an even more egregious example of the optional stopping problem involving 11 successes, by trying values of N in the two programs (N>S):
S=11; H0=.5;
for N=S:3*S,
[lx px pvalBin]=BuildLikelihoodBin(S,N,H0);
[lx px pvalNBin]=BuildLikelihoodNBin(S,N,H0);
[N pvalBin pvalNBin], end
Finally, you should examine the code in the BuildLikelihood... functions to familiarize yourself with the plotting functions and the computations that were made to generate those figures.