library(kableExtra)
library(deSolve)
library(reshape2)
library(ggplot2)

Background 1

Background 2

Background 3

Question 1 (1pt)

Background 4

Background 5 – Model parameters

Parameter Symbol Value
Daily contact rate \(\alpha\) 5.0
Transmision probability \(\beta\) 0.1
Recovery rate \(\sigma\) 0.2
Loss of immunty rate \(\omega\) 0
Birth and death rate \(\mu\) 0

Question 3 (0.5pt)

Question 4 (0.5pt)

Question 5 (0.5pt)

Question 6 (1pt)

Question 6 (1pt)

# Define parameters -- THESE ARE THE MODEL PARAMETERS
parms <- c(alpha =5,        # alpha = daily contacts
           beta=0.1,        # beta = probability of infection on contact
           sigma=0.2,       # sigma = rate of recovery per day
           mu = 0.0,        # mu =  per capita birth and death rate
           omega = 0.0)     # omega = rate of immune loss per day

# Initial conditions --  THESE ARE THE CONDITIONS AT THE START OF THE SIMULATION
init <- c(S=99,           # number initilly susceptible
          I=1,            # number initally infectious
          R=0)            # initially immune or "recovered"

# Define model equations -- do not change -- or change with care!
# These are the model equations.  They are written as a function called sir_ode.  
# "parms" and "init" input the parameters and inital conditions into the equations 
sir_ode <- function(times,init,parms){
  with(as.list(c(parms,init)), {
    # ODEs
    dS <- mu*(S+I+R) + omega*R -alpha*beta*I*S/(S+I+R) - mu*S 
    dI <- alpha*beta*I*S/(S+I+R)-sigma*I - mu*I
    dR <- sigma*I  - omega*R - mu*R
    list(c(dS,dI,dR))
  })
}

# This creates the output from model equations.  
#If you want to run the model for longer, change the second term eg: seq(0,200,...)
times <- seq(0,100,length.out=100)
sir_out <- lsoda(init,times,sir_ode,parms)
sir_out_long <- melt(as.data.frame(sir_out),"time")
#Plotting the model output
ggplot(sir_out_long,aes(x=time,y=value,colour=variable,group=variable))+
  geom_line(lwd=2)+             #Add line
  xlab("Time")+ylab("Number")   #Add labels

Question 7 (0.5pt)

Question 8 (0.5pt)

Question 9 (0.5pt)

Question 10 (0.5pt)

Extensions

Extra credit (0.5pt)