Learn R Programming

dplR (version 1.5.3)

rwi.stats.running: (Running Window) Statistics on Detrended Ring-Width Series

Description

This function calculates descriptive statistics on a data.frame of (usually) ring-width indices. The statistics are optionally computed in a running window with adjustable length and overlap.

Usage

rwi.stats.running(rwi, ids = NULL, period = c("max", "common"),
                  running.window = TRUE,
                  window.length = min(50, nrow(rwi)),
                  window.overlap = floor(window.length / 2),
                  first.start = NULL,
                  min.corr.overlap = min(30, window.length),
                  round.decimals = 3,
                  zero.is.missing = TRUE)

rwi.stats(rwi, ids=NULL, period=c("max", "common"), ...)

rwi.stats.legacy(rwi, ids=NULL, period=c("max", "common"))

Arguments

rwi
a data.frame with detrended and standardized ring width indices as columns and years as rows such as that produced by detrend.
ids
an optional data.frame with column one named "tree" giving a numeric ID for each tree and column two named "core" giving a numeric ID for
period
a character string, either "common" or "max" indicating whether correlations should be limited to complete observations over the period common to all cores (i.e. rows common to all samples) or the maxi
running.window
logical flag indicating whether to use a running window (TRUE, the default) or to ignore the other window parameters and effectively use one window covering all years (FALSE).
window.length
numeric value indicating the length of the running window in years. The default is 50 years or the number of years (rows) in rwi, whichever is smaller.
window.overlap
numeric value indicating the overlap of consecutive window positions, i.e. the number of common years. The default is half of the window length, rounded down.
first.start
an optional numeric value setting the position of the first window. Must be a value between 1 and n.years-window.length+1, where n.years is the number of y
min.corr.overlap
numeric value setting the minimum number of common years in any pair of ring-width series required for their correlation to be included in the calculations. Smaller overlaps are considered to yield unreliable correlation values
round.decimals
non-negative integer numeric value setting the desired number of decimal places in the results. Use NA, NULL or a negative number for no rounding.
zero.is.missing
logical flag indicating whether to treat zeros as missing values (TRUE, the default) or to include them in computation (FALSE).
...
arguments passed on to rwi.stats.running

Value

  • A data.frame containing the following columns (each row corresponds to one position of the window):
  • start.yearthe first year in the window. Not returned if running.window is FALSE or called as rwi.stats or rwi.stats.legacy.
  • mid.yearthe middle year in the window, rounded down. Not returned if running.window is FALSE or called as rwi.stats or rwi.stats.legacy.
  • end.yearthe last year in the window. Not returned if running.window is FALSE or called as rwi.stats or rwi.stats.legacy.
  • n.tottotal number of correlations computed
  • n.wtnumber of within-tree correlations computed
  • n.btnumber of between-tree correlations computed
  • rbar.totthe mean of all correlation between different cores
  • rbar.wtthe mean of the correlations between series from the same tree over all trees
  • rbar.btthe mean interseries correlation between all series from different trees
  • c.effthe effective number of cores (takes into account the number of within-tree correlations in each tree)
  • rbar.effthe effective signal calculated as rbar.bt / (rbar.wt + (1-rbar.wt) / c.eff)
  • epsthe expressed population signal
  • nthe average number of trees (for each year, a tree needs at least one non-NA core in order to be counted). Not returned in the results of rwi.stats.legacy.

Details

