Function for simulating a time series and creating an sts object. As the counts are generated using a negative binomial distribution one also gets the (1-alpha) quantile for each timepoint (can be interpreted as an in-control upperbound for in-control values). The baseline and outbreaks are created as in Noufaily et al. (2012).
overdispersion: size parameter of rnbinom for the parameterization with mean and dispersion
dates: dates of the time series
sizesOutbreak: sizes of all the outbreaks (vector)
datesOutbreak: dates of all the outbreaks (vector)
delayMax: maximal delay in time units
alpha: alpha for getting the (1-alpha) quantile of the negative binomial distribution at each timepoint
densityDelay: density distribution for the delay
Examples
set.seed(12345)# Time series parametersscenario4 <- c(1.6,0,0.4,0.5,2)theta <-1.6beta <-0gamma1 <-0.4gamma2 <-0.5overdispersion <-1m <-1# DatesfirstDate <-"2006-01-01"lengthT=350dates <- as.Date(firstDate)+7*0:(lengthT -1)# Maximal delay in weeksD=10# Dates and sizes of the outbreaksdatesOutbreak <- as.Date(c("2008-03-30","2011-09-25"))sizesOutbreak <- c(2,5)# Delay distributiondata("salmAllOnset")in2011 <- which(isoWeekYear(epoch(salmAllOnset))$ISOYear ==2011)rT2011 <- salmAllOnset@control$reportingTriangle$n[in2011,]densityDelay <- apply(rT2011,2,sum, na.rm=TRUE)/sum(rT2011, na.rm=TRUE)# alpha for the upperboundalpha <-0.05# Create the sts with the full time seriesstsSim <- sts_creation(theta=theta,beta=beta,gamma1=gamma1,gamma2=gamma2,m=m, overdispersion=overdispersion, dates=dates, sizesOutbreak=sizesOutbreak,datesOutbreak=datesOutbreak, delayMax=D,densityDelay=densityDelay, alpha=alpha)plot(stsSim)
References
Noufaily, A., Enki, D.G., Farrington, C.P., Garthwaite, P., Andrews, N.J., Charlett, A. (2012): An improved algorithm for outbreak detection in multiple surveillance systems. Statistics in Medicine, 32 (7), 1206-1222.