[Dplr-commits] r783 - in pkg/dplR: . R man vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Apr 7 22:33:45 CEST 2014


Author: andybunn
Date: 2014-04-07 22:33:44 +0200 (Mon, 07 Apr 2014)
New Revision: 783

Added:
   pkg/dplR/R/interseries.cor.R
   pkg/dplR/man/interseries.cor.Rd
Removed:
   pkg/dplR/R/series.rho.R
   pkg/dplR/man/series.rho.Rd
Modified:
   pkg/dplR/ChangeLog
   pkg/dplR/NAMESPACE
   pkg/dplR/TODO
   pkg/dplR/vignettes/intro-dplR.Rnw
Log:
changed series.rho to interseries.cor

Modified: pkg/dplR/ChangeLog
===================================================================
--- pkg/dplR/ChangeLog	2014-04-07 16:11:00 UTC (rev 782)
+++ pkg/dplR/ChangeLog	2014-04-07 20:33:44 UTC (rev 783)
@@ -7,7 +7,7 @@
 File: NAMESPACE
 -------------------------
 - Added chron.plot to export list.
-- Added rho.series to export list.
+- Added interseries.cor to export list.
 - Added plot.rwl as an S3Method.
 - Added summary.rwl as an S3Method.
 
@@ -41,9 +41,9 @@
 - Removed yr.range() function in favor of yr.range() in helpers.R.
   They are identical for all practical purposes.
 
-File: series.rho.R
+File: interseries.cor.R
 -------------------------
-- New function series.rho.
+- New function interseries.cor.
 
 File: read.compact.R
 -------------------------

Modified: pkg/dplR/NAMESPACE
===================================================================
--- pkg/dplR/NAMESPACE	2014-04-07 16:11:00 UTC (rev 782)
+++ pkg/dplR/NAMESPACE	2014-04-07 20:33:44 UTC (rev 783)
@@ -36,7 +36,7 @@
        series.rwl.plot, skel.plot, spag.plot, strip.rwl, tbrm,
        tridas.vocabulary, uuid.gen, wavelet.plot, wc.to.po,
        write.compact, write.crn, write.rwl, write.tridas,
-       write.tucson, chron.plot, plot.rwl, series.rho, summary.rwl)
+       write.tucson, chron.plot, plot.rwl, interseries.cor, summary.rwl)
 
 S3method(print, redfit)
 S3method(plot, rwl)

Added: pkg/dplR/R/interseries.cor.R
===================================================================
--- pkg/dplR/R/interseries.cor.R	                        (rev 0)
+++ pkg/dplR/R/interseries.cor.R	2014-04-07 20:33:44 UTC (rev 783)
@@ -0,0 +1,20 @@
+interseries.cor <- function(rwl, n=NULL, prewhiten=TRUE, biweight=TRUE, 
+                       method = c("spearman", "pearson","kendall")) {
+    method <- match.arg(method)
+    nseries <- length(rwl)
+    rho <- numeric(nseries)
+    p.val <- numeric(nseries)
+    rwl.mat <- as.matrix(rwl)
+    tmp <- normalize.xdate(rwl=rwl.mat, n=n,
+                           prewhiten=prewhiten, biweight=biweight,
+                           leave.one.out = TRUE)
+    series <- tmp[["series"]]
+    master <- tmp[["master"]]
+    for (i in seq_len(nseries)) {
+        tmp2 <- cor.test(series[, i], master[, i],
+                         method = method)
+        rho[i] <- tmp2[["estimate"]]
+        p.val[i] <- tmp2[["p.value"]]
+    }
+    data.frame(rho = rho, p.val = p.val, row.names = names(rwl))
+}

