%################################################################################## %This is the Matlab code to set up and run model simulations for social-system %structured disease transmission in a basic 10 group metapopulation of primates. %This code is not intended to be elegant and concise, rather, obvious and easy to %manipulate %This code was written and annotated by Sadie J Ryan, commented on July 19th, 2013. %################################################################################# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %First, extract the following code to a separate function, and call it binan.m, so it can be %called inside the model simulations %This file wants to be a function that makes sure that a binomial call which is passed 0,0 won't go crazy function [a] = binan(n,p) n=floor(n); if n==0 a = 0; else a = (binornd(n,p)/n); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %MAIN CODE STARTS HERE %Setting up to run a ridiculous number of simulations to collect summaries at the %end for q=1:20 nreps=100; for j=1:nreps c=[q,j] %If you want to know what iteration it's on, you can uncomment the next line %c=j %Setting up a 10 group SI model with between group movement %DEMOGRAPHIC RATES - in this example code, we use the medium sized monkey % Define the weaning age, ii, to obtain an infant transition category, i ii=3; irate=1/ii; i=irate; %then the age of first reproduction for females, to derive the subadult female category, sf mf = 5 sfrate=1/mf; sf=sfrate; %then the age of maturity for males, to derive subadult males, sm mm=6; smrate = 1/mm; sm=smrate; % b, the birthrate %b=0.50 b=brate; %then longevity, to derive annual persistence, p le=15; p=1-(1/le); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Create the monkey metapopulation matrix, MM %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MM=zeros(100,100); %SET UP TOTAL POPULATION % Create overall NG population vector, X AX=vertcat(5*ones(5,1),zeros(5,1)); BX=vertcat(5*ones(5,1),zeros(5,1)); CX=vertcat(5*ones(5,1),zeros(5,1)); DX=vertcat(5*ones(5,1),zeros(5,1)); EX=vertcat(5*ones(5,1),zeros(5,1)); FX=vertcat(5*ones(5,1),zeros(5,1)); GX=vertcat(5*ones(5,1),zeros(5,1)); HX=vertcat(5*ones(5,1),zeros(5,1)); IX=vertcat(5*ones(5,1),zeros(5,1)); JX=vertcat(5*ones(5,1),zeros(5,1)); X=vertcat(AX,BX,CX,DX,EX,FX,GX,HX,IX,JX); %X=5*ones(100,1); X(7)=1; %We will want to run this one through some timesteps, tmax, and store NGs tmax=200; %making a blank time series matrix, xx xx=zeros(100,tmax); xx(:,1)=X; %The movement rate m=q/20; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %DISEASE PARAMETERS AND TRANSMISSION STRUCTURES (Contact Vectors) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % define beta, B B=0.1; %Define alpha (death from disease), A A=0.05; %give a vertical transmission component, v v=0.0; % We define a contact matrix, 5x5 binary, for the social system in question % To run the model with a particular contact vector, uncomment it %STD, Solitary %C=[0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 0, 0, 0, 0, 1; 0, 0, 0,1, 0]; %STD, Monogamous %C=[0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 0, 0, 0, 0, 1; 0, 0, 0,1, 0]; %STD, Unimale %C=[0, 0, 0, 0, 0; 0, 0, 1, 0, 1; 0, 1, 0, 0, 0; 0, 0, 0, 0, 1; 0, 0, 0,1, 0]; %STD, Multimale % C=[0, 0, 0, 0, 0; 0, 0, 1, 0, 1; 0, 1, 0, 0, 0; 0, 0, 0, 0, 1; 0, 0, 0,0, 0]; %STD, Fission-Fusion %C=[0, 0, 0, 0, 0; 0, 1, 1, 1, 1; 0, 1, 1, 1, 1; 0, 1, 1, 1, 1; 0, 1, 1, 1, 1]; %FO, Solitary % C=[1, 0, 0, 1, 1; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 1, 1; 1, 0, 0, 1, 1]; %FO, Monogamous % C=[1, 0, 0, 1, 1; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 1, 1; 1, 0, 0,1, 1]; %FO, Unimale % C=[1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1]; %FO, Multimale % C=[1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1]; %FO, Fission-Fusion % C=[1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1,1, 1]; %Scratch, Solitary % C=[0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 0, 0, 0, 1, 1; 0, 0, 0, 1, 1]; %Scratch, Monogamous % C=[0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 0, 0, 0, 1, 1; 0, 0, 0, 1, 1]; %Scratch, Unimale % C=[0, 0, 0, 0, 0; 0, 1, 1, 1, 1; 0, 0, 1, 0, 1; 1, 0, 0, 1, 0; 1, 0, 1, 0, 1]; %Scratch, Multimale % C=[0, 0, 0, 0, 0; 0, 1, 1, 1, 1; 0, 0, 1, 1, 1; 1, 0, 1, 1, 1; 1, 0, 1, 1, 1]; %Scratch, Fission-Fusion % C=[0, 0, 0, 0, 0; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1]; %Sneeze, Solitary % C=[1, 0, 0, 1, 1; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 1, 1; 1, 0, 0, 1, 1]; %Sneeze, Monogamous; %Sneeze, Unimale % C=[1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1]; %Sneeze, Multimale % C=[1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1]; %Sneeze, Fission-Fusion % C=[1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1]; %Vector, Solitary %C=[1, 0, 0, 1, 1; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 1, 1; 1, 0, 0, 1, 1]; %Vector, Monogamous % C=[1, 0, 0, 1, 1; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 1, 1; 1, 0, 0, 1, 1]; %Vector, Unimale % C=[1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1]; %Vector, Multimale % C=[1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1]; %Vector, Fission-Fusion % C=[1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1, 1; 1, 1, 1, 1,1]; %start to run the model for a period of years for t=2:tmax %Within group persistence and infection %create an infection probability pinf, for each group AA to AJ %Define Infecteds AAI=xx(6:10, t-1); ABI=xx(16:20, t-1); ACI=xx(26:30, t-1); ADI=xx(36:40, t-1); AEI=xx(46:50, t-1); AFI=xx(56:60, t-1); AGI=xx(66:70, t-1); AHI=xx(76:80, t-1); AII=xx(86:90, t-1); AJI=xx(96:100, t-1); %Define within group population AAN = sum(xx(1:10, t-1)); ABN = sum(xx(11:20, t-1)); ACN = sum(xx(21:30, t-1)); ADN = sum(xx(31:40, t-1)); AEN = sum(xx(41:50, t-1)); AFN = sum(xx(51:60, t-1)); AGN = sum(xx(61:70, t-1)); AHN = sum(xx(71:80, t-1)); AIN = sum(xx(81:90, t-1)); AJN = sum(xx(91:100, t-1)); %Defining susceptibles for later use AAS=xx(1:5, t-1); ABS=xx(11:15, t-1); ACS=xx(21:25, t-1); ADS=xx(31:35, t-1); AES=xx(41:45, t-1); AFS=xx(51:55, t-1); AGS=xx(61:65, t-1); AHS=xx(71:75, t-1); AIS=xx(81:85, t-1); AJS=xx(91:95, t-1); %Set up the vector for freq-dep transmission within each group if AAN==0 pinfAA=zeros(1,5) else pinfAA=1-exp(-B*C*AAI/AAN); end if ABN==0 pinfAB=zeros(1,5) else pinfAB=1-exp(-B*C*ABI/ABN); end if ACN==0 pinfAC=zeros(1,5) else pinfAC=1-exp(-B*C*ACI/ACN); end if ADN==0 pinfAD=zeros(1,5) else pinfAD=1-exp(-B*C*ADI/ADN); end if AEN==0 pinfAE=zeros(1,5) else end pinfAE=1-exp(-B*C*AEI/AEN); if AFN==0 pinAF=zeros(1,5) else end pinfAF=1-exp(-B*C*AFI/AFN); if AGN==0 pinfAG=zeros(1,5) else end pinfAG=1-exp(-B*C*AGI/AGN); if AHN==0 pinfAH=zeros(1,5) else end pinfAH=1-exp(-B*C*AHI/AHN); if AIN==0 pinfAI=zeros(1,5) else end pinfAI=1-exp(-B*C*AII/AIN); if AJN==0 pinfAJ=zeros(1,5) else pinfAJ=1-exp(-B*C*AJI/AJN); end %Put the within-group demography and infection into the big matrix, MM %Susceptible births %Binomial flipped susceptible birthrates for susceptible mothers AAb = binan(xx(4,t-1)+xx(9,t-1), b); ABb = binan(xx(14,t-1)+xx(19,t-1), b); ACb = binan(xx(24,t-1)+xx(29,t-1), b); ADb = binan(xx(34,t-1)+xx(39,t-1), b); AEb = binan(xx(44,t-1)+xx(49,t-1), b); AFb = binan(xx(54,t-1)+xx(59,t-1), b); AGb = binan(xx(64,t-1)+xx(69,t-1), b); AHb = binan(xx(74,t-1)+xx(79,t-1), b); AIb = binan(xx(84,t-1)+xx(89,t-1), b); AJb = binan(xx(94,t-1)+xx(99,t-1), b); MM(1,4) = AAb; MM(11,14) = ABb; MM(21,24) = ACb; MM(31,34) = ADb; MM(41,44) = AEb; MM(51,54) = AFb; MM(61,64) = AGb; MM(71,74) = AHb; MM(81,84) = AIb; MM(91,94) = AJb; %from infected mothers %Binomial flipped birthrates for infected mothers MM(1,9)= AAb*(1-v); MM(11,19)= ABb*(1-v); MM(21,29)= ACb*(1-v); MM(31,39)= ADb*(1-v); MM(41,49)= AEb*(1-v); MM(51,59)= AFb*(1-v); MM(61,69)= AGb*(1-v); MM(71,79)= AHb*(1-v); MM(81,89)= AIb*(1-v); MM(91,99)= AJb*(1-v); %Infected births MM(6,9) = AAb*v; MM(16,19) = ABb*v; MM(26,29) = ACb*v; MM(36,39) = ADb*v; MM(46,49) = AEb*v; MM(56,59) = AFb*v; MM(66,69) = AGb*v; MM(76,79) = AHb*v; MM(86,89) = AIb*v; MM(96,99) = AJb*v; %Arrival of susceptible infants (those not infected and not transitioning) %Binomial flip on infant transition rate AAi = binan(xx(1, t-1)+xx(6,t-1),i); ABi = binan(xx(11, t-1)+xx(16,t-1),i); ACi = binan(xx(21, t-1)+xx(26,t-1),i); ADi = binan(xx(31, t-1)+xx(36,t-1),i); AEi = binan(xx(41, t-1)+xx(46,t-1),i); AFi = binan(xx(51, t-1)+xx(56,t-1),i); AGi = binan(xx(61, t-1)+xx(66,t-1),i); AHi = binan(xx(71, t-1)+xx(76,t-1),i); AIi = binan(xx(81, t-1)+xx(86,t-1),i); AJi = binan(xx(91, t-1)+xx(96,t-1),i); MM(1,1)= p*(1-pinfAA(1))*(1-AAi); MM(11,11) = p*(1-pinfAB(1))*(1-ABi); MM(21,21) = p*(1-pinfAC(1))*(1-ACi); MM(31,31) = p*(1-pinfAD(1))*(1-ADi); MM(41,41) = p*(1-pinfAE(1))*(1-AEi); MM(51,51) = p*(1-pinfAF(1))*(1-AFi); MM(61,61) = p*(1-pinfAG(1))*(1-AGi); MM(71,71) = p*(1-pinfAH(1))*(1-AHi); MM(81,81) = p*(1-pinfAI(1))*(1-AIi); MM(91,91) = p*(1-pinfAJ(1))*(1-AJi); %Arrival of susceptible subadult females (sf) MM(2,1)=p*(1-pinfAA(1))*(AAi/2); MM(12,11)=p*(1-pinfAB(1))*(ABi/2); MM(22,21)=p*(1-pinfAC(1))*(ACi/2); MM(32,31)=p*(1-pinfAD(1))*(ADi/2); MM(42,41)=p*(1-pinfAE(1))*(AEi/2); MM(52,51)=p*(1-pinfAF(1))*(AFi/2); MM(62,61)=p*(1-pinfAG(1))*(AGi/2); MM(72,71)=p*(1-pinfAH(1))*(AHi/2); MM(82,81)=p*(1-pinfAI(1))*(AIi/2); MM(92,91)=p*(1-pinfAJ(1))*(AJi/2); %Arrival of susceptible subadult males (sm) MM(3,1)=p*(1-pinfAA(1))*(AAi/2); MM(13,11)=p*(1-pinfAB(1))*(ABi/2); MM(23,21)=p*(1-pinfAC(1))*(ACi/2); MM(33,31)=p*(1-pinfAD(1))*(ADi/2); MM(43,41)=p*(1-pinfAE(1))*(AEi/2); MM(53,51)=p*(1-pinfAF(1))*(AFi/2); MM(63,61)=p*(1-pinfAG(1))*(AGi/2); MM(73,71)=p*(1-pinfAH(1))*(AHi/2); MM(83,81)=p*(1-pinfAI(1))*(AIi/2); MM(93,91)=p*(1-pinfAJ(1))*(AJi/2); %Persistence of susceptible subadult females (sf) %Binomial flip on sf rates for susceptibles AAsf = binan(xx(2,t-1)+xx(7,t-1),sf); ABsf = binan(xx(12,t-1)+xx(17,t-1),sf); ACsf = binan(xx(22,t-1)+xx(27,t-1),sf); ADsf = binan(xx(32,t-1)+xx(37,t-1),sf); AEsf = binan(xx(42,t-1)+xx(47,t-1),sf); AFsf = binan(xx(52,t-1)+xx(57,t-1),sf); AGsf = binan(xx(62,t-1)+xx(67,t-1),sf); AHsf = binan(xx(72,t-1)+xx(77,t-1),sf); AIsf = binan(xx(82,t-1)+xx(87,t-1),sf); AJsf = binan(xx(92,t-1)+xx(97,t-1),sf); MM(2,2)= p*(1-pinfAA(2))*(1-AAsf); MM(12,12) = p*(1-pinfAB(2))*(1-ABsf); MM(22,22) = p*(1-pinfAC(2))*(1-ACsf); MM(32,32) = p*(1-pinfAD(2))*(1-ADsf); MM(42,42) = p*(1-pinfAE(2))*(1-AEsf); MM(52,52) = p*(1-pinfAF(2))*(1-AFsf); MM(62,62) = p*(1-pinfAG(2))*(1-AGsf); MM(72,72) = p*(1-pinfAH(2))*(1-AHsf); MM(82,82) = p*(1-pinfAI(2))*(1-AIsf); MM(92,92) = p*(1-pinfAJ(2))*(1-AJsf); %Persistence of susceptible subadult males (sm) %Binomial flips on susceptible sm AAsm = binan(xx(3,t-1)+xx(8,t-1),sm); ABsm = binan(xx(13,t-1)+xx(18,t-1),sm); ACsm = binan(xx(23,t-1)+xx(28,t-1),sm); ADsm = binan(xx(33,t-1)+xx(38,t-1),sm); AEsm = binan(xx(43,t-1)+xx(48,t-1),sm); AFsm = binan(xx(53,t-1)+xx(58,t-1),sm); AGsm = binan(xx(63,t-1)+xx(68,t-1),sm); AHsm = binan(xx(73,t-1)+xx(78,t-1),sm); AIsm = binan(xx(83,t-1)+xx(88,t-1),sm); AJsm = binan(xx(93,t-1)+xx(98,t-1),sm); MM(3,3) = p*(1-pinfAA(3))*(1-AAsm); MM(13,13)=p*(1-pinfAB(3))*(1-ABsm); MM(23,23)=p*(1-pinfAC(3))*(1-ACsm); MM(33,33)=p*(1-pinfAD(3))*(1-ADsm); MM(43,43)=p*(1-pinfAE(3))*(1-AEsm); MM(53,53)=p*(1-pinfAF(3))*(1-AFsm); MM(63,63)=p*(1-pinfAG(3))*(1-AGsm); MM(73,73)=p*(1-pinfAH(3))*(1-AHsm); MM(83,83)=p*(1-pinfAI(3))*(1-AIsm); MM(93,93)=p*(1-pinfAJ(3))*(1-AJsm); %Arrival of susceptible adult females (af) MM(4,2) = p*(1-pinfAA(2))*AAsf; MM(14,12) = p*(1-pinfAB(2))*ABsf; MM(24,22) = p*(1-pinfAC(2))*ACsf; MM(34,32) = p*(1-pinfAD(2))*ADsf; MM(44,42) = p*(1-pinfAE(2))*AEsf; MM(54,52) = p*(1-pinfAF(2))*AFsf; MM(64,62) = p*(1-pinfAG(2))*AGsf; MM(74,72) = p*(1-pinfAH(2))*AHsf; MM(84,82) = p*(1-pinfAI(2))*AIsf; MM(94,92) = p*(1-pinfAJ(2))*AJsf; %Arrival of susceptible adult males (am) MM(5,3) = p*(1-pinfAA(3))*AAsm; MM(15,13) = p*(1-pinfAB(3))*ABsm; MM(25,23) = p*(1-pinfAC(3))*ACsm; MM(35,33) = p*(1-pinfAD(3))*ADsm; MM(45,43) = p*(1-pinfAE(3))*AEsm; MM(55,53) = p*(1-pinfAF(3))*AFsm; MM(65,63) = p*(1-pinfAG(3))*AGsm; MM(75,73) = p*(1-pinfAH(3))*AHsm; MM(85,83) = p*(1-pinfAI(3))*AIsm; MM(95,93) = p*(1-pinfAJ(3))*AJsm; %Persistence of susceptible adult females (af) MM(4,4) = p*(1-pinfAA(4)); MM(14,14) = p*(1-pinfAB(4)); MM(24,24) = p*(1-pinfAC(4)); MM(34,34) = p*(1-pinfAD(4)); MM(44,44) = p*(1-pinfAE(4)); MM(54,54) = p*(1-pinfAF(4)); MM(64,64) = p*(1-pinfAG(4)); MM(74,74) = p*(1-pinfAH(4)); MM(84,84) = p*(1-pinfAI(4)); MM(94,94) = p*(1-pinfAJ(4)); %Persistence of susceptible adult males (am) MM(5,5) = p*(1-pinfAA(5)); MM(15,15) = p*(1-pinfAB(5)); MM(25,25) = p*(1-pinfAC(5)); MM(35,35) = p*(1-pinfAD(5)); MM(45,45) = p*(1-pinfAE(5)); MM(55,55) = p*(1-pinfAF(5)); MM(65,65) = p*(1-pinfAG(5)); MM(75,75) = p*(1-pinfAH(5)); MM(85,85) = p*(1-pinfAI(5)); MM(95,95) = p*(1-pinfAJ(5)); %Arrival of infected infants from susceptible MM(6,1) = p*pinfAA(1)*(1-AAi)*(1-A); MM(16,11) = p*pinfAB(1)*(1-ABi)*(1-A); MM(26,21) = p*pinfAC(1)*(1-ACi)*(1-A); MM(36,31) = p*pinfAD(1)*(1-ADi)*(1-A); MM(46,41) = p*pinfAE(1)*(1-AEi)*(1-A); MM(56,51) = p*pinfAF(1)*(1-AFi)*(1-A); MM(66,61) = p*pinfAG(1)*(1-AGi)*(1-A); MM(76,71) = p*pinfAH(1)*(1-AHi)*(1-A); MM(86,81) = p*pinfAI(1)*(1-AIi)*(1-A); MM(96,91) = p*pinfAJ(1)*(1-AJi)*(1-A); %Persistence of infected infants MM(6,6)= p*(1-AAi)*(1-A); MM(16,16)= p*(1-ABi)*(1-A); MM(26,26)= p*(1-ACi)*(1-A); MM(36,36)= p*(1-ADi)*(1-A); MM(46,46)= p*(1-AEi)*(1-A); MM(56,56)= p*(1-AFi)*(1-A); MM(66,66)= p*(1-AGi)*(1-A); MM(76,76)= p*(1-AHi)*(1-A); MM(86,86)= p*(1-AIi)*(1-A); MM(96,96)= p*(1-AJi)*(1-A); %Arrival of infected subadult females from susceptible infants (sf) MM(7,1) = p*pinfAA(1)*(AAi/2)*(1-A); MM(17,11) = p*pinfAB(1)*(ABi/2)*(1-A); MM(27,21) = p*pinfAC(1)*(ACi/2)*(1-A); MM(37,31) = p*pinfAD(1)*(ADi/2)*(1-A); MM(47,41) = p*pinfAE(1)*(AEi/2)*(1-A); MM(57,51) = p*pinfAF(1)*(AFi/2)*(1-A); MM(67,61) = p*pinfAG(1)*(AGi/2)*(1-A); MM(77,71) = p*pinfAH(1)*(AHi/2)*(1-A); MM(87,81) = p*pinfAI(1)*(AIi/2)*(1-A); MM(97,91) = p*pinfAJ(1)*(AJi/2)*(1-A); %Arrival of infected subadult males from susceptible infants (sm) MM(8,1) = p*pinfAA(1)*(AAi/2)*(1-A); MM(18,11) = p*pinfAB(1)*(ABi/2)*(1-A); MM(28,21) = p*pinfAC(1)*(ACi/2)*(1-A); MM(38,31) = p*pinfAD(1)*(ADi/2)*(1-A); MM(48,41) = p*pinfAE(1)*(AEi/2)*(1-A); MM(58,51) = p*pinfAF(1)*(AFi/2)*(1-A); MM(68,61) = p*pinfAG(1)*(AGi/2)*(1-A); MM(78,71) = p*pinfAH(1)*(AHi/2)*(1-A); MM(88,81) = p*pinfAI(1)*(AIi/2)*(1-A); MM(98,91) = p*pinfAJ(1)*(AJi/2)*(1-A); %Arrival of infected subadult females from susceptible subadult females (sf) MM(7,2) = p*pinfAA(2)*(1-AAsf)*(1-A); MM(17,12) = p*pinfAB(2)*(1-ABsf)*(1-A); MM(27,22) = p*pinfAC(2)*(1-ACsf)*(1-A); MM(37,32) = p*pinfAD(2)*(1-ADsf)*(1-A); MM(47,42) = p*pinfAE(2)*(1-AEsf)*(1-A); MM(57,52) = p*pinfAF(2)*(1-AFsf)*(1-A); MM(67,62) = p*pinfAG(2)*(1-AGsf)*(1-A); MM(77,72) = p*pinfAH(2)*(1-AHsf)*(1-A); MM(87,82) = p*pinfAI(2)*(1-AIsf)*(1-A); MM(97,92) = p*pinfAJ(2)*(1-AJsf)*(1-A); %Arrival of infected subadult males from susceptible subadult males (sm) MM(8,3) = p*pinfAA(3)*(1-AAsm)*(1-A); MM(18,13) = p*pinfAB(3)*(1-ABsm)*(1-A); MM(28,23) = p*pinfAC(3)*(1-ACsm)*(1-A); MM(38,33) = p*pinfAD(3)*(1-ADsm)*(1-A); MM(48,43) = p*pinfAE(3)*(1-AEsm)*(1-A); MM(58,53) = p*pinfAF(3)*(1-AFsm)*(1-A); MM(68,63) = p*pinfAG(3)*(1-AGsm)*(1-A); MM(78,73) = p*pinfAH(3)*(1-AHsm)*(1-A); MM(88,83) = p*pinfAI(3)*(1-AIsm)*(1-A); MM(98,93) = p*pinfAJ(3)*(1-AJsm)*(1-A); %Persistence of infected subadult females (sf) MM(7,6)= p*(AAi/2)*(1-A); MM(17,16)= p*(ABi/2)*(1-A); MM(27,26)= p*(ACi/2)*(1-A); MM(37,36)= p*(ADi/2)*(1-A); MM(47,46)= p*(AEi/2)*(1-A); MM(57,56)= p*(AFi/2)*(1-A); MM(67,66)= p*(AGi/2)*(1-A); MM(77,76)= p*(AHi/2)*(1-A); MM(87,86)= p*(AIi/2)*(1-A); MM(97,96)= p*(AJi/2)*(1-A); MM(7,7)= p*(1-AAsf)*(1-A); MM(17,17)= p*(1-ABsf)*(1-A); MM(27,27)= p*(1-ACsf)*(1-A); MM(37,37)= p*(1-ADsf)*(1-A); MM(47,47)= p*(1-AEsf)*(1-A); MM(57,57)= p*(1-AFsf)*(1-A); MM(67,67)= p*(1-AGsf)*(1-A); MM(77,77)= p*(1-AHsf)*(1-A); MM(87,87)= p*(1-AIsf)*(1-A); MM(97,97)= p*(1-AJsf)*(1-A); %Persistence of infected subadult males (sm) MM(8,6)= p*(AAi/2)*(1-A); MM(18,16)= p*(ABi/2)*(1-A); MM(28,26)= p*(ACi/2)*(1-A); MM(38,36)= p*(ADi/2)*(1-A); MM(48,46)= p*(AEi/2)*(1-A); MM(58,56)= p*(AFi/2)*(1-A); MM(68,66)= p*(AGi/2)*(1-A); MM(78,76)= p*(AHi/2)*(1-A); MM(88,86)= p*(AIi/2)*(1-A); MM(98,96)= p*(AJi/2)*(1-A); MM(8,8)= p*(1-AAsm)*(1-A); MM(18,18)= p*(1-ABsm)*(1-A); MM(28,28)= p*(1-ACsm)*(1-A); MM(38,38)= p*(1-ADsm)*(1-A); MM(48,48)= p*(1-AEsm)*(1-A); MM(58,58)= p*(1-AFsm)*(1-A); MM(68,68)= p*(1-AGsm)*(1-A); MM(78,78)= p*(1-AHsm)*(1-A); MM(88,88)= p*(1-AIsm)*(1-A); MM(98,98)= p*(1-AJsm)*(1-A); %Arrival of infected adult females from susceptible subadult females (af) MM(9,2) = p*pinfAA(2)*(AAsf)*(1-A); MM(19,12) = p*pinfAB(2)*(ABsf)*(1-A); MM(29,22) = p*pinfAC(2)*(ACsf)*(1-A); MM(39,32) = p*pinfAD(2)*(ADsf)*(1-A); MM(49,42) = p*pinfAE(2)*(AEsf)*(1-A); MM(59,52) = p*pinfAF(2)*(AFsf)*(1-A); MM(69,62) = p*pinfAG(2)*(AGsf)*(1-A); MM(79,72) = p*pinfAH(2)*(AHsf)*(1-A); MM(89,82) = p*pinfAI(2)*(AIsf)*(1-A); MM(99,92) = p*pinfAJ(2)*(AJsf)*(1-A); %Arrival of infected adult males from susceptible subadult males (sm) MM(10,3) = p*pinfAA(3)*(AAsm)*(1-A); MM(20,13) = p*pinfAB(3)*(ABsm)*(1-A); MM(30,23) = p*pinfAC(3)*(ACsm)*(1-A); MM(40,33) = p*pinfAD(3)*(ADsm)*(1-A); MM(50,43) = p*pinfAE(3)*(AEsm)*(1-A); MM(60,53) = p*pinfAF(3)*(AFsm)*(1-A); MM(70,63) = p*pinfAG(3)*(AGsm)*(1-A); MM(80,73) = p*pinfAH(3)*(AHsm)*(1-A); MM(90,83) = p*pinfAI(3)*(AIsm)*(1-A); MM(100,93) = p*pinfAJ(3)*(AJsm)*(1-A); %Arrival of infected adult females from susceptible adult females (af) MM(9,4) = p*pinfAA(4)*(1-A); MM(19,14) = p*pinfAB(4)*(1-A); MM(29,24) = p*pinfAC(4)*(1-A); MM(39,34) = p*pinfAD(4)*(1-A); MM(49,44) = p*pinfAE(4)*(1-A); MM(59,54) = p*pinfAF(4)*(1-A); MM(69,64) = p*pinfAG(4)*(1-A); MM(79,74) = p*pinfAH(4)*(1-A); MM(89,84) = p*pinfAI(4)*(1-A); MM(99,94) = p*pinfAJ(4)*(1-A); %Arrival of infected adult males from susceptible adults males (am) MM(10,5) = p*pinfAA(5)*(1-A); MM(20,15) = p*pinfAB(5)*(1-A); MM(30,25) = p*pinfAC(5)*(1-A); MM(40,35) = p*pinfAD(5)*(1-A); MM(50,45) = p*pinfAE(5)*(1-A); MM(60,55) = p*pinfAF(5)*(1-A); MM(70,65) = p*pinfAG(5)*(1-A); MM(80,75) = p*pinfAH(5)*(1-A); MM(90,85) = p*pinfAI(5)*(1-A); MM(100,95) = p*pinfAJ(5)*(1-A); %Persistence of infected adult females MM(9,7)= p*AAsf*(1-A); MM(19,17)= p*ABsf*(1-A); MM(29,27)= p*ACsf*(1-A); MM(39,37)= p*ADsf*(1-A); MM(49,47)= p*AEsf*(1-A); MM(59,57)= p*AFsf*(1-A); MM(69,67)= p*AGsf*(1-A); MM(79,77)= p*AHsf*(1-A); MM(89,87)= p*AIsf*(1-A); MM(99,97)= p*AJsf*(1-A); MM(9,9)= p*(1-A); MM(19,19)= p*(1-A); MM(29,29)= p*(1-A); MM(39,39)= p*(1-A); MM(49,49)= p*(1-A); MM(59,59)= p*(1-A); MM(69,69)= p*(1-A); MM(79,79)= p*(1-A); MM(89,89)= p*(1-A); MM(99,99)= p*(1-A); %Persistence of infected adult males MM(10,8)= p*AAsm*(1-A); MM(20,18)= p*ABsm*(1-A); MM(30,28)= p*ACsm*(1-A); MM(40,38)= p*ADsm*(1-A); MM(50,48)= p*AEsm*(1-A); MM(60,58)= p*AFsm*(1-A); MM(70,68)= p*AGsm*(1-A); MM(80,78)= p*AHsm*(1-A); MM(90,88)= p*AIsm*(1-A); MM(100,98)= p*AJsm*(1-A); MM(10,10)= p*(1-A); MM(20,20)= p*(1-A); MM(30,30)= p*(1-A); MM(40,40)= p*(1-A); MM(50,50)= p*(1-A); MM(60,60)= p*(1-A); MM(70,70)= p*(1-A); MM(80,80)= p*(1-A); MM(90,90)= p*(1-A); MM(100,100)= p*(1-A); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %SUBADULT MALE MOVEMENT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %AA is the NG vector after demography AA = MM*xx(:,t-1); %This script moves the monkeys around %First, this chooses a group to move to using a uniform random variable to pick a group. %Second, if the group is the same as the one supplying the move, the vector TT gets a zero entry. %Third, a binomial draw makes a stochastic rate based on the number of monkeys in that age category in the group. %The vector TT gets a minus entry where the monkey leaves and a positive in the group in which it moves to. %The vector TT, NG vector which holds the movers and moved TT=zeros(100,1); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Loop thru groups %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for z=0:9 %Susceptible move %Make a random number representing the group where the monkey will go to GG=round(9*rand); %If the group is the same as where it started, need to make sure it is sum zero if GG==z TT(10*z+3)=TT(10*z+3)+0; else %Move gives the stochastic rate of monkey moving, based on the number of %monkeys in that category; if this number is zero, then zeros will be passed. AAmove=binan(AA(10*z+3),m); %Moved stores the actual quantity of monkey, which must then be removed %from the first group and put into the next one AAmoved=AAmove*AA(10*z+3); TT(10*z+3)= TT(10*z+3)-AAmoved; TT(10*GG+3)=TT(10*GG+3)+AAmoved; end %Infective move GG=round(9*rand); if GG==z TT(10*z+8)=TT(10*z+8)+0; else AAmove=binan(AA(10*z+8),m); AAmoved=AAmove*AA(10*z+8); TT(10*z+8)= TT(10*z+8)-AAmoved; TT(10*GG+8)=TT(10*GG+8)+AAmoved; end end xx(:,t) = AA+TT; clear AA end NAA = sum(xx(1:10,tmax)); IAA = sum(xx(6:10,tmax)); NAB = sum(xx(11:20,tmax)); IAB = sum(xx(16:20,tmax)); NAC = sum(xx(21:30,tmax)); IAC = sum(xx(26:30,tmax)); NAD = sum(xx(31:40,tmax)); IAD = sum(xx(36:40,tmax)); NAE = sum(xx(41:50,tmax)); IAE = sum(xx(46:50,tmax)); NAF = sum(xx(51:60,tmax)); IAF = sum(xx(56:60,tmax)); NAG = sum(xx(61:70,tmax)); IAG = sum(xx(66:70,tmax)); NAH = sum(xx(71:80,tmax)); IAH = sum(xx(76:80,tmax)); NAI = sum(xx(81:90,tmax)); IAI = sum(xx(86:90,tmax)); NAJ = sum(xx(91:100,tmax)); IAJ = sum(xx(96:100,tmax)); Ntmax=sum(xx(:,tmax)); Prevtmax=(IAA+IAB+IAC+IAD+IAE+IAF+IAG+IAH+IAI+IAJ)/Ntmax; NN(j)=Ntmax; PP(j)=Prevtmax; GROUPS(j,:)=[NAA,NAB,NAC,NAD,NAE,NAF,NAG,NAH,NAI,NAJ]; end Nmean=mean(NN); Nste=std(NN)/sqrt(j); Prevmean=mean(PP); Prevste=std(PP)/sqrt(j); GROUPSmean=mean(GROUPS); GROUPSste=std(GROUPS)/sqrt(j); QQ(q,1)=Nmean; QQ(q,2)=Nste; RR(q,1)=Prevmean; RR(q,2)=Prevste; end QQ RR