From noreply at r-forge.r-project.org Wed Dec 12 22:23:52 2018 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 12 Dec 2018 22:23:52 +0100 (CET) Subject: [Dplr-commits] r1136 - in pkg/dplR: . R man Message-ID: <20181212212352.D4C0E18BDED@r-forge.r-project.org> Author: andybunn Date: 2018-12-12 22:23:51 +0100 (Wed, 12 Dec 2018) New Revision: 1136 Modified: pkg/dplR/ChangeLog pkg/dplR/DESCRIPTION pkg/dplR/R/ccf.series.rwl.R pkg/dplR/man/ccf.series.rwl.Rd Log: adding arg to ccf.series.rwl Modified: pkg/dplR/ChangeLog =================================================================== --- pkg/dplR/ChangeLog 2018-11-08 20:14:01 UTC (rev 1135) +++ pkg/dplR/ChangeLog 2018-12-12 21:23:51 UTC (rev 1136) @@ -1,5 +1,11 @@ * CHANGES IN dplR VERSION 1.7.0 +File: ccf.series.rwl.R and .Rd +---------------- + +- Added new argument to allow user to specify whether a series or master gets + passed to ccf as x. The convention was screwy. + File: xdate.floater.R and .Rd ---------------- Modified: pkg/dplR/DESCRIPTION =================================================================== --- pkg/dplR/DESCRIPTION 2018-11-08 20:14:01 UTC (rev 1135) +++ pkg/dplR/DESCRIPTION 2018-12-12 21:23:51 UTC (rev 1136) @@ -3,7 +3,7 @@ Type: Package Title: Dendrochronology Program Library in R Version: 1.7.0 -Date: 2018-11-03 +Date: 2018-12-12 Authors at R: c(person("Andy", "Bunn", role = c("aut", "cph", "cre", "trl"), email = "andy.bunn at wwu.edu"), person("Mikko", "Korpela", role = c("aut", "cph", "trl")), person("Franco", "Biondi", Modified: pkg/dplR/R/ccf.series.rwl.R =================================================================== --- pkg/dplR/R/ccf.series.rwl.R 2018-11-08 20:14:01 UTC (rev 1135) +++ pkg/dplR/R/ccf.series.rwl.R 2018-12-12 21:23:51 UTC (rev 1136) @@ -3,7 +3,7 @@ seg.length = 50, bin.floor = 100, n = NULL, prewhiten = TRUE, biweight = TRUE, pcrit = 0.05, lag.max = 5, make.plot = TRUE, - floor.plus1 = FALSE, ...) { + floor.plus1 = FALSE, series.x, ...) { ## Handle different types of 'series' tmp <- pick.rwl.series(rwl, series, series.yrs) @@ -79,8 +79,15 @@ bin.ccf <- NA } else { - tmp <- ccf(series2[mask], master[mask], lag.max=lag.max, + if(series.x){ + tmp <- ccf(x = series2[mask], y = master[mask], lag.max=lag.max, + plot=FALSE) + } + else { + tmp <- ccf(x = master[mask], y = series2[mask], lag.max=lag.max, plot=FALSE) + } + bin.ccf <- as.vector(tmp$acf) } res.cor[, j] <- bin.ccf Modified: pkg/dplR/man/ccf.series.rwl.Rd =================================================================== --- pkg/dplR/man/ccf.series.rwl.Rd 2018-11-08 20:14:01 UTC (rev 1135) +++ pkg/dplR/man/ccf.series.rwl.Rd 2018-12-12 21:23:51 UTC (rev 1136) @@ -11,7 +11,7 @@ seg.length = 50, bin.floor = 100, n = NULL, prewhiten = TRUE, biweight = TRUE, pcrit = 0.05, lag.max = 5, make.plot = TRUE, - floor.plus1 = FALSE, \dots) + floor.plus1 = FALSE, series.x = FALSE, \dots) } \arguments{ \item{rwl}{ a \code{data.frame} with series as columns and years as rows @@ -46,6 +46,8 @@ \item{floor.plus1}{ \code{logical} flag. If \code{TRUE}, one year is added to the base location of the first segment (e.g., 1601, 1701, 1801 \acronym{AD}). } + \item{series.x}{ \code{logical} flag indicating whether to make the \code{series} + the \code{x} argument to \code{\link{ccf}}. See Details. } \item{\dots}{ other arguments passed to plot. } } \details{ @@ -59,12 +61,13 @@ The cross correlations are calculated calling \code{\link{ccf}} as \cr - \code{ccf(x=series, y=master, lag.max=lag.max, plot=FALSE)}. Note that - prior to dplR version 1.60, the \code{master} was set as \code{x} and - the \code{series} as \code{y}. This was changed to be more in line with - user expectations so that a missing ring in a series produces a positive - lag in the plot rather than a negative lag. This structure of this call - does put the plots at odds with Figure 3 in Bunn (2010) which is unfortunate. + \code{ccf(x=master, y=series, lag.max=lag.max, plot=FALSE)} if \code{series.x} is + \code{FALSE} and as \code{ccf(x=series, y=master, lag.max=lag.max, plot=FALSE)} if + \code{series.x} is \code{TRUE}. This argument was introduced in dplR version 1.7.0. + + Different users have different expectations about how missing or extra rings are + notated. If \code{switch.x = FALSE} the behavior will be like COFECHA where a missing + ring in a series produces a negative lag in the plot rather than a positive lag. Correlations are calculated for the first segment, then the second segment and so on. Correlations are only calculated for segments with From noreply at r-forge.r-project.org Thu Dec 13 00:34:52 2018 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 13 Dec 2018 00:34:52 +0100 (CET) Subject: [Dplr-commits] r1137 - in pkg/dplR: . R man vignettes Message-ID: <20181212233452.29A2418BEB6@r-forge.r-project.org> Author: andybunn Date: 2018-12-13 00:34:51 +0100 (Thu, 13 Dec 2018) New Revision: 1137 Modified: pkg/dplR/ChangeLog pkg/dplR/R/ccf.series.rwl.R pkg/dplR/R/xdate.floater.R pkg/dplR/R/xskel.ccf.plot.R pkg/dplR/man/ccf.series.rwl.Rd pkg/dplR/man/xdate.floater.Rd pkg/dplR/man/xskel.ccf.plot.Rd pkg/dplR/vignettes/xdate-dplR.Rnw Log: more ccf changes. Modified: pkg/dplR/ChangeLog =================================================================== --- pkg/dplR/ChangeLog 2018-12-12 21:23:51 UTC (rev 1136) +++ pkg/dplR/ChangeLog 2018-12-12 23:34:51 UTC (rev 1137) @@ -1,5 +1,16 @@ * CHANGES IN dplR VERSION 1.7.0 +File: xdate-dplR.Rnw +---------------- + +- Rewritten to explain new args in ccf. + +File: xskel.ccf.plot.R and .Rd +---------------- + +- Added new argument to allow user to specify whether a series or master gets + passed to ccf as x. The convention was screwy. + File: ccf.series.rwl.R and .Rd ---------------- Modified: pkg/dplR/R/ccf.series.rwl.R =================================================================== --- pkg/dplR/R/ccf.series.rwl.R 2018-12-12 21:23:51 UTC (rev 1136) +++ pkg/dplR/R/ccf.series.rwl.R 2018-12-12 23:34:51 UTC (rev 1137) @@ -3,7 +3,7 @@ seg.length = 50, bin.floor = 100, n = NULL, prewhiten = TRUE, biweight = TRUE, pcrit = 0.05, lag.max = 5, make.plot = TRUE, - floor.plus1 = FALSE, series.x, ...) { + floor.plus1 = FALSE, series.x = FALSE, ...) { ## Handle different types of 'series' tmp <- pick.rwl.series(rwl, series, series.yrs) Modified: pkg/dplR/R/xdate.floater.R =================================================================== --- pkg/dplR/R/xdate.floater.R 2018-12-12 21:23:51 UTC (rev 1136) +++ pkg/dplR/R/xdate.floater.R 2018-12-12 23:34:51 UTC (rev 1137) @@ -1,9 +1,7 @@ -xdate.floater <- function(rwl, series, series.name = NULL, min.overlap=50, n=NULL,prewhiten = TRUE, biweight=TRUE, +xdate.floater <- function(rwl, series, series.name = "Unk", min.overlap=50, n=NULL,prewhiten = TRUE, biweight=TRUE, method = c("spearman", "pearson", "kendall"), make.plot = TRUE, return.rwl = FALSE, verbose = TRUE) { - - if(is.null(series.name)){ series.name <- "Unk" } method2 <- match.arg(method) # Trim series in case it has NA (e.g., submitted stright from the rwl) idx.good <- !is.na(series) Modified: pkg/dplR/R/xskel.ccf.plot.R =================================================================== --- pkg/dplR/R/xskel.ccf.plot.R 2018-12-12 21:23:51 UTC (rev 1136) +++ pkg/dplR/R/xskel.ccf.plot.R 2018-12-12 23:34:51 UTC (rev 1137) @@ -1,6 +1,6 @@ xskel.ccf.plot <- function(rwl,series,series.yrs = as.numeric(names(series)), win.start, win.width=50, n = NULL, prewhiten = TRUE, - biweight = TRUE) { + biweight = TRUE, series.x = FALSE) { ## check to see that win.width is even if(as.logical(win.width %% 2)) stop("'win.width' must be even") if (win.width > 100) { @@ -81,8 +81,14 @@ ## ccf - ccf.early <- as.vector(ccf(x=series.early,y=master.early,lag.max=5,plot=FALSE)$acf) - ccf.late <- as.vector(ccf(x=series.late,y=master.late,lag.max=5,plot=FALSE)$acf) + if(series.x){ + ccf.early <- as.vector(ccf(x=series.early,y=master.early,lag.max=5,plot=FALSE)$acf) + ccf.late <- as.vector(ccf(x=series.late,y=master.late,lag.max=5,plot=FALSE)$acf) + } + else{ + ccf.early <- as.vector(ccf(x=master.early,y=series.early,lag.max=5,plot=FALSE)$acf) + ccf.late <- as.vector(ccf(x=master.late,y=series.late,lag.max=5,plot=FALSE)$acf) + } pcrit=0.05 sig <- qnorm(1 - pcrit / 2) / sqrt(length(master.early)) sig <- c(-sig, sig) Modified: pkg/dplR/man/ccf.series.rwl.Rd =================================================================== --- pkg/dplR/man/ccf.series.rwl.Rd 2018-12-12 21:23:51 UTC (rev 1136) +++ pkg/dplR/man/ccf.series.rwl.Rd 2018-12-12 23:34:51 UTC (rev 1137) @@ -64,10 +64,10 @@ \code{ccf(x=master, y=series, lag.max=lag.max, plot=FALSE)} if \code{series.x} is \code{FALSE} and as \code{ccf(x=series, y=master, lag.max=lag.max, plot=FALSE)} if \code{series.x} is \code{TRUE}. This argument was introduced in dplR version 1.7.0. - Different users have different expectations about how missing or extra rings are notated. If \code{switch.x = FALSE} the behavior will be like COFECHA where a missing - ring in a series produces a negative lag in the plot rather than a positive lag. + ring in a series produces a negative lag in the plot rather than a positive lag. See the + crossdating vignette \code{xdate-dplR}for more information. Correlations are calculated for the first segment, then the second segment and so on. Correlations are only calculated for segments with Modified: pkg/dplR/man/xdate.floater.Rd =================================================================== --- pkg/dplR/man/xdate.floater.Rd 2018-12-12 21:23:51 UTC (rev 1136) +++ pkg/dplR/man/xdate.floater.Rd 2018-12-12 23:34:51 UTC (rev 1137) @@ -6,7 +6,7 @@ Pulls an undated series through a dated rwl file in order to try to establish dates } \usage{ -xdate.floater(rwl, series, min.overlap = 50, series.name = NULL, n = NULL, +xdate.floater(rwl, series, series.name = "Unk", min.overlap = 50, n = NULL, prewhiten = TRUE, biweight = TRUE, method = c("spearman", "pearson","kendall"), make.plot = TRUE,return.rwl = FALSE, verbose = TRUE) @@ -16,6 +16,7 @@ rows such as that produced by \code{\link{read.rwl}}. } \item{series}{ a \code{data.frame} with series as columns and years as rows such as that produced by \code{\link{read.rwl}}. } + \item{series.name}{ a \code{character} giving a name for the series. } \item{min.overlap}{ number } \item{n}{ \code{NULL} or an integral value giving the filter length for the \code{\link{hanning}} filter used for removal of low Modified: pkg/dplR/man/xskel.ccf.plot.Rd =================================================================== --- pkg/dplR/man/xskel.ccf.plot.Rd 2018-12-12 21:23:51 UTC (rev 1136) +++ pkg/dplR/man/xskel.ccf.plot.Rd 2018-12-12 23:34:51 UTC (rev 1137) @@ -8,7 +8,7 @@ \usage{ xskel.ccf.plot(rwl, series, series.yrs = as.numeric(names(series)), win.start, win.width = 50, n = NULL, - prewhiten = TRUE, biweight = TRUE) + prewhiten = TRUE, biweight = TRUE, series.x=FALSE) } \arguments{ \item{rwl}{ a \code{data.frame} with series as columns and years as rows @@ -30,6 +30,9 @@ whitened using \code{\link{ar}}. } \item{biweight}{ \code{logical} flag. If \code{TRUE} then a robust mean is calculated using \code{\link{tbrm}}. } + \item{series.x}{ \code{logical} flag indicating whether to make the \code{series} + the \code{x} argument to \code{\link{ccf}}. See Details. } + } \details{ This function produces a plot that is a mix of a skeleton plot and a @@ -48,8 +51,18 @@ years the percentage would be 100\%. The bottom panels show cross correlations for the first half (left) - and second half of the time series using function \code{\link{ccf}} as - \code{ccf(x=series,y=master,lag.max=5)}. + and second half of the time series using function \code{\link{ccf}}. + + The cross correlations are calculated calling + \code{\link{ccf}} as \cr + \code{ccf(x=master, y=series, lag.max=lag.max, plot=FALSE)} if \code{series.x} is + \code{FALSE} and as \code{ccf(x=series, y=master, lag.max=lag.max, plot=FALSE)} if + \code{series.x} is \code{TRUE}. This argument was introduced in dplR version 1.7.0. + Different users have different expectations about how missing or extra rings are + notated. If \code{switch.x = FALSE} the behavior will be like COFECHA where a missing + ring in a series produces a negative lag in the plot rather than a positive lag. See the + crossdating vignette \code{xdate-dplR}for more information. + The plot is built using the \link[grid]{Grid} package which allows for great flexibility in building complicated plots. However, Modified: pkg/dplR/vignettes/xdate-dplR.Rnw =================================================================== --- pkg/dplR/vignettes/xdate-dplR.Rnw 2018-12-12 21:23:51 UTC (rev 1136) +++ pkg/dplR/vignettes/xdate-dplR.Rnw 2018-12-12 23:34:51 UTC (rev 1137) @@ -198,25 +198,27 @@ \caption{Cross-correlations between series \code{643114} and the master chronology are shown for each segment (30-year segments lagged by 15 years). The series correlates well at lag 0 until the 1865--1894 bin and then at -lag +1 prior to 1865.} +lag -1 prior to 1865.} \label{fig:ccf.plot} \end{figure} Figure~\ref{fig:ccf.plot} shows that 1865 to 1894 is the misdated part of -this series. The lag of +1 over a lag of 0 indicates that the series +this series. The lag of -1 over a lag of 0 indicates that the series \code{643114} is missing a ring as it better correlates to the master -chronology with a one-year offset. \footnote{As of dplR version 1.60, -the cross correlations in \code{ccf.series.rwl} are calculated calling -\code{ccf(x=series, y=master, lag.max=lag.max, plot=FALSE)}. Note that -prior to dplR version 1.60, the \code{master} was set as \code{x} and -the \code{series} as \code{y}. This was changed to be more in line with -user expectations so that a missing ring in a series produces a positive -lag in the plot rather than a negative lag. This structure of this call -does put the plots at odds with Figure 3 in \cite{Bunn2010} which is -unfortunate.} +chronology with a one-year offset. \footnote{As of dplR version 1.7.0, +the cross correlations in \code{ccf.series.rwl} can be calculated calling +\code{ccf(x=series, y=master, lag.max=lag.max, plot=FALSE)} if \code{series.x = TRUE}. +Otherwise, the function is called \code{ccf(x=master, y=series, lag.max=lag.max, plot=FALSE)}. +Note that prior to dplR version 1.60 the behavior of the function was to have +\code{series.x = FALSE} so that \code{master} was always set as \code{x} and +the \code{series} as \code{y}. From versions 1.6.0 to 1.6.9 the \code{x} and \code{y} +arguments were reversed to be more in line with (some) user expectations that a missing +ring in a series would produce a positive lag in the plot rather than a negative lag. +This structure of calling the function this was does put the plots at odds with Figure 3 +in \cite{Bunn2010} and with the text output from COFECHA. Thus, in true splitting the baby fashion, the argument \code{series.x} was introduced in version 1.7.0 making sure that everybody will be confused.} Using a smaller time window and shorter correlation segments we -can try to further isolate the switch from correlation at lag 0 to lag +1. +can try to further isolate the switch from correlation at lag 0 to lag -1. We will, of course, have to be very careful about using such short segments for correlation and be ready to adjust our expectations accordingly. Fortunately, in this case the trees are so exquisitely sensitive that we can @@ -238,7 +240,7 @@ \end{figure} By 1879 the correlation between series \code{643114} and the master is solidly at -lag +1 (Figure~\ref{fig:ccf.plot2}). The 1870 to 1889 correlation is marginal +lag -1 (Figure~\ref{fig:ccf.plot2}). The 1870 to 1889 correlation is marginal while the dating at 1880--1899 seems accurate (lag 0). This suggests that the dating error is between 1879 and 1889. @@ -266,7 +268,7 @@ of agreement between the skeleton bars for the series and master. The bottom panels show cross correlations for the first half (left) and second half of the time series. In this case, the early period (1865--1884) shows a mismatch -of the skeleton plot by one year coupled with a strong lag +1 correlation. } +of the skeleton plot by one year coupled with a strong lag -1 correlation. } \label{fig:ccf.skel.plot} \end{figure} From noreply at r-forge.r-project.org Thu Dec 13 18:51:53 2018 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 13 Dec 2018 18:51:53 +0100 (CET) Subject: [Dplr-commits] r1138 - pkg/dplR/R Message-ID: <20181213175153.2573D18BEFF@r-forge.r-project.org> Author: andybunn Date: 2018-12-13 18:51:52 +0100 (Thu, 13 Dec 2018) New Revision: 1138 Modified: pkg/dplR/R/ccf.series.rwl.R pkg/dplR/R/xskel.ccf.plot.R Log: tidying up the ccf changes by adding text to plots. Modified: pkg/dplR/R/ccf.series.rwl.R =================================================================== --- pkg/dplR/R/ccf.series.rwl.R 2018-12-12 23:34:51 UTC (rev 1137) +++ pkg/dplR/R/ccf.series.rwl.R 2018-12-13 17:51:52 UTC (rev 1138) @@ -5,6 +5,10 @@ pcrit = 0.05, lag.max = 5, make.plot = TRUE, floor.plus1 = FALSE, series.x = FALSE, ...) { + series.x.txt <- ifelse(series.x, + "NB: With series.x = TRUE, postive lags indicate missing rings in series", + "NB: With series.x = FALSE (default), negative lags indicate missing rings in series") + cat(series.x.txt) ## Handle different types of 'series' tmp <- pick.rwl.series(rwl, series, series.yrs) rwl2 <- tmp[[1]] @@ -135,8 +139,13 @@ panel.dotplot(x, y, col = col, fill=bg, pch=21,...) }, ...) + if(series.x) { ccf.plot <- update(ccf.plot, sub=series.x.txt) } + else { ccf.plot <- update(ccf.plot, sub=series.x.txt) } trellis.par.set(strip.background = list(col = "transparent"), - warn = FALSE) + warn = FALSE, + par.sub.text = list(font = 1, cex=0.75, + just = "left", + x = grid::unit(5, "mm"))) print(ccf.plot) } res <- list(res.cor,bins) Modified: pkg/dplR/R/xskel.ccf.plot.R =================================================================== --- pkg/dplR/R/xskel.ccf.plot.R 2018-12-12 23:34:51 UTC (rev 1137) +++ pkg/dplR/R/xskel.ccf.plot.R 2018-12-13 17:51:52 UTC (rev 1138) @@ -1,6 +1,7 @@ xskel.ccf.plot <- function(rwl,series,series.yrs = as.numeric(names(series)), win.start, win.width=50, n = NULL, prewhiten = TRUE, biweight = TRUE, series.x = FALSE) { + ## check to see that win.width is even if(as.logical(win.width %% 2)) stop("'win.width' must be even") if (win.width > 100) { @@ -213,11 +214,13 @@ popViewport(2) # back to bnd negText <- textGrob(gettext("(Negative)", domain="R-dplR"), - y=unit(-0.5,"lines"),x=unit(3,"native"), + y=unit(0.25,"lines"),x=unit(3,"native"), just = textJust) posText <- textGrob(gettext("(Positive)", domain="R-dplR"), - y=unit(-0.5,"lines"),x=unit(9,"native"), + y=unit(0.25,"lines"),x=unit(9,"native"), just = textJust) + + for (period in c("early", "late")) { if (period == "early") { vp1 <- ccf.early.bnd.vp @@ -255,7 +258,7 @@ periodPattern <- gettext("Period: %d-%d", domain = "R-dplR") agreePattern <- gettext("Skeleton Agreement %s%%", domain = "R-dplR") - grid.segments(x0=0.5,y0=0,x1=0.5,y1=0.95, + grid.segments(x0=0.5,y0=0.05,x1=0.5,y1=0.95, default.units="npc", gp=gpar(lwd=2,lend="butt", col="black")) pushViewport(text.bnd.vp) # description @@ -263,6 +266,7 @@ list(period = sprintf(periodPattern, min(first.yrs), max(first.yrs)), corr = early.r)) + grid.text(tmp.txt,y=unit(0.65,"npc"),x=unit(0.25,"npc"), just = textJust) @@ -292,6 +296,13 @@ agree = sprintf(agreePattern, overall.agree))) grid.text(tmp.txt,y=unit(0.5,"npc"),x=unit(0.5,"npc"), just = textJust) + + popViewport(2) - + series.x.txt <- ifelse(series.x, + "NB: With series.x = TRUE, postive lags indicate missing rings in series", + "NB: With series.x = FALSE (default), negative lags indicate missing rings in series") + grid.text(series.x.txt,y=unit(0.015,"npc"),x=unit(0.5,"npc"), + just = textJust) + }