Deleted: pkg/dplR/R/series.rho.R
===================================================================
--- pkg/dplR/R/series.rho.R	2014-04-07 16:11:00 UTC (rev 782)
+++ pkg/dplR/R/series.rho.R	2014-04-07 20:33:44 UTC (rev 783)
@@ -1,18 +0,0 @@
-series.rho <- function(rwl, n=NULL, prewhiten=TRUE, biweight=TRUE) {
-    nseries <- length(rwl)
-    rho <- numeric(nseries)
-    p.val <- numeric(nseries)
-    rwl.mat <- as.matrix(rwl)
-    tmp <- normalize.xdate(rwl=rwl.mat, n=n,
-                           prewhiten=prewhiten, biweight=biweight,
-                           leave.one.out = TRUE)
-    series <- tmp[["series"]]
-    master <- tmp[["master"]]
-    for (i in seq_len(nseries)) {
-        tmp2 <- cor.test(series[, i], master[, i],
-                         method = "spearman", alternative = "greater")
-        rho[i] <- tmp2[["estimate"]]
-        p.val[i] <- tmp2[["p.value"]]
-    }
-    data.frame(rho = rho, p.val = p.val, row.names = names(rwl))
-}

Modified: pkg/dplR/TODO
===================================================================
--- pkg/dplR/TODO	2014-04-07 16:11:00 UTC (rev 782)
+++ pkg/dplR/TODO	2014-04-07 20:33:44 UTC (rev 783)
@@ -1,5 +1,7 @@
 *  In rwi.stats and any place a correlation is calculated, offer an argument to
-   to specify which correlation method (e.g., spearman).
+   to specify which correlation method (e.g., spearman). Note that I implemented
+   this in interseries.cor - but will have to do this throughout. The default
+   should be spearman.
 
 *  In detrend(method=“ModNegExp”) there should be a verbose option that writes 
    how each series was handled including the parameters of the model.
@@ -9,8 +11,6 @@
   I've been compiling the vignettes in Rstudio which leaves a lot of junk
   behind when it's done.
 
-* Improve the help file for series.rho.
-
 * Decide when to use class('rwl') in functions dealing with rwl objects.
   Other than the plot and summary S3Method for rwl, are there cases when 
   having that class would be useful. E.g., in error checking?

Added: pkg/dplR/man/interseries.cor.Rd
===================================================================
--- pkg/dplR/man/interseries.cor.Rd	                        (rev 0)
+++ pkg/dplR/man/interseries.cor.Rd	2014-04-07 20:33:44 UTC (rev 783)
@@ -0,0 +1,70 @@
+\name{interseries.cor}
+\alias{interseries.cor}
+\title{ Calculate an indidual series correlation against a master chronology 
+  in an rwl object  }
+\description{
+  This function calculates the correlation between a series and a master chronology
+}
+\usage{
+  interseries.cor(rwl,n=NULL,prewhiten=TRUE,biweight=TRUE,
+    method = c("spearman", "pearson","kendall"))
+}
+\arguments{
+  \item{rwl}{ a \code{data.frame} with series as columns and years as
+    rows such as that produced by \code{\link{read.rwl}}. }
+  \item{n}{ \code{NULL} or an integral value giving the filter length
+    for the \code{\link{hanning}} filter used for removal of low
+    frequency variation. }
+  \item{prewhiten}{ \code{logical} flag.  If \code{TRUE} each series is
+    whitened using \code{\link{ar}}. }
+  \item{biweight}{ \code{logical} flag.  If \code{TRUE} then a robust
+    mean is calculated using \code{\link{tbrm}}.}
+  \item{method}{Can either "pearson", "kendall", or "spearman" which indicates
+    the correlation coefficient is to be used. Defaults to "spearman." See 
+    \code{\link{cor.test}}. }
+}
+\details{
+  This function calculates correlation serially between each tree-ring
+  series and a master chronology built from all the other series in the
+  \code{\var{rwl}} object (leave-one-out principle).
+
+  Each series in the rwl object is optionally
+  detrended as the residuals from a \code{\link{hanning}} filter with
+  weight \code{\var{n}}.  The filter is not applied if \code{\var{n}} is
+  \code{NULL}.  Detrending can also be done via prewhitening where the
+  residuals of an \code{\link{ar}} model are added to each series
+  mean.  This is the default.  The master chronology is computed as the
+  mean of the \code{\var{rwl}} object using \code{\link{tbrm}} if
+  \code{\var{biweight}} is \code{TRUE} and \code{rowMeans} if not.  Note
+  that detrending can change the length of the series.  E.g., a
+  \code{\link{hanning}} filter will shorten the series on either end by
+  \code{floor(\var{n}/2)}.  The prewhitening default will change the
+  series length based on the \code{\link{ar}} model fit.  The effects of
+  detrending can be seen with \code{\link{series.rwl.plot}}.
+
+  This function produces the same output of the "overall" portion of 
+  \code{\link{corr.rwl.seg}}. The mean rho value given is sometimes referred to as
+  the "overall interseries correlation"" or the "COFECHA interseries 
+  correlation." This output differs from the \code{rbar} statistics given by
+  \code{\link{rwi.stats}} in that \code{rbar} is the average pairwise correlation between 
+  series where this is the correlation between a series and a master chronology.
+}
+\value{ a \code{data.frame} with rho values and p-values given from
+\code{\link{cor.test}}
+}
+\author{ Andy Bunn, patched and improved by Mikko Korpela  }
+\seealso{ \code{\link{rwl.stats}}, \code{\link{rwi.stats}} }
+\examples{data(gp.rwl)
+foo <- interseries.cor(gp.rwl)
+# compare to: 
+# corr.rwl.seg(rwl=gp.rwl,make.plot=FALSE)$overall
+
+# two measures of interseries correlation
+# compare interseries.cor to rbar from rwi.stats
+gp.ids <- read.ids(gp.rwl, stc = c(0, 2, 1))
+bar <- rwi.stats(gp.rwl, gp.ids, prewhiten=TRUE)
+bar$rbar.eff
+mean(foo[,1])
+
+}
+\keyword{ manip }

