[Dplr-commits] r997 - in pkg/dplR: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 14 11:52:01 CEST 2015


Author: zang
Date: 2015-07-14 11:52:01 +0200 (Tue, 14 Jul 2015)
New Revision: 997

Modified:
   pkg/dplR/R/sea.R
   pkg/dplR/man/sea.Rd
Log:
updated sea() to return bootstrapped CIs

Modified: pkg/dplR/R/sea.R
===================================================================
--- pkg/dplR/R/sea.R	2015-06-04 21:46:43 UTC (rev 996)
+++ pkg/dplR/R/sea.R	2015-07-14 09:52:01 UTC (rev 997)
@@ -36,13 +36,18 @@
         rand.key <- sample(rnames, n, replace = TRUE)
         for (i in seq.n) {
             re.subtable[i, ] <-
-                x.scaled[as.character(rand.key[i] + yrs.base), ]
+                               x.scaled[as.character(rand.key[i] + yrs.base), ]
         }
         re.table[k, ] <- colMeans(re.subtable, na.rm = TRUE)
     }
     ## calculate significance for each (lagged) year
+    ## compute confidence bands, too
     p <- rep(NA_real_, m)
     w <- resample
+    ci_pos <- floor(resample * c(0.025, 0.975, 0.005, 0.995))
+    ci <- apply(apply(re.table, 2, sort), 2, function(x) {
+        x[ci_pos]
+    })
     for (i in seq_len(m)) {
         if (is.na(se[i])) {
             warning(gettextf("NA result at position %d. ", i),
@@ -70,5 +75,12 @@
             }
         }
     }
-    data.frame(lag = c(-lag:lag), se, se.unscaled, p)
+    data.frame(lag = c(-lag:lag),
+               se.unscaled,
+               p,
+               se.scaled = se,
+               ci.95.lower = ci[1,],
+               ci.95.upper = ci[2,],
+               ci.99.lower = ci[3,],
+               ci.99.upper = ci[4,])
 }

Modified: pkg/dplR/man/sea.Rd
===================================================================
--- pkg/dplR/man/sea.Rd	2015-06-04 21:46:43 UTC (rev 996)
+++ pkg/dplR/man/sea.Rd	2015-07-14 09:52:01 UTC (rev 997)
@@ -40,12 +40,16 @@
 \value{
   A \code{data.frame} with
   \item{lag}{the lagged years,}
-  \item{se}{the superposed epoch, i.e. the scaled mean \acronym{RWI} for
-    the event years,}
   \item{se.unscaled}{the unscaled superposed epoch, i.e. the mean
     \acronym{RWI} for the event years,}
   \item{p}{significance of the departure from the chrono\enc{’}{'}s mean
-    \acronym{RWI}.}
+    \acronym{RWI},}
+  \item{se.scaled}{the superposed epoch, i.e. the scaled mean \acronym{RWI} for
+    the event years,}
+  \item{ci.95.lower}{lower 95\% confidence band,}
+  \item{ci.95.upper}{upper 95\% confidence band,}
+  \item{ci.99.lower}{lower 99\% confidence band,}
+  \item{ci.99.upper}{upper 99\% confidence band.}
 }
 
 \author{ Christian Zang.  Patched and improved by Mikko Korpela. }



More information about the Dplr-commits mailing list