function [rd rdl rdu rr rrl rru or orl oru] = risk(a, b, c, d, alpha)
%
% Example of Use: Framingham Data. 
% The table below gives the coronary heart 
% disease status after 18 years, by level of
% systolic blood pressure (SBP). The levels 
% of SBP >=165  are considered as an
% exposure to a risk factor.
% SBP (mmHg) & Coronary disease & No coronary disease
%  >= 165    &  95              &  201    
%  < 165     &  173             &  894
%----------------
% > [rd rdl rdu rr rrl rru or orl oru] = risk(95, 201, 173, 894)

%
if nargin < 5 
    alpha=0.05
end
%--------
n1 = a + b;
n2 = c + d;
hatp1 = a/n1; hatp2 = c/n2;
%---------risk difference (rd) and CI [rdl, rdu] ----------
rd = hatp1 - hatp2;
stdrd = sqrt(hatp1 * (1-hatp1)/n1 + hatp2 * (1- hatp2)/n2 );
rdl = rd - norminv(1-alpha/2) * stdrd; 
rdu = rd + norminv(1-alpha/2) * stdrd;
%----------risk ratio (rr) and CI [rrl, rru] ---------
rr = hatp1/hatp2;
lrr = log(rr);
stdlrr = sqrt(b/(a * n1) + d/(c*n2));
lrrl = lrr - norminv(1-alpha/2)*stdlrr;
  rrl = exp(lrrl);
lrru =  lrr + norminv(1-alpha/2)*stdlrr;
  rru = exp(lrru);
%---------odds ratio (or) and CI [orl, oru] -----------
or = ( hatp1/(1-hatp1) )/(hatp2/(1-hatp2));
lor = log(or);
stdlor = sqrt(1/a + 1/b + 1/c + 1/d);
lorl = lor - norminv(1-alpha/2)*stdlor;
  orl = exp(lorl);
loru =  lor + norminv(1-alpha/2)*stdlor;
  oru = exp(loru);
%-------------------------------------
