Chapter 2: simulated sensitivity and specificity
We can simulate the sensitivity and specificity of the test at these 4 gestational latencies in the following way:
URNall=HIT+MISS+CR+FA; %size of urn containing all tests
URNhm=HIT+MISS; %urn containing all testees with disease
URNcf=CR+FA; %urn containing all testees without disease
HCR=[0 0]; PN=[0 0]; %simulated numbers of hits/CR and pos/neg results
REPS=40000;
for n=1:REPS,
PNind=1+(randi(URNall)>URNhm); PN(PNind)=PN(PNind)+1;
if PNind==1, HCR(1)=HCR(1)+(randi(URNhm)<=HIT);
else HCR(2)=HCR(2)+(randi(URNcf)<=CR); end, end
S=HCR./PN