You seem to suppose that the two computations will yield similar results. On what basis do you suppose this?
\nThe Euler method applied to the differential equation you implement in your \"deSolve\" version is not equivalent to Euler steps applied to the deterministic map you supply in your \"Euler-multinomial\" version, is it?
\nHowever, the two should become closer with smaller step sizes. For example, in the following, I have replaced the timestep of 1 day with a timestep of 1/100 day.
\n\nlibrary(pomp)\nlibrary(dplyr)\n\nsirs_init <- Csnippet(\"\n S = N-300;\n I1 = 300;\n I2 = 0;\n R1 = R2 = R3 = 0;\n J = 0;\n\")\n\nsirs_det_step <- Csnippet(\"\n double pR = 1-exp(-3/pi*dt);\n double pI = 1-exp(-2*mu_IR*dt);\n double dN_SI = S*(1-exp(-beta*(I1+I2)/N*dt));\n double dN_I1 = I1*pI;\n double dN_I2 = I2*pI;\n double dN_R1 = R1*pR;\n double dN_R2 = R2*pR;\n double dN_R3 = R3*pR;\n S += dN_R3 - dN_SI;\n I1 += dN_SI - dN_I1;\n I2 += dN_I1 - dN_I2;\n R1 += dN_I2 - dN_R1;\n R2 += dN_R1 - dN_R2;\n R3 += dN_R2 - dN_R3;\n J += dN_SI;\n\")\n\nsimulate(\n times=seq(1,36520,by=1),\n t0 = 1,\n rinit = sirs_init,\n rprocess = pomp::euler(sirs_det_step,delta.t = 0.01),\n statenames = c(\"S\",\"I1\",\"I2\",\"R1\",\"R2\",\"R3\",\"J\"),\n paramnames = c(\"beta\",\"mu_IR\",\"pi\",\"N\",\"rho\"),\n accumvars = \"J\",\n params=c(beta=0.19, rho=0.108, pi=100, mu_IR=0.2, N=1e7),\n format=\"data.frame\"\n) |>\n mutate(\n I = I1 + I2,\n R = R1 + R2 + R3\n ) -> po_out\n\n##### deSolve version ####\nlibrary(deSolve)\n\nsirs_2I_3R <- function(t, y, params) {\n\n S <- y[1]\n I1 <- y[2]\n I2 <- y[3]\n R1 <- y[4]\n R2 <- y[5]\n R3 <- y[6]\n J <- y[7]\n\n beta <- params[\"beta\"]\n gamma <- params[\"mu_IR\"]\n pi <- params[\"pi\"]\n N <- params[\"N\"]\n\n dS <- -beta*S*(I1+I2)/N + 3/pi*R3\n dI1 <- beta*S*(I1+I2)/N - 2*gamma*I1\n dI2 <- 2*gamma*I1 - 2*gamma*I2\n dR1 <- 2*gamma*I2 - 3/pi*R1\n dR2 <- 3/pi*R1 - 3/pi*R2\n dR3 <- 3/pi*R2 - 3/pi*R3\n ## cumulative infected\n dJ <- beta*S*(I1 + I2)/N\n\n list(c(dS, dI1, dI2, dR1, dR2, dR3, dJ))\n}\n\nsirs_2I_3R_solve <- function (params, I_init = 300, burn_in = 3650, total = 7300) {\n N <- params[\"N\"]\n start <- c(N-I_init,I_init,0,0,0,0,0)\n names(start) <- c(\"S\",\"I1\",\"I2\",\"R1\",\"R2\",\"R3\",\"J\")\n time <- seq(1,total,1)\n out <- ode(\n y = start,\n times = time,\n func = sirs_2I_3R,\n parms = params,\n method = rkMethod(\"euler\")\n )\n out <- data.frame(out)\n out$inc <- c(0,diff(out$J))\n out[burn_in:total,]\n}\n\nsirs_2I_3R_solve(\n params = c(beta=0.19, rho=0.108, pi=100, mu_IR=0.2, N=1e7),\n burn_in = 1,\n total = 36520\n) |>\n mutate(\n I = I1 + I2,\n R = R1 + R2 + R3\n ) -> ds_out\n\nop <- par(mfrow = c(3,1))\nplot(ds_out$I,type = \"l\",main = \"deSolve Euler\",ylab = \"\")\nplot(po_out$I,type = \"l\",main = \"pomp Euler\",ylab = \"\")\nplot(ds_out$I,po_out$I,type = \"p\",xlab = \"deSolve Euler\",ylab=\"pomp Euler\")\nabline(a=0,b=1)\npar(op)\n
-
Hi Dr.King, Recently, I have strange results fitting an SIRS model: my data showed sustained dynamics, while the estimated Reff is below 1. After sanity check using Using the code at the end, I built a deterministic SIRS model and generated three trajectories of Infected with Can you please comment on this? Or please let me know if there is any error in the code (see below). I appreciate your help. Thanks!
|
Beta Was this translation helpful? Give feedback.
-
You seem to suppose that the two computations will yield similar results. On what basis do you suppose this? The Euler method applied to the differential equation you implement in your "deSolve" version is not equivalent to Euler steps applied to the deterministic map you supply in your "Euler-multinomial" version, is it? However, the two should become closer with smaller step sizes. For example, in the following, I have replaced the timestep of 1 day with a timestep of 1/100 day.
|
Beta Was this translation helpful? Give feedback.
You seem to suppose that the two computations will yield similar results. On what basis do you suppose this?
The Euler method applied to the differential equation you implement in your "deSolve" version is not equivalent to Euler steps applied to the deterministic map you supply in your "Euler-multinomial" version, is it?
However, the two should become closer with smaller step sizes. For example, in the following, I have replaced the timestep of 1 day with a timestep of 1/100 day.