'R timeseries :Error in lapply(listed_ts, function(x) auto.arima(x, allowmean = F)) : object 'listed_ts' not found

I want to do a weekly time series analysis for each sales_point_id separately with the results of fact value and what was predicted.

dput()

timeseries=structure(list(sales_point_id = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L), calendar_id_operday = c(1L, 2L, 3L, 4L, 5L, 6L, 
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 
20L, 21L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L), line_fact_amt = c(55767L, 
59913L, 36363L, 48558L, 505L, 76344L, 22533L, 11965L, 78944L, 
36754L, 30621L, 55716L, 32470L, 62165L, 57986L, 2652L, 16487L, 
72849L, 73715L, 65656L, 64411L, 47460L, 61866L, 10877L, 72392L, 
53011L, 23544L, 76692L, 10388L, 24255L, 56684L, 59329L, 6655L, 
65612L, 17495L, 10389L, 63702L, 47407L, 78782L, 22898L, 21151L, 
32587L)), class = "data.frame", row.names = c(NA, -42L))

i need weekly forecast and week=1 its mean 20210101-20210108(ymd) but here there is no date format only week, just such a specificity of these data . Here are my futile attempts

library("lubridate")
# first the grouping variable
timeseries$group <- paste0(timeseries$sales_point_id)

groups <- unique(timeseries$group)
# find starting date per group and save them as a list of elements
timeseries$date <- as.Date(as.character(timeseries$calendar_id_operday), )
timeseries <- timeseries[order(timeseries$calendar_id_operday),]
start_dates <- format(timeseries$date[match(groups, timeseries$group)], )
start_dates <- strsplit(start_dates, ' ')

listed <- split(timeseries,timeseries$group)
str(listed)

listed_ts
listed_arima <- lapply(listed_ts,function(x) auto.arima(x,allowmean = F )) 
#Now the forecast for each arima:
listed_forecast <- lapply(listed_arima,function(x) forecast(x,12) )# forecast 12 weeks ahead
listed_forecast

# need to flat it down to a data.frame, do.call and rbind help:
do.call(rbind,listed_forecast)


#Get a prediction of initial values

lapply(listed_arima, fitted)


 Error in lapply(listed_ts, function(x) auto.arima(x, allowmean = F))

What i do wrong and how fix to correct working of timeseries. my ideal and desired result as just sample output format .

   sales_point_id calendar_id_operday line_fact_amt.fact
1               1                   1                436
2               1                   2                 56
3               1                   3                 66
4               1                   4                NaN
5               1                   5                NaN
6               1                   6                NaN
7               1                   7                NaN
8               1                   8                NaN
9               1                   9                NaN
10              1                  10                NaN
11              1                  11                NaN
12              1                  12                NaN
13              1                  13                NaN
14              1                  14                NaN
15              1                  15                NaN
   line_fact_amt.predict forecast.ahead
1                    435            NaN
2                     57            NaN
3                     70            NaN
4                    NaN            524
5                    NaN            945
6                    NaN            235
7                    NaN            200
8                    NaN            326
9                    NaN            437
10                   NaN              7
11                   NaN            191
12                   NaN            321
13                   NaN            919
14                   NaN            407
15                   NaN             82

As always I appreciate any of your help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source