CR_ode: ODE of consumer-resource model

Description Usage Arguments Value Examples

View source: R/CR_ode.R

Description

The ordinary differential equations that describe the consumer and resource interactions.

Usage

1
CR_ode(time, state, parameters)

Arguments

time

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

state

the initial (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
30
31
# 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 Aug. 13, 2019, 9:41 p.m.