#### Supplementary information – Megalodon extinction code ## clear the memory rm(list=ls()) library(raster) ddf<-read.csv("~/Desktop/Meg Supp Inf/meg.data.csv") dd<-na.omit(ddf) ## optimal linear estimation function OLE <- function(data, alpha){ ## sort the data sights <- rev(sort(data)) ## calculate the number of sightings (in this case the number of fossil finds) k <- length(sights) ## v <- (1/(k-1)) * sum(log((sights[1] - sights[k])/(sights[1] - sights[2:(k-1)]))) ## e <- matrix(rep(1,k), ncol=1) SL<-(-log(1-alpha/2)/length(sights))^-v SU<-(-log(alpha/2)/length(sights))^-v myfun <- function(i,j,v){(gamma(2*v+i)*gamma(v+j))/(gamma(v+i)*gamma(j))} lambda <- outer(1:k, 1:k, myfun, v=v) lambda <- ifelse(lower.tri(lambda), lambda, t(lambda)) # make symmetric a <- as.vector(solve(t(e)%*%solve(lambda)%*%e)) * solve(lambda)%*%e ## calculate the lower confidence interval lowerCI<-max(sights) + ((max(sights)-min(sights))/(SL-1)) ## calculate the upper confidence interval upperCI<-max(sights) + ((max(sights)-min(sights))/(SU-1)) ## calculates the time of extinction extest<-sum(t(a)%*%sights) ## put the results into a data from res<-data.frame(Estimate=extest, lowerCI=lowerCI, upperCI=upperCI) ##return the results return(res) } ### number of simulations sims<-seq(1:10000) save.res<-NULL for(i in 1:length(sims)){ ## incorporate uncertainty by drawing dates used in the calculation from a uniform distribution error.dates<-runif(length(dd$Ma_max), dd$Ma_min, dd$Ma_max) ##normalise the dates to increasing values norm.dates<-sort(max(dd$Ma_max)-error.dates) ## calculate extinction times res<-OLE(norm.dates, 0.05) ##revert data to decreasing values and save results save.res[[i]]<-max(dd$Ma_max)-as.numeric(res[1]) } ## the modal data extinction mode.ext<-modal(round(save.res,5)) mode.ext ## the earliest date of extinction min.ext<-min(save.res) min.ext ## the latest date of extinction max.ext<-max(save.res) max.ext