#This script contributed to Figure 1 of the manuscript submitted to #Philosophical Transactions of the Royal Society B on July 14, 2017 #Authors: Civitello DJ, Allman BE, Morozumi C, and Rohr JR. #Title: "Fertilization, eutrophication, and food provisioning: an integrative view of resource supplementation and wildlife disease dynamics." setwd("P:/RData") library(deSolve) ##### #SIZR ##### #definition of SIZR model disease.web.SIZR <- function(t,y,params){ S = y[1]; I = y[2]; Z = y[3]; R = y[4]; #reference initial conditions with( as.list(params), { dS <- e.S*f.S*(S + I)*R - d*S - u*f.S*S*Z # primary host dynamics dynamics dI <- u*f.S*S*Z - (d+v)*I # Infected primary host dynamics dZ <- sigma*(R/(R+Rh))*(d+v)*I - m*Z - f.S*(S+I)*Z # Parasite dynamics dR <- r*R*(1 - R/K) - f.S*(S+I)*R # Resource dynamics res <- c(dS, dI, dZ, dR) #store results list(res) } ) } #Run model to equilibrium for a set of r values times = seq(from=1, to=4000, by=1) outSIZR = matrix(nrow=0, ncol=4) r.set = (1:100)/100 for(i in 1:length(r.set)){ #Specification of model parameters params = c(e.S=0.5, f.S=0.01, f.P=0.0002, d=0.05, d.P=0.01, u=1e-4, v=0.05, e.C=0.5, f.C=0.0075, sigma=1e5, Rh=20, m=0.2, r=r.set[i], K=250) xstart = c(S = 10, I = 0, Z = 100, R=250) #run model and store equilibrium values of each player in the model outSIZR = rbind(outSIZR, as.data.frame(lsoda(xstart, times, disease.web.SIZR, params))[length(times),]) } #calculate prevalence prev = outSIZR$I/(outSIZR$I + outSIZR$S) plot(r.set, prev, type="l") write.table(outSIZR, file="outSIZR.csv") ##### #SIZRC ##### #definition of SIZRC model disease.web.SIZRC <- function(t,y,params){ S = y[1]; I = y[2]; Z = y[3]; R = y[4]; C = y[5];#reference initial conditions with( as.list(params), { dS <- e.S*f.S*(S + I)*R - d*S - u*f.S*S*Z # primary host dynamics dI <- u*f.S*S*Z - (d+v)*I # Infected primary host dynamics dZ <- sigma*(R/(R+Rh))*(d+v)*I - m*Z - f.S*(S+I)*Z - f.C*C*Z # Parasite dynamics dR <- r*R*(1 - R/K) - f.S*(S+I)*R -f.C*C*R # Resource dynamics dC <- e.C*f.C*C*R - d*C # Competitor dynamics res <- c(dS, dI, dZ, dR, dC) #store results list(res) } ) } #Run model to equilibrium for a set of r values times = seq(from=1, to=4000, by=1) outSIZRC = matrix(nrow=0, ncol=5) r.set = (1:100)/100 xstart = c(S = 10, I = 0, Z = 100, R=250, C=10) for(i in 1:length(r.set)){ #Specification of model parameters params = c(e.S=0.5, f.S=0.01, f.P=0.0002, d=0.05, d.P=0.01, u=1e-4, v=0.05, e.C=0.5, f.C=0.0075, sigma=1e5, Rh=20, m=0.2, r=r.set[i], K=250) #run model and store equilibrium values of each player in the model outSIZRC = rbind(outSIZRC, as.data.frame(lsoda(xstart, times, disease.web.SIZRC, params))[length(times),]) } #calculate prevalence prev = outSIZRC$I/(outSIZRC$I + outSIZRC$S) plot(r.set, prev, type="l") write.table(outSIZRC, file="outSIZRC.csv") ##### #SIZRP ##### #definition of SIZRP model disease.web.SIZRP <- function(t,y,params){ S = y[1]; I = y[2]; Z = y[3]; R = y[4]; P = y[5];#reference initial conditions with( as.list(params), { dS <- e.S*f.S*(S + I)*R - d*S - u*f.S*S*Z - f.P*P*S # primary host dynamics dI <- u*f.S*S*Z - (d+v)*I - f.P*P*I # Infected primary host dynamics dZ <- sigma*(R/(R+Rh))*(d+v)*I - m*Z - f.S*(S+I)*Z # Parasite dynamics dR <- r*R*(1 - R/K) - f.S*(S+I)*R # Resource dynamics dP <- f.P*(S + I)*P - d.P*P # Predator dynamics res <- c(dS, dI, dZ, dR, dP) #store results list(res) } ) } #Run model to equilibrium for a set of r values times = seq(from=1, to=4000, by=1) outSIZRP = matrix(nrow=0, ncol=5) r.set = (1:100)/100 for(i in 1:length(r.set)){ #Specification of model parameters params = c(e.S=0.5, f.S=0.01, f.P=0.0002, d=0.05, d.P=0.01, u=1e-4, v=0.05, e.C=0.5, f.C=0.0075, sigma=1e5, Rh=20, m=0.2, r=r.set[i], K=250) xstart = c(S = 10, I = 0, Z = 100, R=250, P=10) #run model and store equilibrium values of each player in the model outSIZRP = rbind(outSIZRP, as.data.frame(lsoda(xstart, times, disease.web.SIZRP, params))[length(times),]) } #calculate prevalence prev = outSIZRP$I/(outSIZRP$I + outSIZRP$S) plot(r.set, prev, type="l") write.table(outSIZRP, file="outSIZRP.csv") ##### #SIZRCP ##### #definition of SIZRCP model disease.web.SICZRP <- function(t,y,params){ S = y[1]; I = y[2]; C = y[3]; Z = y[4]; R = y[5]; P= y[6];#reference initial conditions with( as.list(params), { dS <- e.S*f.S*(S + I)*R - d*S - u*f.S*S*Z - f.P*P*S # primary host dynamics dI <- u*f.S*S*Z - (d+v)*I - f.P*P*I # Infected primary host dynamics dC <- e.C*f.C*C*R - d*C - f.P*P*C # Competitor dynamics dZ <- sigma*(R/(R+Rh))*(d+v)*I - m*Z - (f.S*(S+I) + f.C*C)*Z # Parasite dynamics dR <- r*R*(1 - R/K) - (f.S*(S+I) + f.C*C)*R # Resource dynamics dP <- f.P*(S + I + C)*P - d.P*P # Predator dynamics res <- c(dS, dI, dC, dZ, dR, dP) #store results list(res) } ) } #Run model to equilibrium for a set of r values times = seq(from=1, to=4000, by=1) outSICZRP = matrix(nrow=0, ncol=6) r.set = (1:100)/100 for(i in 1:length(r.set)){ #Specification of model parameters params = c(e.S=0.5, f.S=0.01, f.P=0.0002, d=0.05, d.P=0.01, u=1e-4, v=0.05, e.C=0.5, f.C=0.0075, sigma=1e5, Rh=20, m=0.2, r=r.set[i], K=250) xstart = c(S = 10, I = 0, C=10, Z = 100, R=250, P=10) #run model and store equilibrium values of each player in the model outSICZRP = rbind(outSICZRP, as.data.frame(lsoda(xstart, times, disease.web.SICZRP, params))[length(times),]) } #calculate prevalence prev = outSICZRP$I/(outSICZRP$I + outSICZRP$S) plot(r.set, prev, type="l") write.table(outSICZRP, file="outSICZRP.csv")