Skip to content

Instantly share code, notes, and snippets.

@N8python
Created July 10, 2020 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save N8python/9cd36fd3df154c32e22e2b12d9ba101d to your computer and use it in GitHub Desktop.
Save N8python/9cd36fd3df154c32e22e2b12d9ba101d to your computer and use it in GitHub Desktop.
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