CR_ode: ODE of consumer-resource model

Description Arguments Value Examples

View source: R/CR_ode.R

Description

The ordinary differential equation (ODE) that describe the consumer and resource interactions.

Arguments

time

time sequence for which output is wanted; the first value of times must be the initial time.

state

the intial (state) values for the ODE, a vector.

parameters

parameters passed to ODE.

Value

a matrix of class deSolve.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Load packages and example parameters
library(tidyverse)
library(deSolve)
data(example_parameter)

# Create species pool
pool_build()

# Time sequence 
time <- seq(0, 100, by = 1)

# Parameters: a named vector
sp <- 1:S
re <- 1:P
parameters <- list(sp = sp, re = re, J = J, Rin = Rin, P = P, S = S, u = u, w = w, m = m, stoi = stoi)

# Initial condition: a named vector
state <- c(setNames(rep(.1, P), paste0("R", sprintf("%03d", 1:P))),
           setNames(rep(1, length(sp)), paste0("X", sprintf("%05d", sp))))

# Run ode 
result <- ode(y = state, times = time, func = CR_ode, parms = parameters)

# Plot
result %>%
 as.tibble() %>%
 gather("index", "value", -1) %>%
 ggplot(aes(x = time, y = value, color = index, lty = substr(index, 1, 1))) +
 geom_line()

Chang-Yu-Chang/MigrationCommunity documentation built on Sept. 8, 2018, 8:30 p.m.