This calculates a variety of descriptive statistics commonly used in dendrochronology. The function rwi.stats is a wrapper that calls rwi.stats.running with running.window = FALSE. The results may differ from those prior to dplR 1.5.3, where the former rwi.stats (now renamed to rwi.stats.legacy) was replaced with a call to rwi.stats.running. For correctly calculating the statistics on within and between series variability, an appropriate mask (parameter ids) must be provided that identifies each series with a tree as it is common for dendrochronologists to take more than one core per tree. The function read.ids is helpful for creating a mask based on the series ID. If ids has duplicate tree/core combinations, the corresponding series are averaged before any statistics are computed. The value of the parameter zero.is.missing is relevant in the averaging: TRUE ensures that zeros don't contribute to the average. The default value of zero.is.missing is TRUE. The default prior to dplR 1.5.3 was FALSE. If the parameter is set to FALSE, the user will be warned in case zeros are present. Duplicate tree/core combinations are not detected by rwi.stats.legacy. Row names of ids may be used for matching the IDs with series in rwi. In this case, the number of rows in ids is allowed to exceed the number of series. If some names of rwi are missing from the row names of ids, the rows of ids are assumed to be in the same order as the columns of rwi, and the dimensions must match. The latter is also the way that rwi.stats.legacy handles ids, i.e. names are ignored and dimensions must match. Note that period = "common" can produce NaN for many of the stats if there is no common overlap period among the cores. This happens especially in chronologies with floating subfossil samples (e.g., ca533). Some of the statistics are specific to dendrochronology (e.g., the effective number of cores or the expressed population signal). Users unfamiliar with these should see Cook and Kairiukstis (1990) and Fritts (2001) for further details.

References

Cook, E. R. and Kairiukstis, L. A. (1990) Methods of Dendrochronology: Applications in the Environmental Sciences. Springer. ISBN-13: 978-0792305866. Fritts, H. C. (2001) Tree Rings and Climate. Blackburn. ISBN-13: 978-1930665392.

See Also

detrend, cor, read.ids, rwi.stats

Examples

Run this code
data(ca533)
ca533.rwi <- detrend(rwl = ca533, method = "Mean") # mean is fast
ca533.ids <- read.ids(ca533, stc = c(3, 2, 3))
rwi.stats.running(ca533.rwi, ca533.ids)
rwi.stats(ca533.rwi, ca533.ids)        # i.e. running.window = FALSE
rwi.stats.legacy(ca533.rwi, ca533.ids) # rwi.stats prior to dplR 1.5.3
## Plot the chronology showing a potential cutoff year based on eps
ca533.rwi <- detrend(rwl = ca533, method = "Spline") # detrend again
ca533.crn <- chron(ca533.rwi)
## Running stats on the rwi with an 80 yr window
foo <- rwi.stats.running(ca533.rwi, ca533.ids, window.length = 80)
yrs <- as.numeric(rownames(ca533.crn))
bar <- data.frame(yrs = c(min(yrs), foo$mid.year, max(yrs)),
                  eps = c(NA, foo$eps, NA))
par(mar = c(3, 3, 3, 3), mgp = c(1.25, 0.25, 0), tcl = 0.25,
    mfcol = c(2, 1))
plot(yrs, ca533.crn[, 1], type = "n", xlab = "Years", ylab = "RWI")
xx <- c(500, 500, max(bar$yrs[bar$eps < 0.8], na.rm = TRUE),
        max(bar$yrs[bar$eps < 0.8], na.rm = TRUE))
yy <- c(-1, 3, 3, -1)
polygon(xx, yy, col = "grey80")
abline(h = 1, lwd = 1.5)
lines(yrs, ca533.crn[, 1], col = "grey50")
lines(yrs, ffcsaps(ca533.crn[, 1], nyrs = 32), col = "red", lwd = 2)
par(new = TRUE)

## Second plot is the chronology after the cut off only
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.25)
box()
yr.mask <- yrs > max(bar$yrs[bar$eps<0.8], na.rm = TRUE)
plot(yrs[yr.mask], ca533.crn[yr.mask, 1], type = "n",
     xlab = "Years", ylab = "RWI")
abline(h = 1, lwd = 1.5)
lines(yrs[yr.mask], ca533.crn[yr.mask, 1], col = "grey50")
lines(yrs[yr.mask], ffcsaps(ca533.crn[yr.mask, 1], nyrs = 32),
      col = "red", lwd = 2)

Run the code above in your browser using DataLab