-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2.1.r~
47 lines (40 loc) · 2.04 KB
/
2.1.r~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#S, I, and R are the initial *totals* of susceptible, infected, and recovered individuals
#All parameters must be positive, and S(0)+I(0) ≤ 1
#Derivative-solving library
<<<<<<< HEAD
library(deSolve)
sir<-function(time, state, parameters) #Solve SIR equations
{
with(as.list(c(state, parameters)), {
dS <- - (beta*S*I)
dI <- (beta*S*I) - (gamma*I)
dR <- (gamma*I)
return(list(c(dS, dI, dR)))
=======
#testing in nanaimo
library(deSolve)
sir<-function(time, state, parameters) #Solve SIR equations
{
with(as.list(c(state, parameters)), {
dS <- - (beta*S*I)
dI <- (beta*S*I) - (gamma*I)
dR <- (gamma*I)
return(list(c(dS, dI, dR)))
>>>>>>> 355c456e52753be20ff16cbaa7faf57bc6afadcf
})}
parms<- c(beta=1.4247, # transmission rate (Ro=beta/gamma)
gamma= 0.14286) # recovery rate
yini<- c(S=1-.000001, # initial proportion susceptible
I=.000001, # initial proportion infected
R=0) # initial proportion recovered
times<- seq(0,100,by=1) #time sequence to use
out <- as.data.frame(ode(func = sir, y=yini, parms = parms, times=times))
out
#Plot values and add legend
graph.colors = c(rgb(0,1,0), rgb(1,0,0), rgb(0,0,1))
<<<<<<< HEAD
matplot(times, out[,-1], lty=1, type = "l", xlab ="Time", ylab = "% of Individuals", main ="SIR Model Freq", bty = "l", lwd=1, col =graph.colors)
=======
matplot(times, out[,-1], lty=1, type = "l", xlab = "Time", ylab = "% of Individuals", main = "SIR Model Freq", bty = "l", lwd=1, col = graph.colors)
>>>>>>> 355c456e52753be20ff16cbaa7faf57bc6afadcf
legend(par("usr")[1],par("usr")[3],c("Susceptible", "Infected", "Recovered"), pch=1, col=graph.colors, xjust=0, yjust=2)