function [se sp pre ppv npv lrp ag yi]   =  sesp(tp, fp, fn, tn)
 %
 %INPUT: 2x2 Contingency (Confusion) Table
 %    tp-true positives;  fp-false positives;
 %    fn-false negatives; tn-true negatives
 % OUTPUT
 %    se-sensitivity, sp-specificity, pre-prevalence(for random sample)
 %    ppv-positive predictive value, npv-negative predictive value,
 %    lrp - likelihood ratio positive, ag-agreement
 %    EXAMPLE OF USE:
 %    D-dimer as a test for acute PE (Goldhaber et al, 1993)
 %    [s1, s2, p1, p2, p3, lr, a, yi]=sesp(42,96,3,32);
 %
n = tp+tn+fn+fp;      %total sample size
np = tp + fp;         %total positive
nn = tn + fn;         %total negative
nd = tp + fn;         %total with disease
nc = tn + fp;         %total control (without disease)
se = tp/nd;           %tp/(tp + fn);:::::sensitivity
sp = tn/nc;           %tn/(tn + fp);:::::specificity
pre = nd/n;           %(tp + fn)/(tp+tn+fn+fp);::prevalence
   %only in case when sample is random from the population
   %of interest. Otherwise, prevalence needed for 
   %calculating PPV and NPV is input variable.
ppv = tp/np;       %tp/(tp + fp);:::positive predictive value
npv = tn/nn;       %tn/(tn + fn);:::negative predictive value
lrp = se/(1-sp);   %:::likelihood ratio positive
lrn = (1-se)/sp;   %:::likelihood ratio negative
ag = (tp+tn)/n;    %:::concordance,agreement
yi = (se + sp - 1)/sqrt(2); %:::youden index
%---------------  
disp('     Se        Sp        Pre       PPV       NPV       LRP        Ag         Yi   ')
disp([se, sp, pre, ppv, npv, lrp, ag, yi])