The simplest way to run a simulation is to use:
simpleSimu=slsirSimu(pop=100,tstep=150)
This use defautl value whcih are detailed in the doc: ?slsirSimu
The output of the simulation can be visualised by adding:
simpleSimu=slsirSimu(pop=100,tstep=150,visu=T)
In this visualisation, light blue squares represent agents conforming to social distancing, blue circle represent agents not conforming to social distancingcircle agents
A more conveniant way to run simulations, used in the paper, is to use generatePopulation
to pre-generate population:
pop=generatePopulation(N=100,xsize=100,ysize=100,speed=1,recovery=1)
This will create a table with all information about the population:
Then the properties of the population can be adjusted
pop[c(10:20),"speed"]=3 #agents 10 to 20 will go twice more quiclkly than all other agents
simpleSimu=slsirSimu(pop=pop,tstep=150,visu=T)
Note: in general all strings are avoided to accelerate the computation time, and avoid the use of data.frame or table and stick to array. To simplify some global variable are given to translate later in their indice:
print(sir)
## S I R
## 1 2 3
print(S)
## [1] 1
print(I)
## [1] 2
print(R)
## [1] 3
print(G)
## [1] 2
print(B)
## [1] 1
Now, some simulations using the parameters from the paper:
xsize=ysize=100
poptest=generatePopulation(500,recovery=c(8,14)*25,speed=c(1,.2),xsize=xsize,ysize=ysize)
poptest[, "behavior"]=B
a=slsirSimu(poptest,450,p=c(1,.2),di=2,i0=1,inf=.9,sat=5,inf_r=.9,sat_r=5,xsize=xsize,ysize=ysize,visu=F,ap=F,ts=T,p_i=.01)
The output of a simulation is made of a list of to objet: allpop
and timeseries
. All pop filled if the opiton ap=T
is given to slsirSimu()
and allows to keep and analysis every agents at every time steps while timeseries
gives the timeseries for the important factors.
Here a simple way to visualise part of the output generated during this simulation:
plot(1,1,type="n",ylim=c(0,500),xlim=c(0,450),ylab="#agents",xlab="time",main="Evolution of Infection" )
na=lapply(sir,function(s)lines(a$timeseries[,s],col=sircol[s],lwd=3))
legend("topright",names(sir),col=sircol,lwd=2)
plot(1,1,type="n",ylim=c(0,500),xlim=c(0,450),ylab="#agents",xlab="time",main="Behavioral changes " )
na=lapply(1:2,function(s)lines(a$timeseries[,3+s],col=3+s,lwd=3))
legend("topright",c("Non-Adherent","Adherent"),col=3+(1:2),lwd=2,title = "Adhesion to social distancing")
output of a simulation