forecast arma error

Hi,

I wanted to use an arma model for predicting, but anyway I got an error message:
Error in is.constant(y) : (list) object cannot be coerced to type 'double'

I am enclosing my small code to reproduct.

x <- c(
-0.182630330550825,
1.43776588036681,
2.81481681390906,
2.0113407663576,
-0.701010275551003,
-0.543605230932999,
0.228593962609001,
0.414170620057577,
1.038825346349,
1.321791599367,
0.458189267809001,
1.03731027525758,
-0.640838732051002,
-0.566790156132998,
-1.910649484891,
-0.476501028142424,
1.478356433449,
1.932462299167,
2.690297016909,
0.825146989857574,
0.232721912249001,
1.507414635867,
-1.314016630591,
1.43001973795758,
0.667089291048995,
-0.505273901232996,
-0.479567091690999,
0.513509557457573,
1.210212965549,
-0.999737343932998,
-2.164102011291,
-1.28907021054242,
-0.357218283950999,
0.811356608466999,
-0.0728665757910001,
-0.627909791542423,
1.259364825149,
2.201785862767,
0.714519655109001,
0.386484342457573,
-0.292395132551
)

arma2 <- tseries::arma(x, order = c(2, 0), include.intercept = F)
arma2
forecast::forecast(arma2)
predict(arma2)

Thank you for your help in advance

Bad argument to forecast

suppressPackageStartupMessages({library(forecast)
                               library(tseries)})
x <- c(
  -0.182630330550825,
  1.43776588036681,
  2.81481681390906,
  2.0113407663576,
  -0.701010275551003,
  -0.543605230932999,
  0.228593962609001,
  0.414170620057577,
  1.038825346349,
  1.321791599367,
  0.458189267809001,
  1.03731027525758,
  -0.640838732051002,
  -0.566790156132998,
  -1.910649484891,
  -0.476501028142424,
  1.478356433449,
  1.932462299167,
  2.690297016909,
  0.825146989857574,
  0.232721912249001,
  1.507414635867,
  -1.314016630591,
  1.43001973795758,
  0.667089291048995,
  -0.505273901232996,
  -0.479567091690999,
  0.513509557457573,
  1.210212965549,
  -0.999737343932998,
  -2.164102011291,
  -1.28907021054242,
  -0.357218283950999,
  0.811356608466999,
  -0.0728665757910001,
  -0.627909791542423,
  1.259364825149,
  2.201785862767,
  0.714519655109001,
  0.386484342457573,
  -0.292395132551
)
arma2 <- tseries::arma(x, order = c(2, 0), include.intercept = F)
str(arma2)
#> List of 12
#>  $ coef             : Named num [1:2] 0.554 -0.213
#>   ..- attr(*, "names")= chr [1:2] "ar1" "ar2"
#>  $ css              : num 44.8
#>  $ n.used           : int 41
#>  $ residuals        : num [1:41] NA NA 1.979 0.758 -1.215 ...
#>  $ fitted.values    : Time-Series [1:41] from 1 to 41: NA NA 0.836 1.253 0.514 ...
#>  $ series           : chr "x"
#>  $ frequency        : num 1
#>  $ call             : language tseries::arma(x = x, order = c(2, 0), include.intercept = F)
#>  $ vcov             : num [1:2, 1:2] 0.0222 -0.0101 -0.0101 0.0223
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:2] "ar1" "ar2"
#>   .. ..$ : chr [1:2] "ar1" "ar2"
#>  $ lag              :List of 1
#>   ..$ ar: int [1:2] 1 2
#>  $ convergence      : int 0
#>  $ include.intercept: logi FALSE
#>  - attr(*, "class")= chr "arma"

#forecast::forecast
# object argument must be a time series or time series model for which forecasts are required

Created on 2020-08-17 by the reprex package (v0.3.0)

but how would the solution look like then?

For example if I want 10 quarter to forecast with this model?

To use forecast you have to give it a time series, not an arma list

You are mixing the tseries package and the forecast package which causes problems. You can fit the equivalent model using the forecast package like this:

arma2 <- forecast::Arima(x, order=c(2,0,0), include.constant = TRUE)
arma2
#> Series: x 
#> ARIMA(2,0,0) with non-zero mean 
#> 
#> Coefficients:
#>          ar1      ar2    mean
#>       0.4906  -0.2540  0.3600
#> s.e.  0.1515   0.1505  0.2131
#> 
#> sigma^2 estimated as 1.168:  log likelihood=-59.95
#> AIC=127.91   AICc=129.02   BIC=134.76
forecast::forecast(arma2)
#>    Point Forecast     Lo 80    Hi 80     Lo 95    Hi 95
#> 42     0.03322998 -1.351842 1.418301 -2.085054 2.151514
#> 43     0.36544236 -1.177342 1.908227 -1.994042 2.724927
#> 44     0.44570945 -1.097185 1.988604 -1.913944 2.805363
#> 45     0.40069643 -1.152859 1.954251 -1.975261 2.776654
#> 46     0.35822214 -1.197626 1.914070 -2.021243 2.737687
#> 47     0.34881864 -1.207037 1.904674 -2.030657 2.728294
#> 48     0.35499505 -1.201042 1.911032 -2.024758 2.734748
#> 49     0.36041405 -1.195658 1.916486 -2.019393 2.740221
#> 50     0.36150366 -1.194569 1.917576 -2.018304 2.741311
#> 51     0.36066162 -1.195414 1.916737 -2.019151 2.740474

Created on 2020-08-20 by the reprex package (v0.3.0)

1 Like

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