%%  GREAT Trial
% Exercise 10.8
% Pocock and Spiegelhalter (1992) examine the effect of anistreplase on recovery
% from myocardial infraction. A total of 311 patients were randomized in 
% two arms Anistreplase and Placebo (conventional treatment). The number of 
% deaths (during 3 months following an acute MI) in each arm is given in the
% table below
%                             Death       No death      Total
%   Anistreplase              13          150           163 
%   Placebo                   24          124           148  
%   Total                     37          274           311 
%  
% (a) Find 95% confidence intervals for the risk difference,
% risk ratio, and odds ratio. You can use file  risk.m.
% 
% (b) Using confidence intervals from (a), argue that the 
% Ansitreplase treatment significantly lowers 3-month mortality. No test
% is necessary.
% 
addpath('C:\STAT\Two\Twomat\')   %make sure risk.m is on path
[rd rdl rdu rr rrl rru or orl oru] = risk([13, 150; 24, 124])

%Solution  (a)
% rd =-0.0824
% rdl =-0.1549
% rdu = -0.0099
% CI for rd [-0.1549, 0.0099]
% 
% rr = 0.4918
% rrl = 0.2601
% rru =0.9301
% CI for rr =[0.2601, 0.9301]
% 
% or =0.4478
% orl =0.2189
% oru =0.9159
% CI for or [0.2189, 0.9159]
%
%  (b) CI for rd does not contain 0, CIs for rr and or do not contain 1 ->
%  the treatment significantly lowers the risk of death.
% 
%% ADD ON: A confidence interval and a test
% 
% Find
% (c) 95% CI for the population proportion of deaths 
% under Placebo treatment in the problem   GREAT Trial. 
% (d) p-value in testing that population proportion for Placebo treatment 
% from problem   GREAT Trial  is 0.2 against the alternative that it is less
% than 0.2, that is,  H0: p = 0.2  vs.  H1: p < 0.2.
% 
% For full credit write down the formulas and 
% MATLAB code for the interval and test.

%(c) 
n=148;
phat = 24/148 %0.1622
sqrt(phat * (1-phat)/148) %0.0303
[phat - norminv(0.975)*sqrt(phat * (1-phat)/n), ...
 phat + norminv(0.975)*sqrt(phat * (1-phat)/n)]
%[0.1028, 0.2215]

% (d) 
z = (phat - 0.2)/sqrt(0.2*0.8/n)  %-1.1508
pval = normcdf(z)  %0.1249  
% Since p-value is > 0.05, H0: p=0.2 is not rejected


