Multivariate time series in R 3 vs R 2

5 messages
Open this post in threaded view
|

Multivariate time series in R 3 vs R 2

 Hello! Recently I got report that my package mar1s doesn't pass checks any more on R 3.0.2. I started to investigate and found the following difference in multivariate time series handling in R 3.0.2 compared to R 2 (I've checked on 2.14.0). Suppose I wish to calculate seasonal component for time series. In case of multivariate time series, I wish to process each column independently. Let f be a simple (trivial) model of seasonal component: f <- function(x)   return(ts(rep(0, length(x)), start = 0, frequency = frequency(x))) In previous versions of R, I used the following compact and efficient expression to calculate seasonal component: y <- do.call(cbind, lapply(x, f)) It worked equally good for univariate and multivariate time series: > R.Version()\$version.string [1] "R version 2.14.0 (2011-10-31)" > t <- ts(1:10, start = 100, frequency = 10) > > x <- t > y <- do.call(cbind, lapply(x, f)) > y Time Series: Start = c(0, 1) End = c(0, 10) Frequency = 10  [1] 0 0 0 0 0 0 0 0 0 0 > > x <- cbind(t, t) > y <- do.call(cbind, lapply(x, f)) > y Time Series: Start = c(0, 1) End = c(0, 10) Frequency = 10     t t 0.0 0 0 0.1 0 0 0.2 0 0 0.3 0 0 0.4 0 0 0.5 0 0 0.6 0 0 0.7 0 0 0.8 0 0 0.9 0 0 But in version 3, I get some frustrating results: > R.Version()\$version.string [1] "R version 3.0.2 (2013-09-25)" > t <- ts(1:10, start = 100, frequency = 10) > > x <- t > y <- do.call(cbind, lapply(x, f)) > y Time Series: Start = 0 End = 0 Frequency = 1   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0 > > x <- cbind(t, t) > y <- do.call(cbind, lapply(x, f)) > y Time Series: Start = 0 End = 0 Frequency = 1   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0   structure(0, .Tsp = c(0, 0, 1), class = "ts") 0                                             0 I didn't watch R development for quite some time now. Could anyone please help me to construct similar expression to what I have used in R 2, for multivariate case (or better, for both univariate and multivariate cases)? Best wishes, Andrey Paramonov         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Open this post in threaded view
|

Re: Multivariate time series in R 3 vs R 2

 This has nothing to do with changes in base R. It is due to changes in the dependent packages. These changes mean that when you call lapply it does not dispatch the right as.list method. The method you want (as.list.ts) is provided by the zoo package. It splits a multivariate time series into a list of univariate time series in the way you are expecting.  Your package mar1s used to depend on zoo indirectly through the fda package. But now fda does not depend on zoo, it only suggests it. So now, when you load your package, zoo is not on the search path and you get the default as.list method, which produces the bad results. The solution is to add "Imports: zoo" to your DESCRIPTION file and "import(zoo)" to your NAMESPACE file. Martyn On Wed, 2013-10-23 at 22:56 +0400, Андрей Парамонов wrote: > Hello! > > Recently I got report that my package mar1s doesn't pass checks any more on > R 3.0.2. I started to investigate and found the following difference in > multivariate time series handling in R 3.0.2 compared to R 2 (I've checked > on 2.14.0). > > Suppose I wish to calculate seasonal component for time series. In case of > multivariate time series, I wish to process each column independently. Let > f be a simple (trivial) model of seasonal component: > > f <- function(x) >   return(ts(rep(0, length(x)), start = 0, frequency = frequency(x))) > > In previous versions of R, I used the following compact and efficient > expression to calculate seasonal component: > > y <- do.call(cbind, lapply(x, f)) > > It worked equally good for univariate and multivariate time series: > > > R.Version()\$version.string > [1] "R version 2.14.0 (2011-10-31)" > > t <- ts(1:10, start = 100, frequency = 10) > > > > x <- t > > y <- do.call(cbind, lapply(x, f)) > > y > Time Series: > Start = c(0, 1) > End = c(0, 10) > Frequency = 10 >  [1] 0 0 0 0 0 0 0 0 0 0 > > > > x <- cbind(t, t) > > y <- do.call(cbind, lapply(x, f)) > > y > Time Series: > Start = c(0, 1) > End = c(0, 10) > Frequency = 10 >     t t > 0.0 0 0 > 0.1 0 0 > 0.2 0 0 > 0.3 0 0 > 0.4 0 0 > 0.5 0 0 > 0.6 0 0 > 0.7 0 0 > 0.8 0 0 > 0.9 0 0 > > But in version 3, I get some frustrating results: > > > R.Version()\$version.string > [1] "R version 3.0.2 (2013-09-25)" > > t <- ts(1:10, start = 100, frequency = 10) > > > > x <- t > > y <- do.call(cbind, lapply(x, f)) > > y > Time Series: > Start = 0 > End = 0 > Frequency = 1 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 > > > > x <- cbind(t, t) > > y <- do.call(cbind, lapply(x, f)) > > y > Time Series: > Start = 0 > End = 0 > Frequency = 1 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > 0                                             0 > > I didn't watch R development for quite some time now. Could anyone please > help me to construct similar expression to what I have used in R 2, for > multivariate case (or better, for both univariate and multivariate cases)? > > Best wishes, > Andrey Paramonov > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Open this post in threaded view
