Search code examples
rtime-seriesforecasting

Conflict between time series packages `forecast` and `aTSA`- how to make it work together in RMarkdown document


I am working on time series analysis and found an interesting error, which I would never realize without this question.

I use two packages: forecast by Hyndman and Athanasopoulos and aTSA.

I have a model

JJ_sarima <- Arima(JJ_data_ts_train, order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 4))

which gives me

Series: JJ_data_ts_train 
ARIMA(0,1,1)(0,1,1)[4] 

Coefficients:
      ma1     sma1
  -0.3419  -0.1849
s.e.   0.1344   0.1389

sigma^2 estimated as 0.001035:  log likelihood=128
AIC=-250   AICc=-249.6   BIC=-243.57

In the same RMarkdown document I do an Augmented Dickey-Fuller test.

adf.test(JJ_data$earnings, nlag = 10)

And when I try to use a forecast function, it does not work.

jj_forecast <- forecast(JJ_sarima, h = 10)

Error in forecast(JJ_sarima, h = 10) : unused argument (h = 10)

If I remove h, I get

Error in forecast(JJ_sarima) : 'object' should be 'Arima' or 'estimate' class estimated from arima() or estimate()

I disable aTSA package, which is necessary in my document, because I cannot run ADF test then.

Error in adf.test(JJ_data$earnings, nlag = 10) : 
could not find function "adf.test"

But them forecast() works, which is weird. But I guess the reason is the function with the same name exists in aTSA.

Any ideas how to make them work together in the RMarkdown? Maybe run in different chunks one by one after performing ADF test, but not a good solution.


Solution

  • We can use the :: to differentiate the package

    forecast::forecast(JJ_sarima, h = 10)