Message-ID: <51758F69.6060706@TU-Dresden.de>
Date: 2013-04-22T19:28:41Z
From: Thomas Petzoldt
Subject: [R-sig-dyn-mod] metapopulation SIR model
In-Reply-To: <1366623995.60039.YahooMailNeo@web171503.mail.ir2.yahoo.com>
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)