在群体 - 矩阵模型中跟踪受感染的个体

时间:2016-08-13 17:46:06

标签: r

我开发了一个简单的年龄结构人口模型来预测疾病发生时的未来人口规模。这种疾病导致个体在感染后1 - 3年死亡,所以我在如何在单阶段矩阵(逐年)模型中跟踪感染动物长达3年的时间里一直在努力。换句话说,如何修改我现有的代码,以确保在感染第三年仍然存活的受感染动物从人群中移除?任何提示将非常感谢。

sum_matd <- matrix(rep(0,5*5),nrow=5)  #matrix for 4 age classes

#model specs
fecundity<- c(0.5) #fecundity
natsurv=0.7 #natural survival rate
prevalence<-c(0.01) #percent of population infected
mort=c(0.33,0.5,1) #mortality rate for infected animals

risk1=0.1   #distribution of infection by age class
risk2=0.2
risk3=0.3
risk4=0.4

nyears <- 15

results<-list()

for (i in 1:nyears)
{
  if(i==1){

    baby=0              #number of animals in population          
    female1=1362                        
    female2=888
    female3=754
    female4=599

  }else{
    baby=0                    #number of animals in population for year +1 
    female1=endpop[1]               
    female2=endpop[6]
    female3=endpop[11]
    female4=endpop[16]+endpop[21] 
}

  initialpop= c(baby,baby,baby,baby,baby, #vector of population age structure at the beginning
             female1,female1,female1,female1,female1,
             female2,female2,female2,female2,female2,
             female3,female3,female3,female3,female3,
             female4,female4,female4,female4,female4)

  #leslie matrix 
  sum_matd[1,]=c(0,natsurv*fecundity,natsurv*fecundity,natsurv*fecundity,natsurv*fecundity) #offspring produced for each age-class
  sum_matd[2,]=c(0,natsurv,0,0,0) 
  sum_matd[3,]=c(0,0,natsurv,0,0)
  sum_matd[4,]=c(0,0,0,natsurv,0)
  sum_matd[5,]=c(0,0,0,0,natsurv)
  popA=initialpop*sum_matd #updated population after mortality and fecundity                    

  sickpoplevel<-prevalence * (sum(popA)) #number of sick animals

  sickagelevel<-c(0,sickpoplevel*risk1,sickpoplevel*risk2,sickpoplevel*risk3,sickpoplevel*risk4) #assign sick age class per risk

  died1<- sickagelevel[2] * (sample (mort,1)) #sick that died based on randomly selected mortality
  died2<- sickagelevel[3] * (sample (mort,1))
  died3<- sickagelevel[4] * (sample (mort,1))
  died4<- sickagelevel[5] * (sample (mort,1))

  infected1<- sickagelevel[2] - died1  # sick but not dead
  infected2<- sickagelevel[3] - died2  # I need to keep track of the number of infected animals
  infected3<- sickagelevel[4] - died3  # because they die 1-3 years of being infected
  infected4<- sickagelevel[5] - died4

  healthybaby   =sum(popA[1,])    
  healthyfemale1=sum(popA[2,])  - died1 #remove mortalties from population
  healthyfemale2=sum(popA[3,])  - died2
  healthyfemale3=sum(popA[4,])  - died3
  healthyfemale4=sum(popA[5,])  - died4

  endpop=c(rep(healthybaby,5),rep(healthyfemale1,5),rep(healthyfemale2,5),rep(healthyfemale3,5),rep(healthyfemale4,5)) 

}

0 个答案:

没有答案