# poisson
hist(rpois(n = 500000, lambda = 3))

Environmental stochasticity

# exponential growth
expoDynamics <- function(n, lambda, steps = 100){
  ret <- c()
  ret[1] <- n
  for(i in 1:steps){
    ret[i+1] <- ret[i] * lambda[i]
  }
  return(ret)
}
stps = 60
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"
)
x = replicate(200, lines(x = 1:stps,
  y = expoDynamics(n = 20, lambda = rnorm(n = stps, mean = 1.3, sd = 0.5), steps = stps-1),
  col = "blue"))

Demographic stochasticity

logisticGrowth <- function(n, r, k) {
  # n+(n*r*(1-(n / k)))
  n * exp(r * (1 - (n / k)))
}

logisticStochasticGrowth <- function(n, r, k) {
  n <- sum(rbinom(n, 1, 0.9))
  n * exp(r * (1 - (n / k)))
}

logisticDynamics <- function(n, r, k, steps = 100, stochastic = FALSE) {
  ret <- c()
  ret[1] <- n
  if (length(r) == 1) {
    r <- rep(r, steps)
  }
  for (i in 1:(steps - 1)) {
    if (stochastic) {
      ret[i + 1] <- logisticStochasticGrowth(ret[i], r[i], k)
    } else{
      ret[i + 1] <- logisticGrowth(ret[i], r[i], k)
    }
  }
  return(ret)
}
stps <- 100

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
)

x = sapply(rep(30, 30), function(x) {
  lines(logisticDynamics(n = x, r = 0.25, k = 100,
    steps = stps, stochastic = TRUE),
  col = 'firebrick')
})

x = sapply(rep(5, 30), function(x) {
  lines(logisticDynamics(n = x, r = 0.25, k = 100,
    steps = stps, stochastic = TRUE),
  col = 'blue')
})

Dispersal

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')

Dispersal kernel shape

Variation in individual dispersal behavior

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()