Created
October 2, 2018 03:58
-
-
Save jebyrnes/3c7c5e263ea9d849cdf168af22e414a1 to your computer and use it in GitHub Desktop.
How to use purrr::iwalk to do discrete time logistic growth models.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #'---------------- | |
| #' 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