This R code allows the reproduction of the three figures published by GU, WEIDONG, and ROBERT J. NOVAK. “SHORT REPORT: DETECTION PROBABILITY OF ARBOVIRUS INFECTION IN MOSQUITO POPULATIONS.” The American Journal of Tropical Medicine and Hygiene 71, no. 5 (November 1, 2004): 636-38.
##############################
# The probability of detection (P) of any infected individuals in a sample
# of N mosquitoes can be calculated based on the binomial
# distribution where r is the infection rate.
##############################
N<-seq(1:2000) # sample size
r1<-0.001 # infection rates per 1000
P1<-1-(1-r1)^N # probability of detection
N<-seq(1:2000) # sample size
r2<-0.005 # infection rates per 1000
P2<-1-(1-r2)^N # probability of detection
# plot
# Probability of detection of infected mosquitoes as a
# function of sample sizes (infection rates per 1,000: bold line = 1; fine line = 5).
plot(P1,ylim=c(0,1),xlab="Sample size",ylab="Probability of detection")
lines(P2)
##############################
# Calculation of the minimal sample size for a specified probability of detection
##############################
r<-seq(0.001,0.02,0.001) # infection rates per 1000 from 1 to 20 per 1
P1<-0.5 # detection probability
N1 = log(1-P1)/log(1-r) # the minimal sample size for a specified probability of detection
P2<-0.8 # detection probability
N2 = log(1-P2)/log(1-r) # the minimal sample size for a specified probability of detection
P3<-0.9 # detection probability
N3 = log(1-P3)/log(1-r) # the minimal sample size for a specified probability of detection
# plot
# Relationship between minimum numbers of mosquitoes
# required for prescribed detection probabilities and infection
# rates of mosquitoes (dotted: Detection probability = 0.5; dashed: Detection probability = 0.8;
# line: Detection probability = 0.9).
plot(N1,ylim=c(0,2500),xlab="Infection rate (/1000)",ylab="Minimum number of mosquitoes")
lines(N2,type="c")
lines(N3)
##############################
# Estimate the upper bound of infection rates, r_upper, compatible
# with observations of a zero-infected individual and a
# specified confidence interval
##############################
library(pracma) # library for the function nthroot
## Warning: package 'pracma' was built under R version 3.1.2
N<-seq(1:1000) # sample size
P<-0.8 # confidence interval of infection rate
# upper bound of infection rates
gs<-1-(nthroot((1-P),N))
gs2<-gs*1000
P<-0.95 # confidence interval of infection rate
# upper bound of infection rates
gs_2<-1-(nthroot((1-P),N))
gs2_2<-gs_2*1000
# Upper bounds of 80% and 95% confidence intervals of
# infection rates compatible with observations of zero-infected individuals
# in mosquito samples (dotted: 80% confidence limit; line: 95% confidence limit).
plot(gs2,ylim=c(0,35),xlim=c(90,1000),xlab="Sample size",ylab="Upper bound of infection rates (/1000)")
lines(gs2_2,type="l")