trace tracker logo

Test evaluation against a gold standard

Use this to estimate test sensitivity, specificity and positive and negative likelihood ratios by comparison with a known reference (gold standard) test. Results are presented as estimates of sensitivity and specificity with specified Clopper-Pearson (exact) confidence limits and point estimates of positive and negative likelihood ratios.

No results

No example available
No references available
				#############################################################
# Program to evaluate a test by comparison with a gold standard
#############################################################


# check version and load header script
rm(list = ls())
test<- ifelse(length(commandArgs()) < 3, TRUE, FALSE)
fpath<- ifelse(test, "webRootUrl", "rtoolsPath")

# load header scripts
  source(paste(fpath, "R/epi_head.R", sep = ""))
  source(paste(fpath, "R/HTMLStream.R", sep = ""))
  source(paste(fpath, "R/epitools_functions.r", sep = ""))


# extract command arguments
    a1<- a0[8:13]

# a1<- a0[8:13]
# a1<- c()

# cat(a0)
# cat(a1)
digits<- 4

# initialise variables
test.name<- a1[1]
test.data<- type.convert(a1[2:5])
conf<- type.convert(a1[6])
lc<- (1 - conf)/2
uc<- 1 - lc
names(a1)<- c("Test Name", "Cell a (++)", "Cell b (-+)", "Cell c (+-)", "Cell d (--)", "Confidence level")

# table of inputs
inputs<- matrix(type.convert(a1[2:5]), nrow = 2, ncol = 2, byrow = T)
inputs<- addmargins(inputs)
colnames(inputs)<- paste("Gold Standard", c("+ve", "-ve", "Total"))
rownames(inputs)<- paste(a1[1], c("+ve", "-ve", "Total"))

n<- sum(test.data)
true.pos<- test.data[1] + test.data[3]
true.neg<- test.data[2] + test.data[4]
t.pos<- test.data[1] + test.data[2]
t.neg<- test.data[4] + test.data[3]

Sens<- test.data[1]/true.pos
Spec<- test.data[4]/true.neg
LRpos<- Sens/(1 - Spec)
LRneg<- (1 - Sens)/Spec
Sens[2]<- qbeta(lc, test.data[1], test.data[3] + 1)
Sens[3]<- qbeta(uc, test.data[1] + 1, test.data[3])
Spec[2]<- qbeta(lc, test.data[4], test.data[2] + 1)
Spec[3]<- qbeta(uc, test.data[4] + 1, test.data[2])

results<- array("", dim = c(4, 3))
rownames(results)<- c("Sensitivity", "Specificity",
        "Likelihood ratio +ve", "Likelihood ratio -ve")
colnames(results)<- c("Point Estimate", paste("Lower ", conf*100, "% CL", sep = ""), paste("Upper ", conf*100, "% CL", sep = ""))
results[1,]<- round(Sens, digits)
results[2,]<- round(Spec, digits)
results[3, 1]<- round(LRpos, digits)
results[4, 1]<- round(LRneg, digits)


# write to html and file
heading<- "Test evaluation against a gold standard"
subheadings<- ""
filename<- digest(Sys.time())
tmp.file<- paste(fpath, "tmp/", filename, sep = "")
result.txt<- ""
# cat(test)
output<- html.output(heading, subheadings, inputs, results = list(results), graphs = "", graph.headings = "", show.inputs = T, show.graphs = F, tmp.file, result.txt = result.txt) 
write.html(output, tmp.file)
cat(output)