% LMex040307_4th.m
% Example 4.3.7 Mensa & IQ Pages 309-310 in
% Larsen & Marx (2006) Introduction to Mathematical Statistics, 4th edition
% Based on LMex040306_4th.m
% Written Fall 2010 by Eugene Gallagher for EEOS601 Revised: 1/9/11
% Eugene.Gallagher@umb.edu 
% http://alpha.es.umb.edu/faculty/edg/files/edgwebp.html
% A person must be in the upper 2% of the population in IQ to join. What is
% the minimum IQ that will qualify a person for membership. Assume that the
% mean IQ is 100 and sigma is 16.
mu=100;
sigma=16; 
% Use the inverse of the normal pdf to find the IQ cutoff for the upper 2%
% of the population 0.98=(1-0.02)
IQmensa=norminv(0.98,100,16);
fprintf('\nThe lowest acceptable IQ for membership in Mensa is ')
fprintf('%3.0f.\n',ceil(IQmensa))

% Plot Figure 4.3.6
X=50:150;
Y = normpdf(X,mu,sigma);
plot(X,Y,'--r');
axis([45 155 0 0.03]);title('Figure 4.3.6: Mensa & IQ','FontSize',20);
ax1=gca;
xlabel('IQ','FontSize',16),
ylabel('f_y(y)','FontSize',16);
set(ax1,'xtick',[50 100 133 150],'FontSize',14);
set(ax1,'ytick',0:.01:0.03,'FontSize',14)
hold on;
xf=ceil(IQmensa):155;yf=normpdf(xf,mu,sigma);
fill([ceil(IQmensa) xf 155]',[0 yf 0]',[.8 .8 1])
text(50,0.007,'Area=0.98','FontSize',18);
text(135,0.007,'Area=0.02','FontSize',18)
figure(gcf);pause
hold off;