Search code examples
rtime-seriesforecast

Forecasting 'tslm' receiving unused argument error


here is my code:

library(forecast)
oldstuff<-read.table(text="Week Forecast     Actual prevAccuracy
                 49 2018-12-03  6775906  280215.00   0.01723065
                 50 2018-12-10  3659630  740035.90   0.05604323
                 51 2018-12-17  4009861       0.00   0.22264551
                 52 2018-12-24  4262533   92620.51   0.24447944
                 53 2018-12-31  4463402 3109617.17   0.19740596
                 54 2019-01-07  4786782 1881454.00   0.02625039
                 55 2019-01-14  4771027 1091031.00   0.02115797
                 56 2019-01-21  5382587 5095186.83   0.06343317")
newstuff<-read.table(text="  Week Forecast prevAccuracy
                     57 2019-01-28  1124392    0.8382692
                     58 2019-02-04  2161792    0.9130823
                     59 2019-02-11  2480092    0.6848097
                     60 2019-02-18  3197242    0.6848097")
oldstuffts<- ts(oldstuff, freq=365.25/7, start=2018 + 337/365.25)
oldstuffmodel <- tslm(Actual~Forecast + prevAccuracy, data=oldstuffts)
forecast(oldstuffmodel, newdata=newstuff)

And when I attempt to forecast my model, I receive this error:

Error in forecast(oldstuffmodel, newdata = newstuff) : 
  unused argument (newdata = newstuff)

How can I get the forecast function to work?


Solution

  • Apparently a forecast function from some other package gets used. Instead you can specify that you want to use the one from the forecast package:

    forecast::forecast(oldstuffmodel, newdata = newstuff)
    #          Point Forecast     Lo 80   Hi 80     Lo 95    Hi 95
    # 2019.076      -921205.5 -10112280 8269869 -16929516 15087105
    # 2019.095      -930932.3 -11151447 9289583 -18732243 16870378
    # 2019.114      -304598.4  -7883188 7273991 -13504405 12895208
    # 2019.133      -181770.1  -7936566 7573026 -13688480 13324940