[Xts-commits] r627 - in pkg/xtsExtra: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 13 17:54:20 CEST 2012


Author: weylandt
Date: 2012-06-13 17:54:20 +0200 (Wed, 13 Jun 2012)
New Revision: 627

Added:
   pkg/xtsExtra/R/acf.R
   pkg/xtsExtra/man/acf.xts.Rd
Modified:
   pkg/xtsExtra/NAMESPACE
   pkg/xtsExtra/R/plot.R
Log:
Basic infrastructure for acf & pacf

Modified: pkg/xtsExtra/NAMESPACE
===================================================================
--- pkg/xtsExtra/NAMESPACE	2012-06-06 19:16:44 UTC (rev 626)
+++ pkg/xtsExtra/NAMESPACE	2012-06-13 15:54:20 UTC (rev 627)
@@ -1,5 +1,21 @@
-# exportPattern("^[[:alpha:]]+")
-# Won't want to export everything eventually (obviously)
+## Graphics
+
 export("plot.xts")
-export("barplot.xts")
+# export("barplot.xts") -- Not yet ready
 S3method(plot, xts)
+
+## Analytics
+
+export("acf")
+# export("acf.xts")
+# export("pacf.xts")
+# export("acf.ts")
+# export("acf.default")
+
+S3method(acf, default)
+S3method(acf, xts)
+S3method(acf, ts)
+
+S3method(pacf,xts)
+
+## Data frame capability
\ No newline at end of file

Added: pkg/xtsExtra/R/acf.R
===================================================================
--- pkg/xtsExtra/R/acf.R	                        (rev 0)
+++ pkg/xtsExtra/R/acf.R	2012-06-13 15:54:20 UTC (rev 627)
@@ -0,0 +1,23 @@
+acf <- function(x, ...){
+  UseMethod("acf")
+}
+
+# Why do we need this? Shouldn't this dispatch to acf.default?
+acf.ts <- stats::acf 
+
+acf.default <- stats::acf
+
+acf.xts <- function(x, ...){
+  if(!is.regular(x)) warning("Input series is not regular -- treating as such but methods may not be reliable.")
+  if(NCOL(x) > 1L) warning("Using only the first column.")
+  
+  acf(coredata(x[,1, drop = FALSE]), ...)
+  
+}
+
+pacf.xts <- function(x, lag.max, plot, na.action, ...){
+  if(!is.regular(x)) warning("Input series is not regular -- treating as such but methods may not be reliable.")
+  if(NCOL(x) > 1L) warning("Using only the first column.")
+  
+  stats::pacf.default(coredata(x[,1, drop = FALSE]), lag.max, plot, na.action, ...)
+}

Modified: pkg/xtsExtra/R/plot.R
===================================================================
--- pkg/xtsExtra/R/plot.R	2012-06-06 19:16:44 UTC (rev 626)
+++ pkg/xtsExtra/R/plot.R	2012-06-13 15:54:20 UTC (rev 627)
@@ -30,6 +30,7 @@
 #    COLOR GRADIENT FOR SCATTERPLOT CASE
 #    Combine OHLC and multi-panel (i.e., if passed cbind(SPY, AGG)) 
 #    candle.col is not supported? 
+#    ohlc bars
 #    ylab.loc = c("left", "right", "out","in","flip","above") -- above kills panel alignment automatically
 #    Refactor plotting functionality into some non-exported bits
 #    It stopped handling ylab when I did the axis hardcoding -- should be smarter
@@ -76,6 +77,17 @@
   main <- if(!("main" %in% names(dots))) deparse(substitute(x)) else dots[["main"]]
   
   x <- try.xts(x)
+						   
+  if("xlim" %in% names(dots)){
+	  xlim <- dots[["xlim"]]
+	
+	  if(is.numeric(x)){  
+	    warning("Numeric xlim not yet supported.")  
+	  }  
+	  if(is.character(xlim)){  
+	    x <- x[xlim, , drop = FALSE]
+	  }
+  }
   
   # Catch OHLC case independently
   if("type" %in% names(dots) && dots[["type"]] %in% c('candles','bars')){
@@ -96,8 +108,10 @@
     # For now, loop over screens one by one constructing relevant elements
     for(i in seq_along(levels((screens)))){
       x.plot <- x.split[[i]]
-      # Set Margins if we are plotting x-time here?
+    
       
+      # Set Margins for each panel here!
+      
       # Handle the screen-wise parameters here
       if("ylab" %in% names(dots)) {
         ylab.panel <- get.elm.recycle(dots[["ylab"]],i)
@@ -173,6 +187,8 @@
     layout.screens <- seq_along(levels(screens))
   }
   
+  layout.screens <- as.matrix(layout.screens)
+  
   # Would like to use do.call and as.list so pro-users can pass widths and heights
   # to layout -- currently undocumented behavior
   # do.call("layout", as.list(layout.screens)) 
@@ -272,3 +288,4 @@
     get.elm.recycle(split(rep(if(length(levels(screens)) == 1L) list(dots[[par]]) else dots[[par]],
      length.out = length(screens)), screens), n)
 }
+  
\ No newline at end of file

Added: pkg/xtsExtra/man/acf.xts.Rd
===================================================================
--- pkg/xtsExtra/man/acf.xts.Rd	                        (rev 0)
+++ pkg/xtsExtra/man/acf.xts.Rd	2012-06-13 15:54:20 UTC (rev 627)
@@ -0,0 +1,20 @@
+\name{acf.xts}
+\alias{acf.xts}
+\alias{pacf.xts}
+\alias{acf}
+\alias{acf.default}
+\alias{acf.ts}
+\title{ Autocorrelation for xts Objects }
+\description{(Partial) autocorrelation functions for xts objects}
+\usage{
+\method{acf}{xts}(x, ...)
+}
+\arguments{
+  \item{x}{ an \code{xts} object }
+  \item{...}{ additional arguments to be passed to the \code{stats} function which drives these methods.}
+}
+\details{
+  Currently little more than thin wrappers to \code{stats::acf} and \code{stats::pacf.default} for xts objects. Will receive increased functionality going forward. See documentation of those functions for more information about the calculation mechanisms.
+}
+\value{An \code{acf} or \code{pacf} object as appropriate.}
+\author{ Michael Weylandt }
\ No newline at end of file



More information about the Xts-commits mailing list