Dema_WO_cr<-function(N,ps,ave.followers,n_rep){
# N - numbers of S, Ig, Is
# ps - probs for S->I, Ig->I
dt=0.01;ts=seq(1,n_rep,dt);n_ts=length(ts);
S=matrix(0,nrow=n_ts,ncol=1);S[1]=N[1];
Ig=matrix(0,nrow=n_ts,ncol=1);Ig[1]=N[2];
I=matrix(0,nrow=n_ts,ncol=1);I[1]=N[3];
N=S[1]+Ig[1]+I[1];
F=ave.followers;
p.S2I=ps[1];p.Ig2I=ps[2]
# main
for (i_time in 1:(n_ts-1)) {
S[i_time+1]=S[i_time]-F/N*I[i_time]*S[i_time]*dt
Ig[i_time+1]=Ig[i_time]+((1-p.S2I)*F/N*I[i_time]*S[i_time]-p.Ig2I*F/N*Ig[i_time]*I[i_time])*dt
I[i_time+1]=I[i_time]+(p.S2I*F/N*I[i_time]*S[i_time]+p.Ig2I*F/N*Ig[i_time]*I[i_time])*dt
}
# plotting results
plot(ts,S,type="l",lwd=4,col="red", main="Distribution of rumors in Twitter "
,xlab="time", ylab="Proportions of People",cex.lab=1.3,ylim=c(0,S[1]))
lines(ts,Ig,type="l",lwd=4,col="blue")
lines(ts,I,type="l",lwd=4,col="green")
legend("right", c("Not seen rumors nor corrections","Seen rumors", "tweeted rumours"),
col=c("red","blue","green"),lty=rep(1,3),lwd=4)
}
Dema_W_cr<-function(N,ps,ave.followers,n_rep){
# N - numbers of S, Ig, Is
# ps - probs for S->I, Ig->I
dt=0.01;ts=seq(1,n_rep,dt);n_ts=length(ts);
S=matrix(0,nrow=n_ts,ncol=1);S[1]=N[1];
Ig=matrix(0,nrow=n_ts,ncol=1);Ig[1]=N[2];
I=matrix(0,nrow=n_ts,ncol=1);I[1]=N[3];
Rg=matrix(0,nrow=n_ts,ncol=1);Rg[1]=N[4];
R=matrix(0,nrow=n_ts,ncol=1);R[1]=N[5];
N=S[1]+Ig[1]+I[1]+Rg[1]+R[1];
F=ave.followers;
p.S2I=ps[1];p.Ig2I=ps[2];p.S2R=ps[3];p.Ig2R=ps[4];p.I2R=ps[5];p.Rg2R=ps[6];
# main
for (i_time in 1:(n_ts-1)) {
S[i_time+1]=S[i_time]+(-F/N*I[i_time]*S[i_time]-F/N*R[i_time]*S[i_time])*dt
Ig[i_time+1]=Ig[i_time]+((1-p.S2I)*F/N*I[i_time]*S[i_time]-p.Ig2I*F/N*Ig[i_time]*I[i_time]
-F/N*Ig[i_time]*R[i_time])*dt
I[i_time+1]=I[i_time]+(p.S2I*F/N*I[i_time]*S[i_time]+p.Ig2I*F/N*Ig[i_time]*I[i_time]
-F/N*I[i_time]*R[i_time])*dt
Rg[i_time+1]=Rg[i_time]+((1-p.S2R)*F/N*R[i_time]*S[i_time]+(1-p.Ig2R)*F/N*Ig[i_time]*R[i_time]
+(1-p.I2R)*F/N*I[i_time]*R[i_time]-p.Rg2R*F/N*Rg[i_time]*R[i_time])*dt
R[i_time+1]=R[i_time]+(p.S2R*F/N*R[i_time]*S[i_time]+p.Ig2R*F/N*Ig[i_time]*R[i_time]
+p.I2R*F/N*I[i_time]*R[i_time]+p.Rg2R*F/N*Rg[i_time]*R[i_time])*dt
}
# plotting results
plot(ts,S,type="l",lwd=4,col="red", main="Distribution of rumors in Twitter "
,xlab="time", ylab="Proportions of People",cex.lab=1.3,ylim=c(0,S[1]*1.25))
lines(ts,Ig,type="l",lwd=4,col="blue")
lines(ts,I,type="l",lwd=4,col="green")
lines(ts,Rg,type="l",lwd=4,col="magenta")
lines(ts,R,type="l",lwd=4,col="cyan")
legend("topright", c("Not seen rumors nor corrections","Seen rumors", "tweeted rumours",
"Seen corrections","tweeted corrections"),
col=c("red","blue","green","magenta","cyan"),lty=rep(1,5),lwd=4)
return(data.frame(S,Ig,I,Rg,R))
}
w=Dema_W_cr(c(10000,0,100,0,1),c(0.001,0.01,0.01,0.01,0.01,0.01),20,50)

Related