[R-sig-dyn-mod] metapopulation SIR model
Thomas Petzoldt
Thomas.Petzoldt at TU-Dresden.de
Mon Apr 22 21:28:41 CEST 2013
Hi,
I would suggest to use an interaction matrix approach
similar to the multi-species Lotka-Volterra example, cf.:
http://desolve.r-forge.r-project.org/slides/tutorial.pdf#91
or the example below.
thpe
##----------------------------------------------------------
library(deSolve)
model <- function(t, n, parms) {
with(parms, {
dn <- r * n + n * (A %*% n)
list(dn)
})
}
parms <- list(
r = c(r1 = 0.1, r2 = 0.1, r3 = -0.1, r4 = -0.1),
A = matrix(c(
0.0, 0.0, -0.2, 0.0, # prey 1
0.0, 0.0, 0.0, -0.1, # prey 2
0.2, 0.0, 0.0, 0.0, # predator 1; eats prey 1
0.0, 0.1, 0.0, 0.0), # predator 2; eats prey 2
nrow = 4, ncol = 4, byrow = TRUE)
)
times = seq(0, 500, 0.1)
n0 = c(n1 = 1, n2 = 1, n3 = 2, n4 = 2)
out <- ode(n0, times, model, parms)
plot(out)
More information about the R-sig-dynamic-models
mailing list