Skip to contents

Run predator-prey model

Usage

run_predprey_model(time, init, params)

Arguments

time

vector of time units over which to run model, starting from 0. time can also be supplied as just the total length of the simulation (i.e. tmax)

init

vector of initial population sizes for both species, with names H and P

params

vector of parameters. If the param vector has entries of c(r, a, e, d), the function runs the classic Lotka-Volterra model (type 1 functional response of predator; exponential growth for prey). If the parameter vector has entries c(r, a, e, d, K), supplied, then the function runs the Lotka-Volterra model with logistic growth in the prey. If the parameter vector has entries c(r, a, e, d, T_h), the function runs the Lotka-Volterra model with a Type II function response in the predator. Finally, if the parameter vector has entries c(r, a, e, d, K, T_h), the function runs the Lotka-Volterra model with logistic growth in the prey and Type II functional response for the predator (this is sometimes called the Rosenzweig-Macarthur model).

See also

plot_predprey_time() for plots of the population dynamics over time, and plot_predprey_portrait() for making portrait plots of the predator and prey (including visualizations of the ZNGIs)

Examples

# Lotka-Volterra predator-prey model
params_lv <- c(r = .1, a = .01, e = .01, d = .001)
head(run_predprey_model(5, init = c(H = 10, P = 5), params = params_lv))
#>      time        H        P
#> [1,]  0.0 10.00000 5.000000
#> [2,]  0.1 10.05013 5.000001
#> [3,]  0.2 10.10050 5.000005
#> [4,]  0.3 10.15113 5.000011
#> [5,]  0.4 10.20201 5.000020
#> [6,]  0.5 10.25315 5.000032
# Lotka-Volterra model with logistic growth of prey
params_lv_logprey <- c(r = .1, a = .01, e = .01, d = .001, K = 1000)
head(run_predprey_model(5, init = c(H = 10, P = 5), params = params_lv_logprey))
#>      time        H        P
#> [1,]  0.0 10.00000 5.000000
#> [2,]  0.1 10.04912 5.000001
#> [3,]  0.2 10.09847 5.000005
#> [4,]  0.3 10.14806 5.000011
#> [5,]  0.4 10.19789 5.000020
#> [6,]  0.5 10.24796 5.000031
# Lotka-Volterra model with Type 2 functional response
params_lvt2 <- c(r = .1, a = .01, e = .01, d = .001, T_h = .1)
head(run_predprey_model(5, init = c(H = 10, P = 5), params = params_lvt2))
#>      time        H        P
#> [1,]  0.0 10.00000 5.000000
#> [2,]  0.1 10.05062 4.999996
#> [3,]  0.2 10.10151 4.999995
#> [4,]  0.3 10.15265 4.999996
#> [5,]  0.4 10.20405 5.000000
#> [6,]  0.5 10.25572 5.000006
# Rosenzweig-Macarthur model (logistic prey and Type 2 FR predator)
params_rm <- c(r = .1, a = .01, e = .01, d = .001, K = 1000, T_h = .1)
head(run_predprey_model(5, init = c(H = 10, P = 5), params = params_rm))
#>      time        H        P
#> [1,]  0.0 10.00000 5.000000
#> [2,]  0.1 10.04962 4.999996
#> [3,]  0.2 10.09948 4.999995
#> [4,]  0.3 10.14958 4.999996
#> [5,]  0.4 10.19993 5.000000
#> [6,]  0.5 10.25053 5.000006