CR_model: Simulate consumer-resource dynamics

Description Usage Arguments Value Examples

View source: R/CR_model.R

Description

This function takes a named vector as initial community, simulates based on CR_ode function, and reports the output result matrix.

Usage

1
CR_model(community = community, time_limit = 100, time_step = 1)

Arguments

community

the initial state of species and resource in a community. A named vector.

time_limit

time limit for ode.

time_step

time step for ode.

Value

a deSolve matrix

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
# Load example parameters
data(example_parameter)

# Build regional species pool
pool_build()

# Create a community, a named vector
set.seed(1)
species <- sample(1:S_pool, S, replace = FALSE) %>% sort()
community <-
  c(
    setNames(c(rep(1, P)), paste0("R", sprintf("%03d", 1:P))),
    setNames(c(rep(.1, length(species))), paste0("X", sprintf("%05d", species)))
  )

# Run ode
result <- CR_model(community = community, time_limit = 100, time_step = 1)

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

# Main function for running consumer-resource model

Chang-Yu-Chang/MigrationCommunity documentation built on Aug. 13, 2019, 9:41 p.m.