Auto.arima different results for .xts and .zoo object.

I have time series of Covid-19 death cases which is only weekdays without weekend. I created it in R as .zoo object. But since some packages work better with time series I created it as .xts object as well. Now when I did auto.arima for the same data with zoo object and xts object, the auto.arima paramaters are different. Which one is correct and why?

deathzoo is zoo object and deathzoor is returns and deathxts is .xts object and deathxtsr is returns.

#Required library

library(timeSeries)
library(zoo)
library(tseries)
library(xts)
library(forecast)
  reconstruct<-structure(list(...1 = structure(c(1579651200, 1579737600, 1579824000, 
                                 1580083200, 1580169600, 1580256000, 1580342400, 1580428800, 1580688000, 
                                 1580774400, 1580860800, 1580947200, 1581033600, 1581292800, 1581379200, 
                                 1581465600, 1581552000, 1581638400, 1581897600, 1581984000, 1582070400, 
                                 1582156800, 1582243200, 1582502400, 1582588800, 1582675200, 1582761600, 
                                 1582848000, 1583107200, 1583193600, 1583280000, 1583366400, 1583452800, 
                                 1583712000, 1583798400, 1583884800, 1583971200, 1584057600, 1584316800, 
                                 1584403200, 1584489600, 1584576000, 1584662400, 1584921600, 1585008000, 
                                 1585094400, 1585180800, 1585267200, 1585526400, 1585612800, 1585699200, 
                                 1585785600, 1585872000, 1586131200, 1586217600, 1586304000, 1586390400, 
                                 1586476800, 1586736000, 1586822400, 1586908800, 1586995200, 1587081600, 
                                 1587340800, 1587427200, 1587513600, 1587600000, 1587686400, 1587945600, 
                                 1588032000, 1588118400, 1588204800, 1588291200, 1588550400, 1588636800, 
                                 1588723200, 1588809600, 1588896000, 1589155200, 1589241600, 1589328000, 
                                 1589414400, 1589500800, 1589760000, 1589846400, 1589932800, 1590019200, 
                                 1590105600, 1590364800, 1590451200, 1590537600, 1590624000, 1590710400, 
                                 1590969600, 1591056000, 1591142400, 1591228800, 1591315200, 1591574400, 
                                 1591660800), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
              death = c(17, 18, 26, 82, 131, 133, 172, 214, 428, 494, 566, 
                        636, 721, 1015, 1115, 1120, 1373, 1525, 1870, 2010, 2125, 
                        2250, 2254, 2633, 2713, 2774, 2817, 2876, 3090, 3164, 3260, 
                        3355, 3469, 4009, 4284, 4636, 4957, 5460, 7265, 8117, 9073, 
                        10215, 11789, 17518, 19944, 22915, 26165, 29804, 42040, 47204, 
                        53846, 60087, 66583, 85288, 93805, 101022, 109173, 116914, 
                        136917, 144272, 153036, 160746, 169629, 188670, 195864, 203141, 
                        210412, 217250, 233562, 240188, 247168, 253423, 259010, 274146, 
                        280293, 287056, 292923, 298876, 312208, 317941, 323378, 329130, 
                        334886, 347700, 352668, 358074, 363110, 368816, 378366, 383144, 
                        388363, 393355, 398511, 409902, 415166, 420786, 426314, 431371, 
                        443223, 448268)), row.names = c(NA, 100L), class = "data.frame")

dt <- seq(as.Date("2020-01-22"), as.Date("2020-06-09"), by = "days")
dt<-dt[!weekdays(dt) %in% c("Saturday","Sunday")] # This removes weekends from data.
View(dt)
deathdata<-reconstruct[,2]
deathzoo=zoo(deathdata,dt)
deathxts=xts(deathdata,dt)

#Calculating rate of change similar to returns using both forms

deathxtsr=100*diff(log(deathxts))
deathzoor = 100*diff(log(deathzoo))


arimaxts=auto.arima(deathxtsr)
summary(arimaxts)

arimazoo=auto.arima(deathzoor)
summary(arimazoo)

I am getting different Arima results
[Different Arima results][1]

When I am comparing arima values, they are completely different. I even tried manual arima, by giving the values of p,q,d as suggested by auto arima,I keep getting different answers for .xts and .zoo

auto.arima() requires a ts object, and it will attempt to convert a zoo or xts object to ts. To be sure of getting correct results, it is much better to convert to ts yourself.

In this case, you can see what happens using as.ts():

> as.ts(deathzoo)
Time Series:
Start = 18283 
End = 18422 
Frequency = 1 
  [1]     17     18     26     NA     NA     82    131
  [8]    133    172    214     NA     NA    428    494
 [15]    566    636    721     NA     NA   1015   1115
 [22]   1120   1373   1525     NA     NA   1870   2010
 [29]   2125   2250   2254     NA     NA   2633   2713
 [36]   2774   2817   2876     NA     NA   3090   3164
 [43]   3260   3355   3469     NA     NA   4009   4284
 [50]   4636   4957   5460     NA     NA   7265   8117
 [57]   9073  10215  11789     NA     NA  17518  19944
 [64]  22915  26165  29804     NA     NA  42040  47204
 [71]  53846  60087  66583     NA     NA  85288  93805
 [78] 101022 109173 116914     NA     NA 136917 144272
 [85] 153036 160746 169629     NA     NA 188670 195864
 [92] 203141 210412 217250     NA     NA 233562 240188
 [99] 247168 253423 259010     NA     NA 274146 280293
[106] 287056 292923 298876     NA     NA 312208 317941
[113] 323378 329130 334886     NA     NA 347700 352668
[120] 358074 363110 368816     NA     NA 378366 383144
[127] 388363 393355 398511     NA     NA 409902 415166
[134] 420786 426314 431371     NA     NA 443223 448268
> as.ts(deathxts)
Time Series:
Start = 1 
End = 100 
Frequency = 1 
  [1]     17     18     26     82    131    133    172
  [8]    214    428    494    566    636    721   1015
 [15]   1115   1120   1373   1525   1870   2010   2125
 [22]   2250   2254   2633   2713   2774   2817   2876
 [29]   3090   3164   3260   3355   3469   4009   4284
 [36]   4636   4957   5460   7265   8117   9073  10215
 [43]  11789  17518  19944  22915  26165  29804  42040
 [50]  47204  53846  60087  66583  85288  93805 101022
 [57] 109173 116914 136917 144272 153036 160746 169629
 [64] 188670 195864 203141 210412 217250 233562 240188
 [71] 247168 253423 259010 274146 280293 287056 292923
 [78] 298876 312208 317941 323378 329130 334886 347700
 [85] 352668 358074 363110 368816 378366 383144 388363
 [92] 393355 398511 409902 415166 420786 426314 431371
 [99] 443223 448268

So the missing weekends are included as NAs in the zoo object, but omitted in the xts object. Hence, different models are obtained.

Thank you so much....I had been struggling with this for a week now. Thanks

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.