# poisson
hist(rpois(n = 500000, lambda = 3))
# exponential growth
<- function(n, lambda, steps = 100){
expoDynamics <- c()
ret 1] <- n
ret[for(i in 1:steps){
+1] <- ret[i] * lambda[i]
ret[i
}return(ret)
}
= 60
stps plot(
x = 1:stps,
y = expoDynamics(n = 20, lambda = rep(1.3, stps+1), steps = stps-1),
type = 'l',
las = 1,
xlab = 'Time',
ylab = 'Population size',
col = "red"
)= replicate(200, lines(x = 1:stps,
x y = expoDynamics(n = 20, lambda = rnorm(n = stps, mean = 1.3, sd = 0.5), steps = stps-1),
col = "blue"))
<- function(n, r, k) {
logisticGrowth # n+(n*r*(1-(n / k)))
* exp(r * (1 - (n / k)))
n
}
<- function(n, r, k) {
logisticStochasticGrowth <- sum(rbinom(n, 1, 0.9))
n * exp(r * (1 - (n / k)))
n
}
<- function(n, r, k, steps = 100, stochastic = FALSE) {
logisticDynamics <- c()
ret 1] <- n
ret[if (length(r) == 1) {
<- rep(r, steps)
r
}for (i in 1:(steps - 1)) {
if (stochastic) {
+ 1] <- logisticStochasticGrowth(ret[i], r[i], k)
ret[i else{
} + 1] <- logisticGrowth(ret[i], r[i], k)
ret[i
}
}return(ret)
}
<- 100
stps
plot(
x = 1:stps,
y = logisticDynamics(n = 30, r = 0.25, k = 100, steps = stps),
type = 'n',
las = 1,
ylim = c(0, 100),
xlab = 'Time',
ylab = 'Population size',
col = 1
)
= sapply(rep(30, 30), function(x) {
x lines(logisticDynamics(n = x, r = 0.25, k = 100,
steps = stps, stochastic = TRUE),
col = 'firebrick')
})
= sapply(rep(5, 30), function(x) {
x lines(logisticDynamics(n = x, r = 0.25, k = 100,
steps = stps, stochastic = TRUE),
col = 'blue')
})
p = P(dispersal 1 unit) p * p = probability that an individual disperses 2 units p**3 = 3 units
plot(dpois(1:10, lambda=1), type='l')
points(1:10, 0.4^(1:10), col='dodgerblue')
lines(1:10, 0.4^(1:10), lwd=2, col='dodgerblue')
n <- 10 b <- 0.5 d <- 0.5
N <- c() N[1] <- n for(i in 1:500){ N[i+1] <- N[i]*rnorm(1,1,0.1) }
pdf(‘out.pdf’) plot(N, type=‘b’, col=‘dodgerblue’,xlab=‘Time’, ylab=‘Population size’) dev.off()