|

Re: Multivariate time series in R 3 vs R 2

 Thank you for your suggestions. But in minimal example I provided I didn't import any package (incl. zoo). However the behavior is different. Something in R has changed between 2.14.0 and 3.0.2. Best wishes, Andrey Paramonov 2013/10/25 Martyn Plummer <[hidden email]> > This has nothing to do with changes in base R. It is due to changes in > the dependent packages. These changes mean that when you call lapply it > does not dispatch the right as.list method. > > The method you want (as.list.ts) is provided by the zoo package. It > splits a multivariate time series into a list of univariate time series > in the way you are expecting.  Your package mar1s used to depend on zoo > indirectly through the fda package. But now fda does not depend on zoo, > it only suggests it. So now, when you load your package, zoo is not on > the search path and you get the default as.list method, which produces > the bad results. > > The solution is to add "Imports: zoo" to your DESCRIPTION file and > "import(zoo)" to your NAMESPACE file. > > Martyn > > > On Wed, 2013-10-23 at 22:56 +0400, ÐÐ½Ð´ÑÐµÐ¹ ÐÐ°ÑÐ°Ð¼Ð¾Ð½Ð¾Ð² wrote: > > Hello! > > > > Recently I got report that my package mar1s doesn't pass checks any more > on > > R 3.0.2. I started to investigate and found the following difference in > > multivariate time series handling in R 3.0.2 compared to R 2 (I've > checked > > on 2.14.0). > > > > Suppose I wish to calculate seasonal component for time series. In case > of > > multivariate time series, I wish to process each column independently. > Let > > f be a simple (trivial) model of seasonal component: > > > > f <- function(x) > >   return(ts(rep(0, length(x)), start = 0, frequency = frequency(x))) > > > > In previous versions of R, I used the following compact and efficient > > expression to calculate seasonal component: > > > > y <- do.call(cbind, lapply(x, f)) > > > > It worked equally good for univariate and multivariate time series: > > > > > R.Version()\$version.string > > [1] "R version 2.14.0 (2011-10-31)" > > > t <- ts(1:10, start = 100, frequency = 10) > > > > > > x <- t > > > y <- do.call(cbind, lapply(x, f)) > > > y > > Time Series: > > Start = c(0, 1) > > End = c(0, 10) > > Frequency = 10 > >  [1] 0 0 0 0 0 0 0 0 0 0 > > > > > > x <- cbind(t, t) > > > y <- do.call(cbind, lapply(x, f)) > > > y > > Time Series: > > Start = c(0, 1) > > End = c(0, 10) > > Frequency = 10 > >     t t > > 0.0 0 0 > > 0.1 0 0 > > 0.2 0 0 > > 0.3 0 0 > > 0.4 0 0 > > 0.5 0 0 > > 0.6 0 0 > > 0.7 0 0 > > 0.8 0 0 > > 0.9 0 0 > > > > But in version 3, I get some frustrating results: > > > > > R.Version()\$version.string > > [1] "R version 3.0.2 (2013-09-25)" > > > t <- ts(1:10, start = 100, frequency = 10) > > > > > > x <- t > > > y <- do.call(cbind, lapply(x, f)) > > > y > > Time Series: > > Start = 0 > > End = 0 > > Frequency = 1 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > > > > > > x <- cbind(t, t) > > > y <- do.call(cbind, lapply(x, f)) > > > y > > Time Series: > > Start = 0 > > End = 0 > > Frequency = 1 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > >   structure(0, .Tsp = c(0, 0, 1), class = "ts") > > 0                                             0 > > > > I didn't watch R development for quite some time now. Could anyone please > > help me to construct similar expression to what I have used in R 2, for > > multivariate case (or better, for both univariate and multivariate > cases)? > > > > Best wishes, > > Andrey Paramonov > > > >       [[alternative HTML version deleted]] > > > > ______________________________________________ > > [hidden email] mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel> >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-devel