[R] cor() and lagged ts objects

Prof Brian D Ripley ripley at stats.ox.ac.uk
Wed Feb 13 21:15:50 CET 2002


On Wed, 13 Feb 2002, Dirk Eddelbuettel wrote:

>
> The following is internally consistent, but not intuitive:
>
> R : Copyright 2002, The R Development Core Team
> Version 1.4.1  (2002-01-30)
> [...]
> > library(ts)
> > x<-rnorm(100)			# white noise
> > xTS<-ts(x,start=1)		# as time series
> > xTSl<-lag(xTS,lag=-1)		# lagged once
> > cor(xTS,xTSl)			# Big surprise
> [1] 1
> > cor(cbind(xTS,xTSl),use="pairwise")	# what was really meant
>              xTS        xTSl
> xTS   1.00000000 -0.04080141
> xTSl -0.04080141  1.00000000
> >
>
> Is there any way cor() could know that the first call was nonsensical (given
> the semantics of lag) and issue a warning?

cor() doesn't know about time series, does it?  I guess it could.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list