[Dplr-commits] r1017 - in pkg/dplR: . data man vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Mar 7 07:47:32 CET 2016


Author: andybunn
Date: 2016-03-07 07:47:32 +0100 (Mon, 07 Mar 2016)
New Revision: 1017

Added:
   pkg/dplR/data/wa082.rda
   pkg/dplR/man/wa082.Rd
   pkg/dplR/vignettes/chron-dplR.Rnw
Modified:
   pkg/dplR/TODO
Log:
made a start on a chron building vignette. adding a new rwl data set wa082 as well.

Modified: pkg/dplR/TODO
===================================================================
--- pkg/dplR/TODO	2016-03-06 17:26:22 UTC (rev 1016)
+++ pkg/dplR/TODO	2016-03-07 06:47:32 UTC (rev 1017)
@@ -12,10 +12,6 @@
    data differntly based on its class.
 
 
-*  Calculate the NET index that was proposed by Esper, J., Neuwirth, B. 
-   and Treydte, K.S. 2001 A new parameter to evaluate temporal signal 
-   strength of tree-ring chronologies. Dendrochronologia, 19 (1), 93-102.
-
 o [andybunn]  xskel.cff.plot is a renamed version of skel.cff.plot which has been taken 
    out of the package. I think. The x preface is to denote its use
    in crossdating. This function needs to have checks built in that will allow

Added: pkg/dplR/data/wa082.rda
===================================================================
(Binary files differ)


