% Proportion of Hemorrhagic-type Strokes Among American Indians. 
% 
% The study described in the American Heart Association news release of September 22, 2008
% included 4,507 members of 13 American Indian tribes in Arizona, Oklahoma, 
% and North and South Dakota.
% It found that American Indians have a stroke rate of 679 per 100,000, compared 
% to 607 per 100,000 for African Americans and 306 per 100,000 for Caucasians.
% None of the participants, ages 45 to 74, had a history of stroke when they were recruited
% for the study from 1989 to 1992. Almost 60% of the volunteers were women.
% 
% During more than 13 years of follow-up, 306 participants suffered a first stroke, 
% most of them  in their mid-60s when it occurred.
% There were 263 strokes of the ischemic type -- caused by a blockage that cuts
% off the blood supply to the brain -- and 43 hemorrhagic (bleeding) strokes.
% 
% It is believed that in the general population one in five of all strokes is hemorrhagic.
% 
% (a) Test the hypothesis that the proportion of hemorrhagic strokes in the
% population of American Indians that suffered a stroke is lower than the
% national proportion of 0.2. Use alpha = 0.05.
% 
% 
% (b) What is the power of the test in (a) against the alternative 
% H_1: p = 0.15?
% 
% (c) What sample size ensures power of 90%
% in detecting p=0.15 in a test of level alpha=0.05, if H_0 states
% p = 0.2.

%(a)
  phat = 43/306  ; %0.1405
 z = (43/306 - 0.2)/sqrt(0.2 *(1- 0.2)/306)    %-2.6011 
 pval = normcdf(z)   %0.0046

 %Exact p-value
 pval = binocdf(43, 306, 0.2)  %0.0044
 
 
% (b)
p0=0.2; p1=0.15; alpha=0.05; n=306;
 power = normcdf( sqrt(p0*(1-p0)/(p1*(1-p1))) * ...
     (norminv(alpha) + abs(p1-p0)*sqrt(n)/sqrt( p0*(1-p0)) ) )
 %0.728
%(c)

beta =  0.1; 
n = p0*(1-p0) * (norminv(1-alpha) + norminv(1-beta)*...
          sqrt( p1*(1-p1)/( p0 * (1-p0))))^2/(p0 - p1)^2
% 497.7779   approx 498   