Created
July 10, 2020 13:20
-
-
Save N8python/9cd36fd3df154c32e22e2b12d9ba101d to your computer and use it in GitHub Desktop.
This file contains 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
library(deSolve) | |
library(reshape2) | |
library(ggplot2) | |
initial_state_values <- c(I = 1000000, R = 0, M = 0) | |
parameters <- c(gamma = 0.1, mu = 0.2) | |
times <- seq(from = 0, to = 28, by = 1) | |
cohort_model <- function(time, state, parameters) { | |
with (as.list(c(state, parameters)), { | |
dI <- -gamma * I - mu * I | |
dR <- gamma * I | |
dM <- mu * I | |
return(list(c(dI, dR, dM))) | |
}) | |
} | |
output <- as.data.frame(ode(y = initial_state_values, times = times, func = cohort_model, parms = parameters)) | |
output_long <- melt(as.data.frame(output), id = "time") | |
ggplot(data = output_long, aes(x = time, y = value, colour = variable, group = variable)) + | |
geom_line() + | |
xlab("Time (days)")+ | |
ylab("Number of people") + | |
labs(title = "Recoveries and Deaths over Time", colour= "Compartments") # add title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment