forked from lash1937/stochasticity_structure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_functions.R
111 lines (102 loc) · 3.67 KB
/
model_functions.R
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# All population and community model functions
# deterministic, population model
# Equation 1 from text
# R = growth rate
# alpha = intraspecific competition coefficient
# N = population size at time t
# N_next = population size at time t+1
do.pop.det.BH <- function(R, alpha, N) {
N_next <- R*N/(1+alpha*N)
return(N_next)
}
# demographic stochasticity, population model
# Equation 2 from text
# R = growth rate
# alpha = intraspecific competition coefficient
# N = population size at time t
# N_next = population size at time t+1
do.pop.dem.BH <- function(R, alpha, N) {
N_next <- rpois(1, R*N/(1+alpha*N))
return(N_next)
}
# environmental stochasticity, population model
# Equation 3 from text
# R = growth rate
# alpha = intraspecific competition coefficient
# N = population size at time t
# N_next = population size at time t+1
# zeta = magnitude of the effect of env. stochasticity
# sigma = environmental condition at time t
do.pop.env.BH <- function(R, alpha, N, zeta, sigma) {
N_next <- R*N/(1+alpha*N) + N*zeta*sigma
return(N_next)
}
# environmental and demographic stochasticity, population model
# Equation 4 from text
# R = growth rate
# alpha = intraspecific competition coefficient
# N = population size at time t
# N_next = population size at time t+1
# zeta = magnitude of the effect of env. stochasticity
# sigma = environmental condition at time t
do.pop.both.BH <- function(R, alpha, N, zeta, sigma) {
N_next <- rpois(1,R*N/(1+alpha*N) + N*zeta*sigma)
return(N_next)
}
# demographic stochasticity, community model
# Equation 6 from text
# R = growth rate
# alphas = competition coefficients
# Nall = vector of population sizes of all species
# N = focal species' population size at time t
# N_next = population size at time t+1 for focal species
do.com.dem.BH <- function(R, alphas, N, Nall) {
N_next <- rpois(1, R*N/(1+sum(alphas*Nall)))
return(N_next)
}
# environmental stochasticity, community model
# Equation 7 from text
# R = growth rate
# alphas = competition coefficients
# Nall = vector of population sizes of all species
# N = focal species' population size at time t
# N_next = population size at time t+1 for focal species
# zeta = magnitude of the effect of env. stochasticity
# sigma = environmental condition at time t
do.com.env.BH <- function(R, alphas, N, Nall, zeta, sigma) {
N_next <- R*N/(1+sum(alphas*Nall)) + N*zeta*sigma
return(N_next)
}
# environmental and demographic stochasticity, community model
# Equation 8 from text
# R = growth rate
# alphas = competition coefficients
# Nall = vector of population sizes of all species
# N = focal species' population size at time t
# N_next = population size at time t+1
# zeta = magnitude of the effect of env. stochasticity
# sigma = environmental condition at time t
do.com.both.BH <- function(R, alphas, N, Nall, zeta, sigma) {
# if lambda ends up being negative due to environmental stochasticity
# set lambda to 0
N_next <- rpois(1, max(R*N/(1+sum(alphas*Nall)) + N*zeta*sigma, 0))
return(N_next)
}
# community model with seedbank and environmental stochasticity
# Equation 10 from text
# R = growth rate
# alphas = competition coefficients
# Nall = vector of population sizes of all species
# N = focal species' population size at time t
# N_next = population size at time t+1 for focal species
# zeta = magnitude of the effect of env. stochasticity
# sigma = environmental condition at time t
# s = seedbank survival
# g = fraction of seeds that germinate under environmental conditions at t=0
do.com.seedbank <- function(R, alphas, N, Nall, zeta, sigma, s, g) {
germ <- g+zeta*sigma
if(germ < 0) {germ <- 0}
if(germ > 1) {germ <- 1}
N_next <- N*s*(1-germ) + germ*R*N/(1+sum(alphas*Nall))
return(N_next)
}