#Code will calculate matrices for fixed temperatures (Temp) and copepodid attachment rates (CopAttach). Mean values for R0, generation time, lambda, sensitivity, elasticity, and stable stage distributions rm(list = ls()) #clear values in workspac ###WILL CLEAR EVERYTHING, BE CAREFUL IF YOU HAVE OTHER WORK OPEN### #setwd() #set to your working directory. Be sure that sourced files (S6 and S8) are in the same directory require(abind) #install if you do not have this #Set parameters (Attachment rate and temperature to desired value) CopAttach<-0.001 Temp=4 Iterations=998 #number of matrices calculated-2 source('S6_Sea_Lice_Parameters.R') #loads parameters source('S8_Sea_Lice_A.R') #calculates matrix A=as.array(A) L<-list(A) source('S6_Sea_Lice_Parameters.R') #loads parameters source('S8_Sea_Lice_A.R') #calculates matrix L<-c(L, list(A)) ##Alist<-abind(Alist, A, rev.along=0) for (i in 1:Iterations){ source('S6_Sea_Lice_Parameters.R') #loads parameters source('S8_Sea_Lice_A.R') #calculates matrix L<-c(L, list(A)) } #Matrix quantiles m<-mean(L) mv<-var2(L) #Elasticities elastTimes<-lapply(L, elasticity) em<-mean(elastTimes)#matrix of elasticity means ev<-var2(elastTimes)#matrix of elasticity variances #Sensitivity SensiTimes<-lapply(L, sensitivity) sm<-mean(SensiTimes) #matrix of sensitivity means sv<-var2(SensiTimes) #matrix of sensitivity variances #Lambda y<-sapply(L, lambda) mean(y) quantile( y, c(0.025, .975) ) #95% confidence interval for lambda ##Histogram of Lambda hist(y, br=30, col="palegreen", xlab="Lambda", main=paste('Estimates of Lambda at Temp=', Temp)) abline(v=quantile(y, c(0.025, .975)), lty=3) #Generation times y<-sapply(L, generation.time) mean(y) quantile( y, c(0.025, .975) ) #95% confidence interval #Histogram of generation times hist(y, br=30, col="palegreen", xlab="Generation Time", main=paste('Estimates of Generation Time at Temp=', Temp)) abline(v=quantile(y, c(0.025, .975)), lty=3) #Net Reproductive Rate y<-sapply(L, net.reproductive.rate) mean(y) quantile( y, c(0.025, .975) ) #95% confidence interval #stable stage distribution y<-sapply(L,stable.stage) ssmean<-rowMeans(y) low95<-rowQuantiles(y, probs=0.025) upper95<-rowQuantiles(y, probs=0.975) data.matrix(ssmean) data.matrix(low95) data.matrix(upper95) #population projection (Will project population for 100 days. Population begins with 10 copepodids) n<-(c(0, 10, 0, 0, 0, 0, 0)) p<-pop.projection(A,n,100) stage.vector.plot(p$stage.vector[,1:100], xlab="Days", main=paste('Projection over time at temp =', Temp, ', larval attachment =', CopAttach), tck=0.01)