  disp('From Exercises Chapter 1 and Chapter Corr')
  lw = 2; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;
% end of preabmle--------------------------------------
  disp('Medical Errors and Coke Vending Machine')
   %
errors= [ 2,  3, 10,  9,  5,  7,  8,  4]';
coke =[112,  100,  220, 250, 100, 200, 160, 100]';
people = [10000, 6000, 17000, 20000, 9000, 15000,...
             14000, 8000]';
 n=length(errors);
 rxy=corr(errors, coke)%0.8785
 txy = rxy* sqrt(n-2)/sqrt(1-rxy^2)  %4.5051
 p = 2 * tcdf(-abs(txy) , n-2)   %0.0041


%%
 corr(errors, people)
 %0.8821
 corr(coke, people)
 % 0.9735
 rxyz=(0.8785-0.8821*0.9735)/(sqrt(1-0.8821^2)*sqrt(1-0.9735^2))
 %   0.1836

 txyz = rxyz * sqrt(n-3)/sqrt(1-rxyz^2)  %0.4176
 p = 2 * tcdf(-abs(txyz) , n-3) % 0.6936

 