[R-sig-dyn-mod] Individual Based Model type with deSolve

Thomas Petzoldt thomas.petzoldt at tu-dresden.de
Sun Feb 4 19:19:54 CET 2018


Romain Pete wrote:
  > I’m trying to implement an IBM type model ...

[...]

  > Trouble here is that the ode function uses initialization vector of
  > length = number of state variables and when using multiple seedings,
  > I, somehow, add state variables, hence, I’m struggling…

Dear Romain,

the initialization vector has always the same length as the number of 
state variables -- this is how ODE models are constructed by definition. 
There is no way to change the number of state variables *within* one 
call to ode() - and this has many good reasons.

However, it is of course possible to chain ode()-calls in an *outer* 
loop. Individual-based models (IBM) with an ODE component are common in 
ecology. R provides everything needed to implement it.

One method could be to define a "basic time step" for the IBM and then 
to initialize and run the ode model for the vector of all individuals 
existing in such a time step. Therefore, your "for (s in seeding 
...)"-loop should take place before MyModel() is evaluated.

Another question is how to combine the DEB with the NPZD model and the 
IBM. From my viewpoint, these are 3 models:

- the DEB model (an ODE model = deterministic and continuous)
- the NPZD model (another ODE model)
- the individual-based model (discrete and usually stochastic)

If the DEB and the NPZD have the same basic time step, the equations may 
be merged together, otherwise they may be run side by side.

Finally, you need to think about a suitable data structure to collect 
the output of your model.

Therefore, I suggest to think about the model and output data structure 
first, then to implement the separate parts in different functions, then 
test these parts separately and then put it together.

I've made something like this (Daphnia-IBM + DEB + 3 phytoplankton 
groups) some years ago as part of package simecolModels, still residing 
on R-Forge. The code is quite compact and needs a little bit philosophy 
;-) Not sure if this is the right approach for you.

Hope it helps,

Thomas


PS: A few additional points from the moderator: Please don't *answer* to 
an old message when posting a *new question* to a mailing list, and 
please do not append things that don't belong to your question. Then 
include a minimal reproducible example and use proper code formatting 
and indentation.


Am 31.01.2018 um 10:54 schrieb Romain Pete:
> Hi Folks,
> 
> I’m trying to implement an IBM type model in an existing biogeochemical model (NPZD-like). What I got is an embedded (NOT nested function) DEB oyster model (in my NPZD) on which I’d like to use a for loop to solve DEB equations for multiple seeding. Finally, I’d like to get the output of DEB with the output of the NPZD:
> 
> MyModel <- function(t, state, parameters) {
> 	with(as.list(c(state, parameters)), {
> 
> # all biogeochemical processes defined here
> 
> for( s in seeding){
> 	run DEB equations
> 	c(seeding1, seeding2, etc..) # 4 state variables DEB hence a matrix result with nrow=4 state variables, ncol= « s » seeding
> }
> 
> # rate of change
> dN = remineralisation + oyster excretion - uptake
> dP = growth - Zoo_grazing - Oyster_grazing - death
> dZ = growth - Oyster_grazing - death - egestion
> dD = death + egestion - mineralization
> 
> dE = stock			###
> dV = volume			###	These 4 state variables are multiplied by number of seedings
> dEr = reproduction		###
> dEgo = gamete		###
> 
> list(c(
> 	dN, dP, dZ, dD, dO, c(seeding)
> 	))
> 	})
> }
> 
> 
> Trouble here is that the ode function uses initialization vector of length = number of state variables and when using multiple seedings, I, somehow, add state variables, hence, I’m struggling…
> 
> Any thoughts would be much appreciated
> 
> Cheers
> 
> Romain



More information about the R-sig-dynamic-models mailing list