Deleted: pkg/dplR/man/series.rho.Rd
===================================================================
--- pkg/dplR/man/series.rho.Rd	2014-04-07 16:11:00 UTC (rev 782)
+++ pkg/dplR/man/series.rho.Rd	2014-04-07 20:33:44 UTC (rev 783)
@@ -1,65 +0,0 @@
-\name{series.rho}
-\alias{series.rho}
-\title{ Calculate an individual indidual series correlation against a master chronology in an rwl object  }
-\description{
-  This function calculates the correlation between a series and a master chronology
-}
-\usage{
-  series.rho(rwl,n=NULL,prewhiten=TRUE,biweight=TRUE)
-}
-\arguments{
-  \item{rwl}{ a \code{data.frame} with series as columns and years as
-    rows such as that produced by \code{\link{read.rwl}}. }
-  \item{n}{ \code{NULL} or an integral value giving the filter length
-    for the \code{\link{hanning}} filter used for removal of low
-    frequency variation. }
-  \item{prewhiten}{ \code{logical} flag.  If \code{TRUE} each series is
-    whitened using \code{\link{ar}}. }
-  \item{biweight}{ \code{logical} flag.  If \code{TRUE} then a robust
-    mean is calculated using \code{\link{tbrm}}. }
-}
-\details{
-  This function calculates correlation serially between each tree-ring
-  series and a master chronology built from all the other series in the
-  \code{\var{rwl}} object (leave-one-out principle).
-
-  Each series in the rwl object is optionally
-  detrended as the residuals from a \code{\link{hanning}} filter with
-  weight \code{\var{n}}.  The filter is not applied if \code{\var{n}} is
-  \code{NULL}.  Detrending can also be done via prewhitening where the
-  residuals of an \code{\link{ar}} model are added to each series
-  mean.  This is the default.  The master chronology is computed as the
-  mean of the \code{\var{rwl}} object using \code{\link{tbrm}} if
-  \code{\var{biweight}} is \code{TRUE} and \code{rowMeans} if not.  Note
-  that detrending can change the length of the series.  E.g., a
-  \code{\link{hanning}} filter will shorten the series on either end by
-  \code{floor(\var{n}/2)}.  The prewhitening default will change the
-  series length based on the \code{\link{ar}} model fit.  The effects of
-  detrending can be seen with \code{\link{series.rwl.plot}}.
-
-  This function produces the same output of the "overall" portion of 
-  \code{\link{corr.rwl.seg}}. The mean rho value given is sometimes referred to as
-  the "overall interseries correlation"" or the "COFECHA interseries 
-  correlation." This output differs from the \code{rbar} statistics given by
-  \code{\link{rwi.stats}} in that \code{rbar} is the average pairwise correlation between 
-  series where this is the correlation between a series and a master chronology.
-}
-\value{ a \code{data.frame} with rho values and p-values given from
-\code{\link{cor.test}}
-}
-\author{ Andy Bunn, patched and improved by Mikko Korpela  }
-\seealso{ \code{\link{rwl.stats}}, \code{\link{rwi.stats}} }
-\examples{data(gp.rwl)
-foo <- series.rho(gp.rwl)
-# compare to: 
-# corr.rwl.seg(rwl=gp.rwl)$overall
-
-# two measures of interseries correlation
-# compare series.rho to rbar from rwi.stats
-gp.ids <- read.ids(gp.rwl, stc = c(0, 2, 1))
-bar <- rwi.stats(gp.rwl, gp.ids, prewhiten=TRUE)
-bar$rbar.eff
-mean(foo[,1])
-
-}
-\keyword{ manip }

