# NB: the example takes a short while to run.
# Draw an exposure window width 1, 2, 3, 4, 5
L1 <- sample(1:5, 100, replace = TRUE)
# Draw the infection moment from a uniform distribution on (L0, L1)
L <- runif(100, 0, L1)
# Draw latency times (as estimated by Xin et al., 2022)
times <- rgamma(100, shape = 4.05, rate = 0.74)
R <- L + times
# Draw end of quarantine (last test moment)
Q <- L1 + sample( c(5, 10, 15, 20, 25), 100, replace = TRUE)
# Define the data set
mydat <- data.frame(R = R, L0 = 0, L1 = L1,
R0 = floor(R), R1 = floor(R + 1), Trunc = Q)
# Apply the truncation
mydat <- mydat[which( (mydat$R > mydat$Trunc) == FALSE), ]
mydat$R <- NULL
# If exposure ends after the last possible moment of the endpoint, end
# exposure earlier
mydat$L1 <- ifelse(mydat$L1 > mydat$R1, mydat$R1, mydat$L1)
# Run the model with truncation
Estimate_doublIn(dat = mydat,
infection_risk_distribution = "constant",
method = "gamma", percentiles = c(0.5, 0.9, 0.95, 0.99),
right_truncation = TRUE, iters = 1000,
burnin_period = 10, thin = 1,
further_thin_plots = 1)
Run the code above in your browser using DataLab