I have a simple SIR model, I am trying to implement a vaccination approach (V) where at first it is checked if the infected are higher than a threshold (100), and if there are still enough susceptibles left (50) it will vaccinate a certain number per timestep (50).
However what I am trying to do, is that once the condition is fulfilled it should vaccinate for 7 days (regardless of whether during these 7 days the infected are still higher than the threshold or not, for example if after day 4, I = 70 it should still continue, it should only stop if S < 50. After the 7 days are finished, it should check the condition again, and either start again for another 7 days or not.
What I have so far, I would be grateful if someone helped me implement that loop
sirV=function(time, y, params){
S = y[1]
I = y[2]
R = y[3]
V = y[4]
with(as.list(params),{
vac_helper = if (I > 100 & S > 50) {50}
else {0}
N = S+I+R+V
dS = -S*beta*I/N - vac_helper
dI = S*beta*I/N - gamma*I
dR = +gamma*I
dV = vac_helper
return(list(c(dS, dI, dR, dV)))
})
}
myparameters = c(gamma=1/10,beta=0.2)
times <- seq(0, 300)
my_ode <- as.data.frame(ode( y=c(100000, 10, 0,0), times, sirV, myparameters))