########################################################################### #FUNCTION FOR ONE-PHASE EXPONENIAL MODEL OF LOSS FROM THE MIXED LAYER #WITH ABRUPT INCREAE AND TERMINATION IN PRODUCTION ########################################################################### OneStateConstantTwiceTruncatedExp=function(theta){ lambda1=exp(theta) N=length(ages) first01=0 first02=(lambda1*(exp(-lambda1*TIME)-exp(-lambda1*TIMEMAX)))/lambda1 first=(1/(first01+first02)) second=lambda1*exp(-lambda1*ages) prsecond=sum(log(second)) loglik=N*log(first)+prsecond -(loglik) } ########################################################################### #FUNCTION FOR TWO-PHASE EXPONENIAL MODEL OF LOSS FROM THE MIXED LAYER #WITH ABRUPT INCREAE AND TERMINATION IN PRODUCTION ########################################################################### OneStateConstantTwiceTruncatedExpMix=function(theta){ lambda1=exp(theta[1]) lambda2=exp(theta[2]) tau=exp(theta[3]) N=length(ages) first01=(tau*(exp(-lambda2*TIME)-exp(-lambda2*TIMEMAX)))/lambda2 first02=((lambda1-lambda2)*(exp(-(tau+lambda1)*TIME)-exp(-(tau+lambda1)*TIMEMAX)))/(tau+lambda1) #first01=ifelse(first01>0,first01,10e-50) #first02=ifelse(first02>0,first02,10e-50) first=(1/(first01+first02)) second=(tau*exp(-lambda2*ages) + (lambda1-lambda2)*exp(-(tau+lambda1)*ages)) #second=ifelse(second>0,second,10e-50) prsecond=sum(log(second)) loglik=N*log(first)+prsecond if (lambda2>=(lambda1)) {loglik=-100000} -(loglik) } ##################################################################################### #REQUIRED PACKAGES ##################################################################################### require(msm) require(TruncatedDistributions) require(gridBase) require(modeest) require(grid) ##################################################################################### #OTHER FUNCTIONS FOR BOOTSTRAP AND HISTOGRAM bootcimode<-function(temp) { x.resample<-numeric(); xmode.resample<-numeric(); for (i in 1:1000) { for (j in 1:length(temp)) {x.resample[j]<-sample(temp,1,replace=T)} xmode.resample[i]<-mlv(x.resample, method = "hsm", bw=0.1)$M } out=list(resamplemode=xmode.resample) out } horiz.hist <- function(Data, breaks="Sturges", col="transparent", las=1, ylim=range(HBreaks), labelat=pretty(ylim), labels=labelat, border=par("fg"), ... ) {a <- hist(Data, plot=FALSE, breaks=breaks) HBreaks <- a$breaks HBreak1 <- a$breaks[1] hpos <<- function(Pos) (Pos-HBreak1)*(length(HBreaks)-1)/ diff(range(HBreaks)) barplot(a$counts, space=0, horiz=T, ylim=hpos(ylim), col=col, border=border,...) axis(2, at=hpos(labelat), labels=labels, las=las, ...) print("use hpos() to address y-coordinates") } ###################################################################################################################################################### #VECTOR WITH POSTMORTEM AGES FROM AAR CALIBRATED BY RADIOCARBON ageLaqueusSCB=c(108,164,4623,182,380,269,211,471,405,269,4708,168,211,943,4068,339,2969,4832,217,1465,136, 250,128,1417,147,228,461,155,302,159,222,118,1015,222,155,4014,1846,1568,222,3385,256, 1214,2759,723,1300,461,738,461,6179,2236,5800,1417,233,979,461,797,177,405,143,263,239, 155,168,196,317,115,121,132,186,738,355,105,177,115,132,244,168,201,206,211,1072, 481,288,159,217,182,159,710,355,324,461,943,275,191,233,217,196,220,155,147,452, 186,172,2488,1974,1137,228,1227,196,132,397,151,524,414,228,159,347,2925,324,7089,7622, 2137,442,172,581,1111,1417,617,1489,164,1214,2341,1192,683,828,546,1595,405,1675,630,2005, 3901,5874,182,2718,339,442,683,4122,6416,5800,3688,388,324,1489,452,535,3846,843,1621,2527, 1758,960,1130,1893,1788,1846,2203,1072,1940,2236,2203,8423,875,1702,8482,943,8472,2137,1130,1541, 1393,960,1111,1256,1465,1072,3194,2104,9431) #SITE ASSIGNMENTS OF SHELLS: 4134 - WESTERN PALOS VERDES SHELF (2003), #OC - WESTERN PALOS VERDES SHELF (2008), 10C - EASTERN PALOS VERDES SHELF (2008 AND 2009), 24205 - SANTA MONICA BAY (1975) site=c("4134","4134","4134","4134","4134","4134","4134","4134","4134","4134","4134","4134","4134", "4134","4134","4134","4134","4134","4134","4134","4134","4134","4134","4134","4134","4134", "4134","4134","4134","4134","4134","4134","4134","4134","4134","4134","4134","4134","4134", "10C", "10C", "10C", "10C", "10C", "10C", "10C", "10C", "10C", "10C", "10C", "10C", "10C", "10C", "10C", "10C", "10C", "0C","0C","0C","0C","0C","0C","0C","0C","0C", "0C","0C","0C","0C","0C","0C","0C","0C","0C","0C","0C","0C","0C", "0C","0C","0C","0C","0C","0C","0C","0C","0C","0C","0C","0C","0C", "0C","0C","0C","0C","0C","0C","0C","0C","0C","0C","0C","0C","0C", "0C","0C","0C","0C","0C","0C","0C","0C","0C","0C","0C","0C","10C", "10C","10C","10C","10C","10C","10C","10C","10C","10C","10C","10C","10C","10C", "10C","10C","10C","10C","10C","10C","10C","10C","10C","10C","10C","10C","10C", "10C","10C","10C","10C","10C","10C","10C","10C","10C","10C","10C","10C","10C", "10C","10C","10C","24205","24205","24205","24205","24205","24205","24205","24205","24205","24205", "24205","24205","24205","24205","24205","24205","24205","24205","24205","24205","24205","24205","24205", "24205","24205","24205","24205","24205","24205","24205","24205") #logged standard deviation from calibration (for lognormal ucertainty) ln.d=-2.291966 ###################################################################################################################################################### #REGIONAL LAQUEUS HISTOGRAM FIGURE ###################################################################################################################################################### BREAKS=100 mode.est=quantile(bootcimode(ageLaqueusSCB)$resamplemode, c(0.025,0.5,0.975)) mlv(ageLaqueusSCB, method="hsm", bw=0.1) par(mfrow=c(2,2)) par(mar=c(10,4,2,1)) out1=hist(ageLaqueusSCB, breaks=c(0,seq(13,10000,by=BREAKS)), col="gray", ylim=c(0,50), main="", freq=T, xlab="Shell age (years before 2013)", ylab="Number of specimens", cex.axis=1) mode.est range(ageLaqueusSCB) INSET=TRUE if (INSET==TRUE) { vp <- baseViewports() pushViewport(vp$inner,vp$figure,vp$plot) pushViewport(viewport(x=0.25,y=0.99,width=0.7,height=0.7,just=c("left","top"))) par(plt=gridPLT(),new=T) grid.rect(gp=gpar(lwd=1,col="black")) breaks2=c(0,seq(13,1000,by=25)); smallage<-ageLaqueusSCB[ageLaqueusSCB1000], breaks=seq(1000,2020,by=25), col="gray", ylab="", xlab="Number of specimens", xlim=c(0,15)) mode.est range(ageLaqueusSCB) plot(Laqueus.25.means[scale.25<1000], -scale.25[scale.25<1000], xlab="Abundance (25 year cohorts)", type="n", frame.plot=FALSE,ylab="Time (years)",pch=16, log="", xlim=c(0,40), ylim=c(-1000,0)) lines(Laqueus.25.means[scale.25<1000], -scale.25[scale.25<1000], lwd=3) lines(Laqueus.25.025[scale.25<1000],-scale.25[scale.25<1000], lty=2) lines(Laqueus.25.975[scale.25<1000],-scale.25[scale.25<1000], lty=2) scale.25[which.max(Laqueus.25.means)] VECTOR=seq(12.5,9987.5,by=25) invsurv=Laqueus.25.means/exp(-0.002*seq(12.5,9987.5,by=25)) invsurv=Laqueus.25.means/(temp.alpha*exp(-temp.lambda2*VECTOR)+(1-temp.alpha)*exp(-(temp.tau+temp.lambda1)*VECTOR)) seg.UCI=Laqueus.25.025/(temp.alpha*exp(-temp.lambda2*VECTOR)+(1-temp.alpha)*exp(-(temp.tau+temp.lambda1)*VECTOR)) seg.LCI=Laqueus.25.975/(temp.alpha*exp(-temp.lambda2*VECTOR)+(1-temp.alpha)*exp(-(temp.tau+temp.lambda1)*VECTOR)) lines(invsurv[scale.25<1000], -scale.25[scale.25<1000], col="gray", lwd=3) lines(seg.LCI[scale.25<1000],-scale.25[scale.25<1000], lty=2, col="gray") lines(seg.UCI[scale.25<1000],-scale.25[scale.25<1000], lty=2, col="gray") legend(x="topright",lwd=c(3,3), col=c("black","gray"),legend=c("Preserved","Reconstructed"), bty="n") ############################################################################################## #FIGURE HISTOGRAM VS RECONSTRUCTED IN ONE FIGURE AND LIFESPAN TO STANDING DENSITY ############################################################################################## AD.ageLaqueusSCB=2013-ageLaqueusSCB par(mfrow=c(1,4)) par(mar=c(25,4,4,0)) out=horiz.hist(AD.ageLaqueusSCB[AD.ageLaqueusSCB>1400], breaks=seq(1400,2020,by=25), col="gray", ylab="", xlab="Number of specimens", xlim=c(0,40), ylim=c(1400,2020)) out=hist(AD.ageLaqueusSCB[AD.ageLaqueusSCB>1400], breaks=seq(1400,2020,by=25), plot=F) par(new=T) plot(Laqueus.25.means[scale.25<600], 2013-scale.25[scale.25<600], xlab="", type="l", ylab="", frame.plot=FALSE, xlim=c(0,40), ylim=c(1400,2020), yaxt="n", xaxt="n") lines(Laqueus.25.means[scale.25<1000], 2013-scale.25[scale.25<1000], lwd=3, col="gray41") lines(Laqueus.25.025[scale.25<1000],2013-scale.25[scale.25<1000], lty=2, col="gray41") lines(Laqueus.25.975[scale.25<1000],2013-scale.25[scale.25<1000], lty=2, col="gray41") scale.25[which.max(Laqueus.25.means)] VECTOR=seq(12.5,9987.5,by=25) invsurv=Laqueus.25.means/exp(-0.002*seq(12.5,9987.5,by=25)) invsurv=Laqueus.25.means/(temp.alpha*exp(-temp.lambda2*VECTOR)+(1-temp.alpha)*exp(-(temp.tau+temp.lambda1)*VECTOR)) seg.UCI=Laqueus.25.025/(temp.alpha*exp(-temp.lambda2*VECTOR)+(1-temp.alpha)*exp(-(temp.tau+temp.lambda1)*VECTOR)) seg.LCI=Laqueus.25.975/(temp.alpha*exp(-temp.lambda2*VECTOR)+(1-temp.alpha)*exp(-(temp.tau+temp.lambda1)*VECTOR)) lines(invsurv[scale.25<1000], 2013-scale.25[scale.25<1000], col="black", lwd=3) lines(seg.LCI[scale.25<1000],2013-scale.25[scale.25<1000], lty=2, col="black") lines(seg.UCI[scale.25<1000],2013-scale.25[scale.25<1000], lty=2, col="black") legend(x="topright",lwd=c(3,3), col=c("black","gray"),legend=c("Preserved","Reconstructed"), bty="n") #LIFESPAN #total area = 0.5 m2, i.e., five grabs, therefore, multiply by 2 to get individuals/m2 #lifespan of Laqueus = 12 years, abundance is per 25 year cohort, therefore 25/12 = 2.08, divide by 2.08 to get abundance per year #finally, if all pedicle and brachial valves would be counted, the number should be divided by two because each individual consist of two valves #we use 1.3 rather than 2 because in some samples, just one type of valves was dated axis(3,at=c(0,20,40),labels= round(c(0,20,40)*2/2.08/1.3)) (invsurv[scale.25<600]*2)/2.08/1.3