2

I'm trying to solve this SEIRVB ODE with time delay using dede in deSolve package of R in RStudio

I'm currently have this code

library(deSolve)

tau=0


# Parameters

Lambda = 0.5      
beta1 = 1.13921549    
beta2 = 2.68228986      
beta3 = 2.9627036      
beta4 = 1.19686956     
beta5 = 0.5    
beta6 = 1.34496108     
beta7 = 3.40332936   
beta8 = 1.48249240    
beta9 = 0.04681161     
beta10 = 2.32555864    
alpha = 0.5    
kappa = 0.02933240    
d = 0.0047876         
r = 0.09871        
tau=7 #time delay


# Function representing the SEIRVB model with time delay
seirvb_model <- function(t, y, parms) {
  if (t < tau)
    Ilag <- initial_conditions["I"]
  else
    Ilag <- lagvalue(t-tau,3)
  
  

  dS <- Lambda - beta1 * y[1] * y[2] - (beta3 + alpha) * y[1]
  dE <- beta4 * y[5] * y[2] + beta6 * y[6] * y[2] + beta1 * y[1] * y[2] - beta2 * y[2] * y[3] - (kappa + alpha) * y[2]
  dI <- beta5 * y[5] * Ilag + beta7 * y[6] * y[3] + beta2 * y[2] * y[3] - (d + alpha + r) * y[3]
  dR <- beta9 * y[5] + beta8 * y[6] + r * y[3] + kappa * y[2] - alpha * y[4]
  dV <- beta3 * y[1] - (beta9 + alpha + beta10) * y[5] - beta4 * y[5] * y[2] - beta5 * y[5] * Ilag
  dB <- beta10 * y[5] - beta6 * y[6] * y[2] - beta7 * y[6] * y[3] - (beta8 + alpha) * y[6]
  list(c(dS, dE, dI, dR, dV, dB))
}
  




# Initial conditions
initial_conditions <- c(
  S=0.3,
  E=0.1,
  I=0.006,
  R=0,
  V=0,
  B=0
)

# Time vector
times <- seq(0, 120, by = 1)

# Solve the SEIRVB model
ode_output <- dede(y = initial_conditions, times = times, func = seirvb_model, parms = NULL)

# Plotting the results
plot(ode_output, xlab = "Time", ylab = "Population", main = "SEIRVB Model for COVID-19")

Even though it works, the time delay was not considered in the solution as I got the same answer even though I changed the time delay already. Can someone help me how to fix this? Thank you!

tpetzoldt
  • 5,338
  • 2
  • 12
  • 29
Malanie
  • 23
  • 3
  • The formulation of your equations (transfer from V to I at a rate `beta*V(t)*I(t-tau)`) seems odd; what's the justification for it? – Ben Bolker Jun 18 '23 at 16:02
  • Oh, that's just an error with the model itself (in terms of equation) – Malanie Jun 18 '23 at 20:05
  • Two small comments about terminology: (1) There is a difference between R (the language) and RStudio (the premier interface program to work with R). Package deSolve is an add-on to R. It works also without RStudio. (2) R is case sensitive, the name of the package is **deSolve**. – tpetzoldt Jun 19 '23 at 23:29

1 Answers1

3

It appears there is a difference:

tau <- 0 
ode_output2 <- dede(y = initial_conditions, times = times, func = seirvb_model, parms = NULL)
tau <- 40
ode_output3 <- dede(y = initial_conditions, times = times, func = seirvb_model, parms = NULL)

We can use all.equal() to see that the outputs are not the same.

Visualizing the differences between the baseline tau=7 and two alternatives (tau=0, tau=40);

png("dede_diff.png")
par(las = 1, bty = "l")
matplot(ode_output[,"I"] - cbind(ode_output3[,"I"],ode_output2[,"I"]),
        lty = 1:2, col = 1:2, ylab = "diff", type = "l")
legend("topright",
       legend = c("tau = 40", "tau=0"),
       lty = 1:2, col = 1:2)
dev.off()

enter image description here

You may wonder why the delay makes so little difference to the output, but it does make some difference.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453