<jupyter_start><jupyter_text>SIR model in R using deSolve  Description  Equations $$\frac{dS(t)}{dt}  = -\beta S(t) I(t)\\\frac{dI(t)}{dt}  = \beta S(t) I(t)- \gamma I(t)\\\frac{dR(t)}{dt}  = \gamma I(t)$$  References  Implementation<jupyter_code>%%R
sir.ode <- function(times,init,parms){
  with(as.list(c(parms,init)), {
  # ODEs
  dS <- -beta*S*I
  dI <- beta*S*I-gamma*I
  dR <- gamma*I
  list(c(dS,dI,dR))
  })
}
parms <- c(beta=0.1,gamma=0.05)
init <- c(S=0.99,I=0.01,R=0) 
times <- seq(0,200,by=0.01)
sir.out <- lsoda(init,times,sir.ode,parms)
%%R
sir.out.long <- melt(as.data.frame(sir.out),"time")
%%R
ggplot(sir.out.long,aes(x=time,y=value,colour=variable,group=variable))+
  # Add line
  geom_line(lwd=2)+
  #Add labels
  xlab("Time")+ylab("Number")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2379746835443038, 'fraction_numerical': 0.02531645569620253, 'mean_word_length': 4.731884057971015, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '515261', 'license': 'MIT', 'n_tokens_mistral': 407, 'n_tokens_neox': 384, 'n_words': 51, 'path': 'sir-r.ipynb', 'repo_name': 'epirecipes/epinotebooks', 'size': '790'}