robjhyndman / forecast

Forecasting Functions for Time Series and Linear Models
http://pkg.robjhyndman.com/forecast
1.1k stars 340 forks source link

auto.arima error: " Error in seq.int(trunc((start - xtsp[1L]) * xfreq + 1.5), trunc((end - : 'from' must be of length 1 " #946

Closed osman-gencyurek closed 2 months ago

osman-gencyurek commented 9 months ago

I have a minutely data to forecast. I defined my ts similar as I defined for hourly data (which is working) as below:

How I define ts for hourly data (which is working):

tsSerie <- ts(data = DataTrain$HourlySerie,

                 start = c(Serie.StartYear  <- as.numeric(substr(min(period_vec),1,4))
                              ,Serie.StartMonth <- as.numeric(substr(min(period_vec),5,6))
                              ,Serie.StartDay   <- as.numeric(substr(min(period_vec),7,8))
                              ,Serie.StartHour  <- as.numeric(substr(min(period_vec),9,10))) ,

                  end =  c(Serie.EndYear    <- as.numeric(substr(max(period_vec),1,4))
                               ,Serie.EndMonth   <- as.numeric(substr(max(period_vec),5,6))
                               ,Serie.EndDay     <- as.numeric(substr(max(period_vec),7,8))
                              ,Serie.EndHour    <- as.numeric(substr(max(period_vec),9,10))) ,

                 frequency = 8766)

How I define ts for minutely data (which I have the error for auto.arima):

tsSerie <- ts(data = DataTrain$MinutelySerie,

                 start =c( Serie.StartYear  <- as.numeric(substr(min(period_vec),1,4))
                               ,Serie.StartMonth <- as.numeric(substr(min(period_vec),5,6))
                               ,Serie.StartDay   <- as.numeric(substr(min(period_vec),7,8))
                               ,Serie.StartHour  <- as.numeric(substr(min(period_vec),9,10))
                               ,Serie.StartMin  <- as.numeric(substr(min(period_vec),11,12)) 
                               ) ,

                  end =  c(Serie.EndYear    <- as.numeric(substr(max(period_vec),1,4))
                               ,Serie.EndMonth   <- as.numeric(substr(max(period_vec),5,6))
                               ,Serie.EndDay     <- as.numeric(substr(max(period_vec),7,8))
                               ,Serie.EndHour    <- as.numeric(substr(max(period_vec),9,10))
                               ,Serie.EndMin    <- as.numeric(substr(max(period_vec),11,12))
                               ) ,

                 frequency = 525960)

then I try to run auto.arima like below:

ARIMAfit <- forecast::auto.arima(log(tsSerie +1), approximation=FALSE, trace=FALSE, seasonal=TRUE)

then I get following error:

Error in seq.int(trunc((start - xtsp[1L]) * xfreq + 1.5), trunc((end -  : 
  'from' must be of length 1

Could you please help me to solve this please?

robjhyndman commented 9 months ago

First, this is not reproducible. I don't have period_vec or DataTrain objects. Please provide a reproducible example. You don't have to share the real data. Just simulate something of the same structure.

Second, start and end should be either single numbers or vectors of two numbers. See the help file for ts(). So I don't know what this code is doing.

With high-frequency sub-daily data, it is much easier to use the tsibble data structure with the fable package for forecasting. The forecast package uses ts objects, which works fine for low frequency data such as monthly or quarterly observations, but the ts data structure is not really designed for high frequency observations.