## R functions for computing age-depth model following Colombaroli et al. (2018) ## Example usage of these functions is in code in file silt-model-workflow-R.txt ## Colombaroli, D., Gavin, D.G., Morey, A.E. & Thorndycraft, V.R. ## High resolution lake sediment record reveals self-organized criticality in erosion ## processes regulated by internal feedbacks. EARTH SURFACE PROCESSES AND LANDFORMS 43, ## 2181–2192 (2018). require(compiler) ## Function silt.model This function is called by the "optimize" function, to compute ## optimal value of crit.s. See code in silt-model-workflow-R.txt # crit.s value to be optimized to minimize residuals of straight-line fit between age control points # and effective depths # sval vector of proxy values for silt content of sediment. Could be density, magnetic # susceptibility, or grayscale color. Ordered from core top to base at equal depth intervals. # min.s single value of minimum sval corresponding to 0% silt content # date.dep vector of depths of age control points, as indices of the sval vector. # date.age vector of ages of age control points silt.model <- function(crit.s,sval,min.s,date.dep,date.age){ len<-length(sval) theta.est<-array(NA,len) ed<-array(NA,len) for(i in 1:len){ theta.est[i]<-1-min(1,((sval[i]-min.s)/(crit.s-min.s))) } for(i in 1:len){ ed[i]<-sum(theta.est[1:i]) } fit<-lm(date.age~ed[date.dep]) return(sum(fit$residuals^2)) } silt.model.c<-cmpfun(silt.model) #### Monotonic spline functions. Unpublished algorithm by CJC Kruger. # For given sequence of control points (depths (depths) and ages (ag)), # provide the ages at a sequence of depths (depthseq) using constrained cubic spline # interpolation. dxx <- function(x1,x0){ dx <- x1-x0 if(dx == 0) dx <- 10^30 return(dx) } # monspline2 = fit one depth monspline2<-function(x,ag,depths) { gxx<-array(NA,2); ggxx<-array(NA,2) Nmax <- length(depths) #(1a) Find LineNumber or segment. Linear extrapolate if outside range. Num <- 1 if(xdepths[Nmax]){ if(x