Modified: pkg/dplR/vignettes/intro-dplR.Rnw
===================================================================
--- pkg/dplR/vignettes/intro-dplR.Rnw	2014-04-07 16:11:00 UTC (rev 782)
+++ pkg/dplR/vignettes/intro-dplR.Rnw	2014-04-07 20:33:44 UTC (rev 783)
@@ -155,8 +155,8 @@
 
 An alternative method in detrend is to standardize with the ``Spline'' approach.
 This method uses a spline as the growth model where the frequency response 
-is 0.50 at a wavelength of 0.67 * series length (unless specified differently by the
-user. This attempts to remove the low frequency 
+is 0.50 at a wavelength of 0.67 * series length (unless specified differently by 
+the user). This attempts to remove the low frequency 
 variability that is due to biological or stand effects. Rather than detrend the
 entire ca533 rwl object, we'll illustrate the spline method by detrending a 
 single series using the detrend.series function, which produces a plot by
@@ -217,17 +217,19 @@
 @
 
 There is (at least) one other way of looking at the average interseries 
-correlation of a dataset. The series.rho function in dplR gives a measure of
+correlation of a dataset. The interseries.cor function in dplR gives a measure of
 average interseries correlation that is different than the rbar measurements
 from rwi.stats. In this function, correlations are calculated serially between 
 each tree-ring series and a master chronology built from all the other series 
 in the rwl object (leave-one-out principle). The average of those correlations
 is sometimes called the ``overall interseries correlation.'' This number is
-typically higher than rbar
+typically higher than rbar. We are showing just the first five series and the 
+mean for all series here:
 
 <<>>=
-ca533.rho <- series.rho(ca533.rwi, prewhiten=TRUE)
-head(ca533.rho)
+ca533.rho <- interseries.cor(ca533.rwi, prewhiten=TRUE,
+                             method="spearman")
+ca533.rho[1:5,]
 mean(ca533.rho[, 1])
 @
 
@@ -235,7 +237,6 @@
 canonical works in dendrochronology like \cite{Cook1990} and \cite{Fritts2001}
 as well as more recent works like \cite{Hughes2011}.
 
-
 \section{Building a Mean Value Chronology}
 After detrending, a user will typically build a chronology by averaging across
 the years of the rwi object. In dplR the function for doing this is chron which



More information about the Dplr-commits mailing list