I am trying to use ARIMA to forecast the monthly price of fish sales, in euros per kg, with an exogenous variable, the total weight of fish caught that month. I can build the model, but get an error when I try to forecast using the model. I have 108 data points in total and have divided those into a training and test set. The training set has 84 data points and the test set has 24 data points. The error is:

Error in `mutate()`:
ℹ In argument: `arima = (function (object, ...) ...`.
Caused by error in `new_dist()`:
! Can't recycle `mu` (size 84) to match `sigma` (size 24).

I have a df, df_fish, which has the monthly mean price per kg for the fish, along with the total weight caught in each month, for the period January 2014 to December 2022. I have divided it into df_train (January 2014-December 2020, 84 values) and df_test(January 2021-December 2022, 24 values). I build the model with:

arima_fish <- df_train %>%
  model(arima = ARIMA(EurosPerLiveKg  ~ df_train$EstTonne))

report(arima_fish) gives:

Series: EurosPerLiveKg 
Model: LM w/ ARIMA(0,0,0)(0,0,2)[12] errors 

Coefficients:
        sma1    sma2  xreg_train_wt  intercept
        0.1424  0.2308         -3e-04     0.9696
s.e.  0.1408  0.1646          5e-04     0.0435

sigma^2 estimated as 0.06625:  log likelihood=-3.88
AIC=17.76   AICc=18.53   BIC=29.91

When I try to run:

arima_fish %>%
  forecast(h=24, xreg=df_test$EstTonne)

I get the error given above.

Would anyone know what I'm doing wrong? Or how I should be doing it? Thanks

1

There are 1 best solutions below

1
Rob Hyndman On

You seem to be confusing the use of forecast() and dynamic regression modelling in the fable package and the forecast package. See https://otexts.com/fpp3/forecasting.html for examples using the fable package. Your call to forecast() should use the new_data argument, not xreg.