%
%data = [19 2 1 532];
n11=19; n12 = 2; n21=1; n22=532;
%
n1d = n11+ n12;
n2d = n21 + n22;
nd1 = n11 + n21; 
nd2 = n12 + n22;
n = n11+n12+n21+n22;
%----------
p0 = (n11 + n22)/n;
pci = (n1d*nd1 + n2d * nd2)/n^2;
preva = 2 * ( n11 + n12 + n21)/(2 * n);
qre = 1 - preva;
%------------
kappa = 2 * (n11 * n22 - n12 * n21)/(n1d*nd2 + nd1*n2d);
kappamle = (4 * (n11*n22 - n12*n21) - (n12 -n21)^2) / ( ...
(2 * n11 + n12 + n21) * (2 * n22 + n12 + n21));
%-------
%BK
varbk = (1-kappa)/n * ( (1-kappa)*(1-2*kappa) + ...
    (kappa * (2 - kappa)/(2 * preva * qre)));
vargarner = 4/( (1-pci)^2 * n^2 * (1/(n11+1) + 1/(n12+1) + ...
    1/(n21+1) + 1/(n22 + 1) ) );

%ci
kappa
kappamle
lbkappabk = kappa - 1.96 * sqrt(varbk)
lbkappagar = kappa - 1.96 * sqrt(vargarner)
w95bk = 2*1.96 * sqrt(varbk)
w95gar = 2*1.96 * sqrt(vargarner)

