Created
July 10, 2020 14:08
-
-
Save N8python/474c86c5b7e844bd2f881ef312e0b038 to your computer and use it in GitHub Desktop.
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
| runs <- 1 | |
| for(run in 1:runs) { | |
| beta <- 0.65 | |
| gamma <- 0.15 | |
| N <- 1000 | |
| S <- c(999) | |
| I <- c(1) | |
| R <- c(0) | |
| for(i in 1:(7*8)){ | |
| l <- rbinom(1, round(I[length(I)]), beta) | |
| yI <- rbinom(1, round(I[length(I)]), gamma) | |
| sProportion <- S[length(S)] / N | |
| S <- c(S, S[length(S)] - l * sProportion) | |
| I <- c(I, I[length(I)] + l * sProportion - yI) | |
| R <- c(R, R[length(R)] + yI) | |
| } | |
| if (run == 1) { | |
| plot(S, type="l", col = "blue", main = "SIR Stochastic Model", xlab = "Time (In Days)", ylab = "Number of People", ylim = c(0, N)) | |
| legend("left", legend = c("S", "I", "R"), fill = c("blue", "red", "green")) | |
| } else { | |
| lines(S, col="blue") | |
| } | |
| lines(I, col="red") | |
| lines(R, col="green") | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment