Clearing environment
rm(list = ls())
Loading necessary package
require(deSolve)
## Loading required package: deSolve
System of DEs
SARSCOV2Model <- function (t, y, params) {
S.h<-y[1] #create local variable S, first element of y
E.h<-y[2]
I.h<-y[3]
S.l<-y[4]
E.l<-y[5]
I.l<-y[6]
Q<-y[7]
R<-y[8]
V<-y[9]
with(
as.list(params, y),
{
dS.h<--q*beta*(I.h+I.l)*S.h/(S.h+E.h+I.h+S.l+E.l+I.l+Q+R)-c*(1-exp((-1/K)*V))*S.h
dE.h<-q*beta*(I.h+I.l)*S.h/(S.h+E.h+I.h+S.l+E.l+I.l+Q+R)+c*(1-exp((-1/K)*V))*S.h-lambda*E.h
dI.h<-lambda*E.h-b*g*I.h-aH*h*(1-g)*I.h-gammah*(1-h)*(1-g)*I.h
dS.l<--(1-p)*q*beta*(I.h+I.l)*S.l/(S.h+E.h+I.h+S.l+E.l+I.l+Q+R)-(1-p)*c*(1-exp((-1/K)*V))*S.l
dE.l<-(1-p)*q*beta*(I.h+I.l)/(S.h+E.h+I.h+S.l+E.l+I.l+Q+R)+(1-p)*c*(1-exp((-1/K)*V))*S.l-lambda*E.l
dI.l<-lambda*E.l-b*I.l
dQ<-b*I.l+g*b*I.h-aQ*h*Q-gammaQ*(1-h)*Q
dR<-gammah*(1-h)*(1-g)*I.h+gammaQ*(1-h)*Q
dV<-omega*I.h+(1-p)*omega*I.l-delta*V
dy<-c(dS.h,dE.h,dI.h,dS.l,dE.l,dI.l,dQ,dR,dV) #combine results into one vector dy
list(dy)
}
)
}
Initial Values
times<-seq(0,180,by=1)
covid.params<-c(q=0.2,beta=13,p=.2,c=0,lambda=1/4.43,b=1/0.77,g=0,gammaQ=0.1,gammah=1/2.7,aQ=1/1.93,aH=1/2.7,h=0.00082,omega=0,delta=1,K=10000)
ystart<-c(S.h=(.2)*100000,E.h=0,I.h=1,S.l=(1-0.2)*100000,E.l=0,I.l=0,Q=0,R=0,V=0)
covid.out <- as.data.frame(lsoda(ystart,times,SARSCOV2Model,covid.params))
Changing h to 0, 0.0002, 0.0004, 0.0006, 0.0008, & 0.001
covid.params.h1 <- c(q=0.5,beta=13,p=.2,c=0,lambda=1/4.43,b=1/0.77,g=0,gammaQ=0.1,gammah=1/2.7,aQ=1/1.93,aH=1/2.7,h=0,omega=0,delta=1,K=1000000)
covid.params.h2 <- c(q=0.5,beta=13,p=.2,c=0,lambda=1/4.43,b=1/0.77,g=0,gammaQ=0.1,gammah=1/2.7,aQ=1/1.93,aH=1/2.7,h=0.0002,omega=0,delta=1,K=1000000)
covid.params.h3 <- c(q=0.5,beta=13,p=.2,c=0,lambda=1/4.43,b=1/0.77,g=0,gammaQ=0.1,gammah=1/2.7,aQ=1/1.93,aH=1/2.7,h=0.0004,omega=0,delta=1,K=1000000)
covid.params.h4 <- c(q=0.5,beta=13,p=.2,c=0,lambda=1/4.43,b=1/0.77,g=0,gammaQ=0.1,gammah=1/2.7,aQ=1/1.93,aH=1/2.7,h=0.0006,omega=0,delta=1,K=1000000)
covid.params.h5 <- c(q=0.5,beta=13,p=.2,c=0,lambda=1/4.43,b=1/0.77,g=0,gammaQ=0.1,gammah=1/2.7,aQ=1/1.93,aH=1/2.7,h=0.0008,omega=0,delta=1,K=1000000)
covid.params.h6 <- c(q=0.5,beta=13,p=.2,c=0,lambda=1/4.43,b=1/0.77,g=0,gammaQ=0.1,gammah=1/2.7,aQ=1/1.93,aH=1/2.7,h=0.001,omega=0,delta=1,K=1000000)
Creating data frame for each value of h
covid.out.h1 <- as.data.frame(lsoda(ystart,times,SARSCOV2Model,covid.params.h1))
covid.out.h2 <- as.data.frame(lsoda(ystart,times,SARSCOV2Model,covid.params.h2))
covid.out.h3 <- as.data.frame(lsoda(ystart,times,SARSCOV2Model,covid.params.h3))
covid.out.h4 <- as.data.frame(lsoda(ystart,times,SARSCOV2Model,covid.params.h4))
covid.out.h5 <- as.data.frame(lsoda(ystart,times,SARSCOV2Model,covid.params.h5))
covid.out.h6 <- as.data.frame(lsoda(ystart,times,SARSCOV2Model,covid.params.h6))
Plotting all classes
## SUSCEPTIBLES ##
op1 <- par(fig=c(0,0.5,0,1), mar=c(4,4,1,1))
plot(covid.out.h1$S.h~covid.out.h1$time,type="l", col="blue", xlab="Days", ylab = "Susceptible (High)")
lines(covid.out.h2$S.h~covid.out.h2$time, type="l", col="red")
lines(covid.out.h3$S.h~covid.out.h3$time, type="l", col="darkturquoise")
lines(covid.out.h4$S.h~covid.out.h4$time, type="l", col="orange")
lines(covid.out.h5$S.h~covid.out.h5$time, type="l", col="purple")
lines(covid.out.h6$S.h~covid.out.h6$time, type="l", col="green")
legend(100, 15000,legend = c("h=0","h=0.0002","h=0.0004","h=0.0006","h=0.0008","h=0.001"), col = c("blue", "red", "darkturquoise", "orange", "purple", "green"), lty=1, cex=0.8)
par(fig=c(0.5,1,0,1), mar=c(4,4,1,1), new=T)
plot(covid.out.h1$S.l~covid.out.h1$time,type="l", col="blue", xlab="Days", ylab = "Susceptible (Low)")
lines(covid.out.h2$S.l~covid.out.h2$time, type="l", col="red")
lines(covid.out.h3$S.l~covid.out.h3$time, type="l", col="darkturquoise")
lines(covid.out.h4$S.l~covid.out.h4$time, type="l", col="orange")
lines(covid.out.h5$S.l~covid.out.h5$time, type="l", col="purple")
lines(covid.out.h6$S.l~covid.out.h6$time, type="l", col="green")
legend(100, 60000,legend = c("h=0","h=0.0002","h=0.0004","h=0.0006","h=0.0008","h=0.001"), col = c("blue", "red", "darkturquoise", "orange", "purple", "green"), lty=1, cex=0.8)
par(op1)
## EXPOSED ##
op2 <- par(fig=c(0,0.5,0,1), mar=c(4,4,1,1))
plot(covid.out.h1$E.h~covid.out.h1$time,type="l", col="blue", xlab="Days", ylab = "Exposed (High)")
lines(covid.out.h2$E.h~covid.out.h2$time, type="l", col="red")
lines(covid.out.h3$E.h~covid.out.h3$time, type="l", col="darkturquoise")
lines(covid.out.h4$E.h~covid.out.h4$time, type="l", col="orange")
lines(covid.out.h5$E.h~covid.out.h5$time, type="l", col="purple")
lines(covid.out.h6$E.h~covid.out.h6$time, type="l", col="green")
legend(100, 6000,legend = c("h=0","h=0.0002","h=0.0004","h=0.0006","h=0.0008","h=0.001"), col = c("blue", "red", "darkturquoise", "orange", "purple", "green"), lty=1, cex=0.8)
par(fig=c(0.5,1,0,1), mar=c(4,4,1,1), new=T)
plot(covid.out.h1$E.l~covid.out.h1$time,type="l", col="blue", xlab="Days", ylab = "Exposed (Low)")
lines(covid.out.h2$E.l~covid.out.h2$time, type="l", col="red")
lines(covid.out.h3$E.l~covid.out.h3$time, type="l", col="darkturquoise")
lines(covid.out.h4$E.l~covid.out.h4$time, type="l", col="orange")
lines(covid.out.h5$E.l~covid.out.h5$time, type="l", col="purple")
lines(covid.out.h6$E.l~covid.out.h6$time, type="l", col="green")
legend(100, 2.5,legend = c("h=0","h=0.0002","h=0.0004","h=0.0006","h=0.0008","h=0.001"), col = c("blue", "red", "darkturquoise", "orange", "purple", "green"), lty=1, cex=0.8)
par(op2)
## INFECTED ##
op3 <- par(fig=c(0,0.5,0,1), mar=c(4,4,1,1))
plot(covid.out.h1$I.h~covid.out.h1$time,type="l", col="blue", xlab="Days", ylab = "Infected (High)")
lines(covid.out.h2$I.h~covid.out.h2$time, type="l", col="red")
lines(covid.out.h3$I.h~covid.out.h3$time, type="l", col=453)
lines(covid.out.h4$I.h~covid.out.h4$time, type="l", col="orange")
lines(covid.out.h5$I.h~covid.out.h5$time, type="l", col="purple")
lines(covid.out.h6$I.h~covid.out.h6$time, type="l", col="green")
legend(100, 3000,legend = c("h=0","h=0.0002","h=0.0004","h=0.0006","h=0.0008","h=0.001"), col = c("blue", "red", 453, "orange", "purple", "green"), lty=1, cex=0.8)
par(fig=c(0.5,1,0,1), mar=c(4,4,1,1), new=T)
plot(covid.out.h1$I.l~covid.out.h1$time,type="l", col="blue", xlab="Days", ylab = "Infected (Low)")
lines(covid.out.h2$I.l~covid.out.h2$time, type="l", col="red")
lines(covid.out.h3$I.l~covid.out.h3$time, type="l", col="darkturquoise")
lines(covid.out.h4$I.l~covid.out.h4$time, type="l", col="orange")
lines(covid.out.h5$I.l~covid.out.h5$time, type="l", col="purple")
lines(covid.out.h6$I.l~covid.out.h6$time, type="l", col="green")
legend(100, 0.4,legend = c("h=0","h=0.0002","h=0.0004","h=0.0006","h=0.0008","h=0.001"), col = c("blue", "red", "darkturquoise", "orange", "purple", "green"), lty=1, cex=0.8)
par(op3)
## SELF-ISOLATING ##
op4 <- par(mar=c(6,6,2,2))
plot(covid.out.h1$Q~covid.out.h1$time,type="l", col="blue", xlab="Days", ylab = "Self-Isolating")
lines(covid.out.h2$Q~covid.out.h2$time, type="l", col="red")
lines(covid.out.h3$Q~covid.out.h3$time, type="l", col=453)
lines(covid.out.h4$Q~covid.out.h4$time, type="l", col="orange")
lines(covid.out.h5$Q~covid.out.h5$time, type="l", col="purple")
lines(covid.out.h6$Q~covid.out.h6$time, type="l", col="green")
legend(125, 3,legend = c("h=0","h=0.0002","h=0.0004","h=0.0006","h=0.0008","h=0.001"), col = c("blue", "red", 453, "orange", "purple", "green"), lty=1, cex=0.8)
par(op4)
## RECOVERED ##
op5 <- par(mar=c(6,6,2,2))
plot(covid.out.h1$R~covid.out.h1$time,type="l", col="blue", xlab="Days", ylab = "Recovered")
lines(covid.out.h2$R~covid.out.h2$time, type="l", col="red")
lines(covid.out.h3$R~covid.out.h3$time, type="l", col=453)
lines(covid.out.h4$R~covid.out.h4$time, type="l", col="orange")
lines(covid.out.h5$R~covid.out.h5$time, type="l", col="purple")
lines(covid.out.h6$R~covid.out.h6$time, type="l", col="green")
legend(125, 15000,legend = c("h=0","h=0.0002","h=0.0004","h=0.0006","h=0.0008","h=0.001"), col = c("blue", "red", 453, "orange", "purple", "green"), lty=1, cex=0.8)
par(op5)
## VIRUS IN ENVIRONMENT ##
op6 <- par(mar=c(6,6,2,2))
plot(covid.out.h1$V~covid.out.h1$time,type="l", col="blue", xlab="Days", ylab = "Virus in Environment")
lines(covid.out.h2$V~covid.out.h2$time, type="l", col="red")
lines(covid.out.h3$V~covid.out.h3$time, type="l", col="darkturquoise")
lines(covid.out.h4$V~covid.out.h4$time, type="l", col="orange")
lines(covid.out.h5$V~covid.out.h5$time, type="l", col="purple")
lines(covid.out.h6$V~covid.out.h6$time, type="l", col="green")
legend(125, 3500,legend = c("h=0","h=0.0002","h=0.0004","h=0.0006","h=0.0008","h=0.001"), col = c("blue", "red", "darkturquoise", "orange", "purple", "green"), lty=1, cex=0.8)
par(op6)
Results of plots
# first dataframe lists highest values
# second dataframe lists lowest values
# third dataframe lists ending values
results.h1 <- data.frame(
S.h = c(max(covid.out.h1[ ,2]), max(covid.out.h2[ ,2]), max(covid.out.h3[ ,2]), max(covid.out.h4[ ,2]), max(covid.out.h5[ ,2]), max(covid.out.h6[ ,2])),
E.h = c(max(covid.out.h1[ ,3]), max(covid.out.h2[ ,3]), max(covid.out.h3[ ,3]), max(covid.out.h4[ ,3]), max(covid.out.h5[ ,3]), max(covid.out.h6[ ,3])),
I.h = c(max(covid.out.h1[ ,4]), max(covid.out.h2[ ,4]), max(covid.out.h3[ ,4]), max(covid.out.h4[ ,4]), max(covid.out.h5[ ,4]), max(covid.out.h6[ ,4])),
S.l = c(max(covid.out.h1[ ,5]), max(covid.out.h2[ ,5]), max(covid.out.h3[ ,5]), max(covid.out.h4[ ,5]), max(covid.out.h5[ ,5]), max(covid.out.h6[ ,5])),
E.l = c(max(covid.out.h1[ ,6]), max(covid.out.h2[ ,6]), max(covid.out.h3[ ,6]), max(covid.out.h4[ ,6]), max(covid.out.h5[ ,6]), max(covid.out.h6[ ,6])),
I.l = c(max(covid.out.h1[ ,7]), max(covid.out.h2[ ,7]), max(covid.out.h3[ ,7]), max(covid.out.h4[ ,7]), max(covid.out.h5[ ,7]), max(covid.out.h6[ ,7])),
Q = c(max(covid.out.h1[ ,8]), max(covid.out.h2[ ,8]), max(covid.out.h3[ ,8]), max(covid.out.h4[ ,8]), max(covid.out.h5[ ,8]), max(covid.out.h6[ ,8])),
R = c(max(covid.out.h1[ ,9]), max(covid.out.h2[ ,9]), max(covid.out.h3[ ,9]), max(covid.out.h4[ ,9]), max(covid.out.h5[ ,9]), max(covid.out.h6[ ,9])),
V = c(max(covid.out.h1[ ,10]), max(covid.out.h2[ ,10]), max(covid.out.h3[ ,10]), max(covid.out.h4[ ,10]), max(covid.out.h5[ ,10]), max(covid.out.h6[ ,10]))
)
results.h2 <- data.frame(
S.h = c(min(covid.out.h1[ ,2]), min(covid.out.h2[ ,2]), min(covid.out.h3[ ,2]), min(covid.out.h4[ ,2]), min(covid.out.h5[ ,2]), min(covid.out.h6[ ,2])),
E.h = c(min(covid.out.h1[ ,3]), min(covid.out.h2[ ,3]), min(covid.out.h3[ ,3]), min(covid.out.h4[ ,3]), min(covid.out.h5[ ,3]), min(covid.out.h6[ ,3])),
I.h = c(min(covid.out.h1[ ,4]), min(covid.out.h2[ ,4]), min(covid.out.h3[ ,4]), min(covid.out.h4[ ,4]), min(covid.out.h5[ ,4]), min(covid.out.h6[ ,4])),
S.l = c(min(covid.out.h1[ ,5]), min(covid.out.h2[ ,5]), min(covid.out.h3[ ,5]), min(covid.out.h4[ ,5]), min(covid.out.h5[ ,5]), min(covid.out.h6[ ,5])),
E.l = c(min(covid.out.h1[ ,6]), min(covid.out.h2[ ,6]), min(covid.out.h3[ ,6]), min(covid.out.h4[ ,6]), min(covid.out.h5[ ,6]), min(covid.out.h6[ ,6])),
I.l = c(min(covid.out.h1[ ,7]), min(covid.out.h2[ ,7]), min(covid.out.h3[ ,7]), min(covid.out.h4[ ,7]), min(covid.out.h5[ ,7]), min(covid.out.h6[ ,7])),
Q = c(min(covid.out.h1[ ,8]), min(covid.out.h2[ ,8]), min(covid.out.h3[ ,8]), min(covid.out.h4[ ,8]), min(covid.out.h5[ ,8]), min(covid.out.h6[ ,8])),
R = c(min(covid.out.h1[ ,9]), min(covid.out.h2[ ,9]), min(covid.out.h3[ ,9]), min(covid.out.h4[ ,9]), min(covid.out.h5[ ,9]), min(covid.out.h6[ ,9])),
V = c(min(covid.out.h1[ ,10]), min(covid.out.h2[ ,10]), min(covid.out.h3[ ,10]), min(covid.out.h4[ ,10]), min(covid.out.h5[ ,10]), min(covid.out.h6[ ,10]))
)
results.h3 <- data.frame(
S.h = c(tail(covid.out.h1[ ,2],n=1), tail(covid.out.h2[ ,2],n=1), tail(covid.out.h3[ ,2],n=1), tail(covid.out.h4[ ,2],n=1), tail(covid.out.h5[ ,2],n=1), tail(covid.out.h6[ ,2],n=1)),
E.h = c(tail(covid.out.h1[ ,3],n=1), tail(covid.out.h2[ ,3],n=1), tail(covid.out.h3[ ,3],n=1), tail(covid.out.h4[ ,3],n=1), tail(covid.out.h5[ ,3],n=1), tail(covid.out.h6[ ,3],n=1)),
I.h = c(tail(covid.out.h1[ ,4],n=1), tail(covid.out.h2[ ,4],n=1), tail(covid.out.h3[ ,4],n=1), tail(covid.out.h4[ ,4],n=1), tail(covid.out.h5[ ,4],n=1), tail(covid.out.h6[ ,4],n=1)),
S.l = c(tail(covid.out.h1[ ,5],n=1), tail(covid.out.h2[ ,5],n=1), tail(covid.out.h3[ ,5],n=1), tail(covid.out.h4[ ,5],n=1), tail(covid.out.h5[ ,5],n=1), tail(covid.out.h6[ ,5],n=1)),
E.l = c(tail(covid.out.h1[ ,6],n=1), tail(covid.out.h2[ ,6],n=1), tail(covid.out.h3[ ,6],n=1), tail(covid.out.h4[ ,6],n=1), tail(covid.out.h5[ ,6],n=1), tail(covid.out.h6[ ,6],n=1)),
I.l = c(tail(covid.out.h1[ ,7],n=1), tail(covid.out.h2[ ,7],n=1), tail(covid.out.h3[ ,7],n=1), tail(covid.out.h4[ ,7],n=1), tail(covid.out.h5[ ,7],n=1), tail(covid.out.h6[ ,7],n=1)),
Q = c(tail(covid.out.h1[ ,8],n=1), tail(covid.out.h2[ ,8],n=1), tail(covid.out.h3[ ,8],n=1), tail(covid.out.h4[ ,8],n=1), tail(covid.out.h5[ ,8],n=1), tail(covid.out.h6[ ,8],n=1)),
R = c(tail(covid.out.h1[ ,9],n=1), tail(covid.out.h2[ ,9],n=1), tail(covid.out.h3[ ,9],n=1), tail(covid.out.h4[ ,9],n=1), tail(covid.out.h5[ ,9],n=1), tail(covid.out.h6[ ,9],n=1)),
V = c(tail(covid.out.h1[ ,10],n=1), tail(covid.out.h2[ ,10],n=1), tail(covid.out.h3[ ,10],n=1), tail(covid.out.h4[ ,10],n=1), tail(covid.out.h5[ ,10],n=1), tail(covid.out.h6[ ,10],n=1))
)
`.rowNamesDF<-`(results.h1,make.names=FALSE,c('h = 0','h = 0.0002','h = 0.0004','h = 0.0006','h = 0.0008','h = 0.001'))
`.rowNamesDF<-`(results.h2,make.names=FALSE,c('h = 0','h = 0.0002','h = 0.0004','h = 0.0006','h = 0.0008','h = 0.001'))
`.rowNamesDF<-`(results.h3,make.names=FALSE,c('h = 0','h = 0.0002','h = 0.0004','h = 0.0006','h = 0.0008','h = 0.001'))
Plotting highest, lowest, and ending values of classes
## HIGHEST ##
op7 <- par(mar=c(6,6,2,2))
plot(results.h1$S.h,type="b", col="blue", xlab="q values", ylab = "Individuals", main="Highest", ylim=c(0,80000))
lines(results.h1$E.h, type = "b", col="red")
lines(results.h1$I.h, type = "b", col="green")
lines(results.h1$S.l, type = "b", col="purple")
lines(results.h1$E.l, type = "b", col="orange")
lines(results.h1$I.l, type = "b", col="forestgreen")
lines(results.h1$Q, type = "b", col="darkturquoise")
lines(results.h1$R, type = "b", col="pink2")
lines(results.h1$V, type = "b", col="yellow")
legend(3, 70000,legend = c("Susceptibles (High)","Exposed (High)","Infected (High)","Susceptibles (Low)","Exposed (Low)","Infected (Low)", "Self-Isolating","Recovered","Virus"), col = c("blue", "red", "green","purple","orange","forestgreen","darkturquoise","pink2","yellow"), lty=1, cex=0.6)
par(op7)
## LOWEST
op8 <- par(mar=c(6,6,2,2))
plot(results.h2$S.h,type="b", col="blue", main="Lowest", xlab="q values", ylab = "Individuals", ylim=c(0,80000))
lines(results.h2$E.h, type = "b", col="red")
lines(results.h2$I.h, type = "b", col="green")
lines(results.h2$S.l, type = "b", col="purple")
lines(results.h2$E.l, type = "b", col="orange")
lines(results.h2$I.l, type = "b", col="forestgreen")
lines(results.h2$Q, type = "b", col="darkturquoise")
lines(results.h2$R, type = "b", col="pink2")
lines(results.h2$V, type = "b", col="yellow")
legend(3, 70000,legend = c("Susceptibles (High)","Exposed (High)","Infected (High)","Susceptibles (Low)","Exposed (Low)","Infected (Low)", "Self-Isolating","Recovered","Virus"), col = c("blue", "red", "green","purple","orange","forestgreen","darkturquoise","pink2","yellow"), lty=1, cex=0.6)
par(op8)
## ENDING ##
op9 <- par(mar=c(6,6,2,2))
plot(results.h3$S.h, type="b", col="blue", main="Ending", xlab="q values", ylab = "Individuals", ylim=c(0,80000))
lines(results.h3$E.h, type = "b", col="red")
lines(results.h3$I.h, type = "b", col="green")
lines(results.h3$S.l, type = "b", col="purple")
lines(results.h3$E.l, type = "b", col="orange")
lines(results.h3$I.l, type = "b", col="forestgreen")
lines(results.h3$Q, type = "b", col="darkturquoise")
lines(results.h3$R, type = "b", col="pink2")
lines(results.h3$V, type = "b", col="yellow")
legend(3, 70000,legend = c("Susceptibles (High)","Exposed (High)","Infected (High)","Susceptibles (Low)","Exposed (Low)","Infected (Low)", "Self-Isolating","Recovered","Virus"), col = c("blue", "red", "green","purple","orange","forestgreen","darkturquoise","pink2","yellow"), lty=1, cex=0.6)
par(op9)