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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 9 21:24:31 CEST 2014


Author: andybunn
Date: 2014-04-09 21:24:31 +0200 (Wed, 09 Apr 2014)
New Revision: 801

Modified:
   pkg/dplR/R/detrend.series.R
   pkg/dplR/man/detrend.series.Rd
Log:
made some changes to detrend.series plots as well as handling negative values from method Ar.

Modified: pkg/dplR/R/detrend.series.R
===================================================================
--- pkg/dplR/R/detrend.series.R	2014-04-09 17:12:41 UTC (rev 800)
+++ pkg/dplR/R/detrend.series.R	2014-04-09 19:24:31 UTC (rev 801)
@@ -136,8 +136,15 @@
     if("Ar" %in% method2){
       ## Fit an ar model - aka prewhiten
       Ar <- ar.func(y2)
-      # this will propogate NA to rwi as a result of detrending. 
-      # Other methods don't. Problem?
+      # This will propogate NA to rwi as a result of detrending. 
+      # Other methods don't. Problem when interacting with other
+      # methods?
+      # Also, this can (and does!) produce negative RWI values.
+      # See example using CAM011. Thus:
+      if (any(Ar <= 0, na.rm = TRUE)) {
+        warning("Ar fit is not all positive")
+        Ar[Ar<0] <- 0
+      }
       resids$Ar <- Ar / mean(Ar,na.rm=TRUE)
       do.ar <- TRUE
     } else {
@@ -149,9 +156,22 @@
     if(make.plot){
         op <- par(no.readonly=TRUE)
         on.exit(par(op))
-        par(mar=c(2.5, 2.5, 2.5, 0.5) + 0.1, mgp=c(1.5, 0.5, 0))
-        n.rows <- 1 + ncol(resids)
-        mat <- matrix(seq_len(n.rows), n.rows, 1)
+        par(mar=c(2.1, 2.1, 2.1, 2.1), mgp=c(1.1, 0.1, 0),
+            tcl=0.5, xaxs='i')
+        n.plots <- 1 + ncol(resids) 
+        if(n.plots == 5){
+          mat <- matrix(c(1,1,2,3,4,5), nrow=3, ncol=2,byrow=TRUE)
+        }
+        if(n.plots == 4){
+          mat <- matrix(c(1,2,3,4), nrow=2, ncol=2,byrow=TRUE)
+        }
+        if(n.plots == 3){
+          mat <- matrix(c(1,1,2,3), nrow=2, ncol=2,byrow=TRUE)
+        }
+        if(n.plots == 2){
+          mat <- matrix(c(1,2), nrow=2, ncol=1,byrow=TRUE)
+        }
+
         layout(mat,
                widths=rep.int(0.5, ncol(mat)),
                heights=rep.int(1, nrow(mat)))
@@ -159,7 +179,6 @@
         plot(y2, type="l", ylab="mm",
              xlab=gettext("Age (Yrs)", domain="R-dplR"),
              main=gettextf("Raw Series %s", y.name, domain="R-dplR"))
-        if(do.ar) lines(Ar, col="purple", lwd=2)
         if(do.spline) lines(Spline, col="green", lwd=2)
         if(do.mne) lines(ModNegExp, col="red", lwd=2)
         if(do.mean) lines(Mean, col="blue", lwd=2)
@@ -190,10 +209,11 @@
         }
         if(do.ar){
           plot(resids$Ar, type="l", col="purple",
-               main=gettext("Ar", domain="R-dplR"),
+               main=gettextf("Ar", domain="R-dplR"),
                xlab=gettext("Age (Yrs)", domain="R-dplR"),
                ylab=gettext("RWI", domain="R-dplR"))
           abline(h=1)
+          mtext(text="Not plotted with raw series",side=3,line=-1)
         }
     }
 

Modified: pkg/dplR/man/detrend.series.Rd
===================================================================
--- pkg/dplR/man/detrend.series.Rd	2014-04-09 17:12:41 UTC (rev 800)
+++ pkg/dplR/man/detrend.series.Rd	2014-04-09 19:24:31 UTC (rev 801)
@@ -133,6 +133,22 @@
 data(ca533)
 series <- ca533[, "CAM011"]
 names(series) <- rownames(ca533)
+# defaults to all four methods
 series.rwi <- detrend.series(y = series, y.name = "CAM011")
+# see plot with three methods
+series.rwi <- detrend.series(y = series, y.name = "CAM011",
+                             method=c("Spline", "ModNegExp","Mean"))
+# see plot with two methods
+# interesting to note difference from ~200 to 250 years 
+# in terms of what happens to low frequency growth
+series.rwi <- detrend.series(y = series, y.name = "CAM011",
+                             method=c("Spline", "ModNegExp"))
+# see plot with just one method
+series.rwi <- detrend.series(y = series, y.name = "CAM011",
+                             method="Spline")
+# note that method "Ar" doesn't get plotted in first panel
+# since this approach doesn't approximate a growth curve.
+series.rwi <- detrend.series(y = series, y.name = "CAM011",
+                             method="Ar")
 }
 \keyword{ manip }



More information about the Dplr-commits mailing list