Skip to content

Instantly share code, notes, and snippets.

@jebyrnes
Created October 2, 2018 03:58
Show Gist options
  • Save jebyrnes/3c7c5e263ea9d849cdf168af22e414a1 to your computer and use it in GitHub Desktop.
Save jebyrnes/3c7c5e263ea9d849cdf168af22e414a1 to your computer and use it in GitHub Desktop.
How to use purrr::iwalk to do discrete time logistic growth models.
#'----------------
#' Discrete time logistic growth model
#' Using purrr and iwalk
#'----------------
library(purrr)
r <- 3.95237783423
n0 <- 0.3
gens <- 200
k <- 1
x <- rep(n0, gens)
iwalk(x, ~ ifelse(.y<2, x[.y], x[.y] <<- r* x[.y-1] * (1-x[.y-1]/k) ))
plot(x, type="l")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment