modelHanta.r

rm(list=ls())
library(ibmR)

times=seq(0,20,by=0.001);

model=new("scheduler")
#Human population
model=addPopulation(model,nbIndividuals=1000,evtCtctRate=0.1,intraSpecCtctRate=0.1,lifespan=1/70,name="Human");
model=addPopulation(model,nbIndividuals=1000,evtCtctRate=0.1,intraSpecCtctRate=0.1,lifespan=1/70,name="Rodent");
#Add pathogen
model=addPathogen(model,mutationRate=0.1,crossProtection=0,probaInfection=0.01,latencyPeriod=365/7,infectiousPeriod=365/7,recoveryPeriod=365/7)

#Modulation of probability infection according to infection history
modulationProbaInfectionHistory<-function(proba,pPathogen){
	return(proba);
}

#Individual step function
step<-function(){
	infArray
	popArray
	patArray
	indexPat=sample(1:length(patArray))
	for(k in indexPat){
		#Infection from direct contact with other populations
		proba=patArray[indexPat[k]]$probaInfection*(intraSpecCtctRate*length(infArray[infArray$pop==currentPop & infArray$pathogen==patArray[indexPart[k]]$id]))+sum((interSpecCtctRate*length(infArray[infArray$pop~=currentPop & infArray$pathogen==patArray[indexPart[k]]$id])));
		proba=modulationProbaInfectionHistory(proba,patArray[k]);
		if(rand()<proba){
			#Infection
			addPathogen(patArray[indexPat[k]]);
		}
	}
	if(rand()<mutationRate){
		mutation();
	}
}
rocheben/ibmR documentation built on May 5, 2019, 1:39 p.m.