# Probability of infection in a test-negative sample

Use this to calculate the probability that a sample of test-negative units will include one or more infected individuals, given that they come from a population infected at a given design prevalence and the specified test and specificity. Also calculated is the probability that all units in the sample will test negatively. Results are calculated for the specified design prevalence as well as for a range of prevalence values.

No results

Ex

No references available

###################################### # Program to calculate Probability of infection in a group of test-negative animals ###################################### # 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<- type.convert(a0[8:11]) # cat(a0) # cat(a1) digits<- 4 Prevalence<- a1[1] Se<- a1[2] Sp<- a1[3] results.labels<- c("Sample size", "Probability of infection", "Probability all test negative") s.sizes<- 14 # number of sample sizes excluding user input # table of inputs inputs<- array("", dim = c(length(a1), 1)) inputs[1:length(a1), 1]<- a1[1:length(a1)] rownames(inputs)<- c("Prevalence", "Sensitivity", "Specificity", "Sample Size") filename<- digest(Sys.time) graphfile<- paste(fpath, "tmp/", filename, ".png", sep="") sinkfile<- paste(fpath, "tmp/", filename, ".txt", sep="") results<- array(0, dim = c(s.sizes + 1, 3)) colnames(results)<- c(results.labels[1], results.labels[2], results.labels[3]) results[,1]<- c(1, 5, 10, 15, 20, 25, 30, 40, 50, 60, 80, 100, 200, 300, a1[4]) results[,2]<- 1 - (((1 - Prevalence)*Sp)/((1 - Prevalence)*Sp + Prevalence*(1 - Se)))^results[,1] results[,3]<- (1 - (Prevalence*Se + (1 - Prevalence)*(1 - Sp)))^results[,1] results<- round(results, digits) #tmp<- format(results[,3], scientific = F) results1<- c(a1, results[s.sizes+1, 2], results[s.sizes+1, 3]) results1[6]<- format(results1[6], scientific = F) dim(results1)<- c(length(results1), 1) colnames(results1)<- "Value" rownames(results1)<- c(rownames(inputs), results.labels[2], results.labels[3]) # graph results sink(sinkfile) Title<-c("Probability of infection in a test-negative sample") OpenGraphOutput(graphfile, pointsize = 12, ht = 6, wd = 8) plot(x = results[1:s.sizes,1], y = results[1:s.sizes,2], type="l", xlab = results.labels[1], ylim = c(0, 1), xlim = c(0, max(results[1:s.sizes,1])), ylab="Probability", main=Title, col="darkblue") lines(results[1:s.sizes,1], results[1:s.sizes,3], type="l", col="red") legend(max(results[1:s.sizes,1]), 1, c(results.labels[2], results.labels[3]), xjust = 1, col=c("darkblue", "red"), lty = c(1, 1), plot = TRUE, cex = 0.7) CloseGraphOutput("B") sink() # write to html and file heading<- "Probability of infection in a test-negative sample" subheadings<- c("For specified sample size", "For a range of sample sizes") tmp.file<- paste(fpath, "tmp/", filename, sep = "") result.txt<- paste("The table and graph below summarise the probability of undetected infection in a test-negative sample and the probability that the sample will test negatively for various sample sizes from a population with a prevalence of

", sep = "") output<- html.output(heading, subheadings, inputs, results = list(t(t(results1)), results[1:s.sizes,]), graphs = graphfile, graph.headings = "Probability of infection in a test-negative sample", show.inputs = T, show.graphs = T, tmp.file, result.txt = result.txt) write.html(output, tmp.file) cat(output)", Prevalence, "and test sensitivity =", Se, "and specificity =", Sp, ".