dajmcdon / rtestim

https://dajmcdon.github.io/rtestim/
Other
4 stars 0 forks source link

Fix the problem of negative delays in the convolution #63

Closed dajmcdon closed 3 months ago

dajmcdon commented 4 months ago

Closes #60

library(rtestim)
#> Loading required package: dspline
#> Loading required package: Matrix
length <- 300
## piecewise constant Rt: 
Rt <- c(rep(2, floor(2 * length / 5)), rep(0.8, length - floor(2 * length / 5)))
Mu <- double(length)
Mu[1] <- 2
incidence <- double(length)
w <- double(length)
## gamma parameters of measles: 
gamma_pars <- c(14.5963, 1.0208) 

set.seed(317)
incidence[1] <- Mu[1]
for(t in 2:length){
  w[t] <- delay_calculator(incidence[1:t], dist_gamma = gamma_pars)[t]
  Mu[t] <- Rt[t] * w[t]
  incidence[t] <- rpois(1, Mu[t])
}
w_full <- delay_calculator(incidence, dist_gamma = gamma_pars)
w_full[1:10]
#>  [1] 2.000000 2.000000 2.000201 2.013323 2.073506 2.181888 2.309699 2.432720
#>  [9] 2.547964 2.671985
w[1:10]
#>  [1] 0.000000 2.000000 2.000201 2.013323 2.073506 2.181888 2.309699 2.432720
#>  [9] 2.547964 2.671985