Auto.arima from forecas-Different results for Zoo object and.xts object?

29 Views Asked by At

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

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

1

There are 1 best solutions below

0
Joshua Ulrich On

The zoo package is designed to be an extension of the 'ts' class. While xts extends zoo, it doesn't do a good job maintaining all the attributes required to convert to/from 'ts' seamlessly. So you should convert any xts objects to zoo (using as.zoo()) before passing them to any forecast package functions.