Property changes on: pkg/dplR/data/wa082.rda
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: pkg/dplR/man/wa082.Rd
===================================================================
--- pkg/dplR/man/wa082.Rd	                        (rev 0)
+++ pkg/dplR/man/wa082.Rd	2016-03-07 06:47:32 UTC (rev 1017)
@@ -0,0 +1,27 @@
+\encoding{UTF-8}
+\name{wa082}
+\docType{data}
+\alias{wa082}
+\title{Hurricane Ridge, Pacific silver fir}
+\description{
+  This data set gives the raw ring widths for Pacific silver fir
+  \emph{Abies amabilis} at Hurricane Ridge in Washington, \acronym{USA}.
+  There are 23 series.  Data set was created using \code{\link{read.rwl}}
+  and saved to an .rda file using \code{\link{save}}.
+}
+\usage{data(wa082)}
+\format{
+  A \code{data.frame} containing 35 tree-ring series in columns and 286
+  years in rows.
+}
+\source{
+  International tree-ring data bank, Accessed on 06-March-2016 at
+  \url{ftp://ftp.ncdc.noaa.gov/pub/data/paleo/treering/measurements/northamerica/usa/wa082.rwl}
+}
+\references{
+  Schweingruber, F. (1983) Hurricane Ridge Data Set.  \acronym{IGBP}
+  \acronym{PAGES}/World Data Center for Paleoclimatology Data
+  Contribution Series 1983-wa082.RWL.  \acronym{NOAA}/\acronym{NCDC}
+  Paleoclimatology Program, Boulder, Colorado, \acronym{USA}.
+}
+\keyword{datasets}

Added: pkg/dplR/vignettes/chron-dplR.Rnw
===================================================================
--- pkg/dplR/vignettes/chron-dplR.Rnw	                        (rev 0)
+++ pkg/dplR/vignettes/chron-dplR.Rnw	2016-03-07 06:47:32 UTC (rev 1017)
@@ -0,0 +1,238 @@
+% -*- mode: noweb; noweb-default-code-mode: R-mode; -*-
+%\VignetteIndexEntry{Chronology Building in dplR}
+\documentclass[a4paper,11pt]{article}
+\usepackage{dplR} % dplR settings - needs some work
+\usepackage[utf8]{inputenx} % R CMD build wants this here, not in dplR.sty
+\input{ix-utf8enc.dfu} % more characters supported
+\title{Chronology Building in dplR} 
+\author{Andy Bunn \and Mikko Korpela}
+<<echo=FALSE,results=hide>>=
+library(dplR) # latexify(), latexDate()
+@ 
+\hypersetup{
+  pdfauthor = {Andy Bunn; Mikko Korpela},
+}
+\date{\footnotesize Processed with dplR 
+\Sexpr{packageDescription("dplR", field="Version")}
+in \Sexpr{latexify(R.version.string)} on \Sexpr{latexDate()}}
+
+\begin{document}
+\bibliographystyle{jss}
+
+\setkeys{Gin}{width=1.0\textwidth} % figure width
+\SweaveOpts{concordance=TRUE}
+\SweaveOpts{strip.white=true}
+\SweaveOpts{include=FALSE}
+<<echo=FALSE,results=hide>>=
+options(width=62) # width of paper (number of characters)
+options(useFancyQuotes=FALSE) # fancy quotes not included in fixed-width font?
+Sys.setenv(LANGUAGE="en") # no translations to languages other than English
+@ 
+
+\maketitle
+
+\begin{abstract}
+In this vignette we cover three methods for building chronologies using 
+stadardized ring widths.
+\end{abstract}
+\tableofcontents
+
+\newpage
+
+\section{Introduction}
+\subsection{What Is Covered}
+The Dendrochronology Program Library in R (dplR) is a package for 
+dendrochronologists to handle data processing and analysis. This 
+document gives an illustration of chronology development in dplR. 
+\subsection{Citing dplR and R}
+The creation of dplR is an act of love. We enjoy writing this software and 
+helping users. However, neither of us is among the idle rich. Alas. We have
+jobs and occasionally have to answer to our betters. There is a nifty 
+\code{citation} function in R that gives you information on how to best 
+cite R and, in many cases, its packages. We ask that you please cite dplR 
+and R appropriately in your work. This way when our department chairs and 
+deans accuse us of being dilettantes we can point to the use of dplR as a 
+partial excuse.
+
+<<>>=
+citation()
+citation("dplR")
+@
+
+\section{Data Sets}
+
+Throughout this vignette we will use the onboard data set \code{wa082} 
+which gives the raw ring widths for Norway spruce \emph{Picea abies} at 
+Rothenburg ob der Tauber, Bavaria, Germany. There are 20 series from 10 trees,
+spanning 98 years. 
+
+This data comes from Zang's PhD thesis. It is a well-dated ring width data set 
+and plotted in Figure~\ref{fig:rwl}. Note the summary stats below.
+<<a, fig=TRUE>>=
+library(dplR)
+data(wa082)
+wa082.sum <- summary(wa082)
+mean(wa082.sum$year)
+mean(wa082.sum$stdev)
+mean(wa082.sum$median)
+mean(wa082.sum$ar1)
+mean(interseries.cor(wa082)[, 1])
+plot(wa082, plot.type="spag",zfac=0.5)
+@
+\begin{figure}[ht]
+\centering
+\includegraphics{chron-dplR-a}
+\caption{A spaghetti plot of the Norway spruce ring widths.}
+\label{fig:rwl}
+\end{figure}
+
+\textbf{By the way, if this is all new to you -- you should 
+proceed immediately to a good primer on dendrochronology like 
+\cite{Fritts2001}. This vignette is not intended to teach you about how to do 
+tree-ring analysis. It is intended to teach you how to use the package.}
+
+\section{Building Chronologies}
+Let us make a few chronologies from the \code{wa082} data after detrending
+each series with a spline that has a frequency response of 50\% at a 
+wavelength of 2/3 of
+each series's length. 
+<<b>>=
+wa082.rwi <- detrend(wa082, method="Spline")
+@
+
+
+\subsection{Traditional Chronology}
+The simplest way to make a chronology in `dplR` is chronology is with the `crn`
+function which also has a `plot` method. This defaults to building a mean-value
+chronology by averaging the rows of the `rwi` data using Tukey's biweight robust
+mean. The result is plotted in Figure~\ref{fig:crn.plot}.
+<<c, fig=TRUE>>=
+wa082.crn <- chron(wa082.rwi, prefix="HUR")
+plot(wa082.crn, add.spline=TRUE, nyrs=10)
+@
+\begin{figure}[ht]
+\centering
+\includegraphics{chron-dplR-c}
+\caption{The `wa082` chronology.}
+\label{fig:crn.plot}
+\end{figure}
+Note that the `chron` function will also compute a residual chronology by
+"prewhitening" the series before averaging. If the `prewhiten` flag is 	
+set to `TRUE`, each series is whitened using `ar` prior to averaging. The 
+residual chronology is thus white noise and has no autocorrelation. Note that
+the `wa082.std.resid` object has two columns with chronologies as well as the sample
+depth in a third column. The result is plotted in 
+Figure~\ref{fig:crn.plot.resid}.
+<<d, fig=TRUE>>=
+wa082.std.resid <- chron(wa082.rwi, prefix="HUR",prewhiten = TRUE)
+tail(wa082.std.resid)
+plot(wa082.std.resid, add.spline=TRUE, nyrs=10)
+@
+\begin{figure}[ht]
+\centering
+\includegraphics{chron-dplR-d}
+\caption{The `wa082` chronology as the standard chronology and the residual
+chronology.}
+\label{fig:crn.plot.resid}
+\end{figure}
+
+\subsection{Using a Cutoff}
+A relatively simple addition to the traditional chronology is to truncate the
+chronology when the sample depth gets to a certain threshold. The output from
+the `chron` function contains a column called `samp.depth` which shows the
+number of series that are average for a particular year. We can use the 
+`subset` function to modify the chronology. The result is plotted in 
+Figure~\ref{fig:crn.plot.sd}.
+
+<<e, fig=TRUE>>=
+head(wa082.crn)
+wa082.trunc <- subset(wa082.crn, samp.depth > 5)
+# and plot
+plot(wa082.trunc,add.spline=T,nyrs=10)
+@
+
+\begin{figure}[ht]
+\centering
+\includegraphics{chron-dplR-e}
+\caption{The `wa082` chronology truncated by sample depth.}
+\label{fig:crn.plot.sd}
+\end{figure}
+
+A more interesting and likely more robust approach is to truncate via the
+expressed population signal (EPS).The result is plotted in 
+Figure~\ref{fig:crn.plot.eps}.
+
+<<f, fig=TRUE>>=
+wa082.ids <- autoread.ids(wa082)
+eps.cut <- 0.75 # An arbitrary EPS cutoff for demonstration
+foo <- rwi.stats.running(wa082.rwi, wa082.ids, window.length = 32)
+yrs <- as.numeric(rownames(wa082.crn))
+bar <- data.frame(yrs = c(min(yrs), foo$mid.year, max(yrs)),
+                  eps = c(NA, foo$eps, NA))
+op <- par(no.readonly=TRUE)
+par(mar = c(2, 2, 2, 2), mgp = c(1.1, 0.1, 0), tcl = 0.25,
+    mfcol = c(2, 1), xaxs='i')
+plot(yrs, wa082.crn[, 1], type = "n", xlab = "Year",
+     ylab = "RWI", axes=FALSE)
+cutoff <- max(bar$yrs[bar$eps < eps.cut], na.rm = TRUE)
+xx <- c(500, 500, cutoff, cutoff)
+yy <- c(-1, 3, 3, -1)
+polygon(xx, yy, col = "grey80")
+abline(h = 1, lwd = 1.5)
+lines(yrs, wa082.crn[, 1], col = "grey50")
+lines(yrs, ffcsaps(wa082.crn[, 1], nyrs = 32), col = "red", lwd = 2)
+axis(1); axis(2); axis(3);
+par(new = TRUE)
+## Add EPS
+plot(bar$yrs, bar$eps, type = "b", xlab = "", ylab = "",
+     axes = FALSE, pch = 20, col = "blue")
+axis(4, at = pretty(foo$eps))
+mtext("EPS", side = 4, line = 1.1)
+box()
+## Second plot is the chronology after the cutoff only
+## Chronology is rebuilt using just years after cutoff but
+## that difference is essentially nil.
+yr.mask <- yrs > cutoff
+yrs2 <- yrs[yr.mask]
+wa082.crn2 <- chron(wa082.rwi[yr.mask, ])
+plot(yrs2, wa082.crn2[, 1], type = "n",
+     xlab = "Year", ylab = "RWI", axes=FALSE)
+abline(h = 1, lwd = 1.5)
+lines(yrs2, wa082.crn2[, 1], col = "grey50")
+lines(yrs2, ffcsaps(wa082.crn2[, 1], nyrs = 32),
+      col = "red", lwd = 2)
+axis(1); axis(2); axis(3); axis(4)
+box()
+par(op)
+@
+
+\begin{figure}[ht]
+\centering
+\includegraphics{chron-dplR-f}
+\caption{The `wa082` chronology truncated by EPS.}
+\label{fig:crn.plot.eps}
+\end{figure}
+
+\subsection{Stripping out series by EPS}
+
+<<f, fig=TRUE>>=
+wa082.strip.rwl <- strip.rwl(wa082, ids = wa082.ids)
+wa082.rwi.strip <- detrend(wa082.strip.rwl, method="Spline")
+wa082.crn.strip <- chron(wa082.rwi.strip, prefix = "HUR")
+plot(wa082.crn.strip)
+@
+
+\begin{figure}[ht]
+\centering
+\includegraphics{chron-dplR-f}
+\caption{The `wa082` chronology after stripping series with low EPS.}
+\label{fig:crn.plot.strip}
+\end{figure}
+
+\section{Conclusion}
+There are dozens of packages in R that to do time series analysis. Here, 
+we've tried to give just a few examples of doing work with dplR while
+showing you how you might harness the awesome power of R.
+\bibliography{dplR}
+
+\end{document}



More information about the Dplr-commits mailing list