[Dplr-commits] r811 - in pkg/dplR: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Apr 11 23:58:45 CEST 2014
Author: andybunn
Date: 2014-04-11 23:58:44 +0200 (Fri, 11 Apr 2014)
New Revision: 811
Modified:
pkg/dplR/ChangeLog
pkg/dplR/R/detrend.R
pkg/dplR/R/detrend.series.R
pkg/dplR/TODO
pkg/dplR/man/detrend.Rd
pkg/dplR/man/detrend.series.Rd
Log:
Mikko, I made a start on the verbose option for detrend.series. Can you look at TODO and see what's to be done there?
Modified: pkg/dplR/ChangeLog
===================================================================
--- pkg/dplR/ChangeLog 2014-04-11 11:14:54 UTC (rev 810)
+++ pkg/dplR/ChangeLog 2014-04-11 21:58:44 UTC (rev 811)
@@ -31,6 +31,7 @@
File: detrend.R and detrend.series.R
------------
- Added an Ar detrend method. Revised plotting in detrend.series
+- Added a verbose option to write out parameters used in detrending
File: powt.R
------------
Modified: pkg/dplR/R/detrend.R
===================================================================
--- pkg/dplR/R/detrend.R 2014-04-11 11:14:54 UTC (rev 810)
+++ pkg/dplR/R/detrend.R 2014-04-11 21:58:44 UTC (rev 811)
@@ -2,7 +2,8 @@
function(rwl, y.name = names(rwl), make.plot = FALSE,
method=c("Spline", "ModNegExp", "Mean", "Ar"),
nyrs = NULL, f = 0.5, pos.slope = FALSE,
- constrain.modnegexp = c("never", "when.fail", "always"))
+ constrain.modnegexp = c("never", "when.fail", "always"),
+ verbose=FALSE)
{
stopifnot(identical(make.plot, TRUE) || identical(make.plot, FALSE),
identical(pos.slope, FALSE) || identical(pos.slope, TRUE))
@@ -42,7 +43,8 @@
nyrs=nyrs, f=f,
pos.slope=pos.slope,
constrain.modnegexp=
- constrain2)
+ constrain2,
+ verbose=verbose)
if(is.data.frame(fits))
row.names(fits) <- rn
fits
@@ -54,7 +56,8 @@
make.plot=make.plot,
method=method2, nyrs=nyrs, f=f,
pos.slope=pos.slope,
- constrain.modnegexp=constrain2)
+ constrain.modnegexp=constrain2,
+ verbose=verbose)
if(is.data.frame(fits))
row.names(fits) <- rn
out[[i]] <- fits
Modified: pkg/dplR/R/detrend.series.R
===================================================================
--- pkg/dplR/R/detrend.series.R 2014-04-11 11:14:54 UTC (rev 810)
+++ pkg/dplR/R/detrend.series.R 2014-04-11 21:58:44 UTC (rev 811)
@@ -2,7 +2,8 @@
function(y, y.name = "", make.plot = TRUE,
method = c("Spline", "ModNegExp", "Mean", "Ar"),
nyrs = NULL, f = 0.5, pos.slope = FALSE,
- constrain.modnegexp = c("never", "when.fail", "always"))
+ constrain.modnegexp = c("never", "when.fail", "always"),
+ verbose=FALSE)
{
stopifnot(identical(make.plot, TRUE) || identical(make.plot, FALSE),
identical(pos.slope, FALSE) || identical(pos.slope, TRUE))
@@ -11,6 +12,25 @@
method2 <- match.arg(arg = method,
choices = known.methods,
several.ok = TRUE)
+
+
+
+ if(verbose){
+ nyrs.tmp <- ifelse(test=is.null(nyrs),yes="NULL",nyrs)
+ cat("\nVerbose output: ", y.name,
+ "\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
+ "\n Options:",
+ "\n make.plot =", make.plot,
+ "\n method(s) =", paste(deparse(method2), sep = "\n",
+ collapse = "\n"),
+ "\n nyrs =", nyrs.tmp,
+ "\n f =", f,
+ "\n pos.slope =", pos.slope,
+ "\n constrain.modnegexp =", constrain2,
+ "\n verbose =", verbose,
+ "\n")
+ }
+
## Remove NA from the data (they will be reinserted later)
good.y <- which(!is.na(y))
if(length(good.y) == 0) {
@@ -21,6 +41,14 @@
y2 <- y[good.y]
nY2 <- length(y2)
## Recode any zero values to 0.001
+ if(verbose) {
+ cat("\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
+ if(any(y2==0)){
+ cat("\n Zeros in series:")
+ cat("\n ", names(y2)[y2==0])
+ }
+ else cat("Zeros in series: 0 \n")
+ }
y2[y2 == 0] <- 0.001
resids <- list()
@@ -101,6 +129,11 @@
}
resids$ModNegExp <- y2 / ModNegExp
do.mne <- TRUE
+ if(verbose) {
+ cat("\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
+ "\n Detrend by ModNegExp.",
+ "\n How on earth to extract what we need?\n")
+ }
} else {
do.mne <- FALSE
}
@@ -114,6 +147,12 @@
nyrs2 <- floor(nY2 * 0.67)
else
nyrs2 <- nyrs
+ if(verbose) {
+ cat("\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
+ "\n Detrend by spline.",
+ "\n Spline parameters",
+ "\n nyrs =", nyrs2," f =", f)
+ }
Spline <- ffcsaps(y=y2, x=seq_len(nY2), nyrs=nyrs2, f=f)
if (any(Spline <= 0)) {
warning("Spline fit is not all positive")
@@ -128,6 +167,11 @@
if("Mean" %in% method2){
## Fit a horiz line
Mean <- rep.int(mean(y2), nY2)
+ if(verbose) {
+ cat("\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
+ "\n Detrend by mean.",
+ "\n Mean =",mean(y2))
+ }
resids$Mean <- y2 / Mean
do.mean <- TRUE
} else {
@@ -135,6 +179,12 @@
}
if("Ar" %in% method2){
## Fit an ar model - aka prewhiten
+ if(verbose) {
+ ar.tmp <- ar(y2)
+ cat("\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~",
+ "\n Detrend by prewhitening.")
+ print(ar.tmp)
+ }
Ar <- ar.func(y2)
# This will propogate NA to rwi as a result of detrending.
# Other methods don't. Problem when interacting with other
Modified: pkg/dplR/TODO
===================================================================
--- pkg/dplR/TODO 2014-04-11 11:14:54 UTC (rev 810)
+++ pkg/dplR/TODO 2014-04-11 21:58:44 UTC (rev 811)
@@ -1,3 +1,10 @@
+o[mvkorpel] Mikko, I started working on the verbose option for detrend.series.
+ There are some things to take care of in there that you can likely do
+ better than I can.
+- What is the best way to extract the parameters with ModNegExp?
+- In detrend() the call to detrend.series doesn't appear to pass the names
+ in to detrend.series when dopar is invoked. Is that right?
+
* Write more vignettes:
- Crossdating
- Spectral and wavelets
@@ -8,15 +15,6 @@
implemented in interseries.cor - but will have to do this throughout.
The default should be spearman.
-* In detrend.series there should be a verbose option that writes
- how a series is handled including the parameters of the model.
-- Things to keep track of (not in order):
- 1. Number of zero values and where they are are (what years).
- 2. What method is being used
- 3. For the method the relevant parameters. E.g., at params of an nls model,
- ar coef, etc.
- 4. What else?
-
* 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? Same for
Modified: pkg/dplR/man/detrend.Rd
===================================================================
--- pkg/dplR/man/detrend.Rd 2014-04-11 11:14:54 UTC (rev 810)
+++ pkg/dplR/man/detrend.Rd 2014-04-11 21:58:44 UTC (rev 811)
@@ -9,7 +9,8 @@
detrend(rwl, y.name = names(rwl), make.plot = FALSE,
method = c("Spline", "ModNegExp", "Mean", "Ar"), nyrs = NULL,
f = 0.5, pos.slope = FALSE,
- constrain.modnegexp = c("never", "when.fail", "always"))
+ constrain.modnegexp = c("never", "when.fail", "always"),
+ verbose=FALSE)
}
\arguments{
@@ -42,6 +43,8 @@
\item{constrain.modnegexp}{ a \code{character} string which controls
the constraints of the \code{"ModNegExp"} model. See
\code{\link{detrend.series}} for further details. }
+
+ \item{verbose}{ logical. Write out details? }
}
\details{
Modified: pkg/dplR/man/detrend.series.Rd
===================================================================
--- pkg/dplR/man/detrend.series.Rd 2014-04-11 11:14:54 UTC (rev 810)
+++ pkg/dplR/man/detrend.series.Rd 2014-04-11 21:58:44 UTC (rev 811)
@@ -9,7 +9,8 @@
detrend.series(y, y.name = "", make.plot = TRUE,
method = c("Spline", "ModNegExp", "Mean", "Ar"),
nyrs = NULL, f = 0.5, pos.slope = FALSE,
- constrain.modnegexp = c("never", "when.fail", "always"))
+ constrain.modnegexp = c("never", "when.fail", "always"),
+ verbose=FALSE)
}
\arguments{
@@ -47,6 +48,7 @@
constrained solution, even if the unconstrained one would have been
valid. See \sQuote{Details}. }
+ \item{verbose}{ logical. Write out details? }
}
\details{
This detrends and standardizes a tree-ring series. The detrending is
More information about the Dplr-commits
mailing list