'Holt Winters : Time series has no less than 2 periods
I am trying to fit Holt winters on daily data with 310 rows excluding weekends.
Date DOTW Volume Lag1
11-2-20 Mon 320 320
11-3-20 Tue 400 320
11-4-20 Wed 350 400
12-2-20 Mon 200 350
12-3-20 Tue 350 200
12-4-20 Wed 500 350
Below is the code used
library(forecast)
library(dplyr)
library(lubridate)
# reading dataset and modifying date variable
df <- read.csv("daily_forecast.csv")
colnames(df)[1]<-'Date'
df[['Date']] <- strptime(df[['Date']], format="%m/%d/%Y")
df<- arrange(df, Date)
df[['Date']] <- format(as.POSIXct(df[,'Date'],format='%m/%d/%Y'),format='%m/%d/%Y')
extended_data <- df[,c('Date','Actual_Volume')]
for(i in 1:31){
extended_data[nrow(df)+i,'Date'] = as.character(mdy(df[nrow(df),'Date'])+i)
extended_data[nrow(df)+i,'Actual_Volume'] = NA
}
for(i in 1:nrow(df)){
extended_data[i,'Date'] <- as.character(mdy(extended_data[i,'Date']))
}
extended_data_mod <- extended_data %>%
dplyr::mutate(.,months=lubridate::month(Date),years=lubridate::year(Date),
day_of_week=lubridate::wday(Date))
a <- min(which(is.na(extended_data_mod[,'Actual_Volume'])))
time <- ts(extended_data_mod[1:(a-1),],frequency=261,start=c(lubridate::year(extended_data_mod[1,1]),lubridate::month(extended_data_mod[1,1])))
fit5 <- HoltWinters(time)
value5 <- predict(fit5,(a-1),prediction.interval=TRUE,level=0.95)
I receive the following error,
Error in decompose(ts(x[1L:wind], start = start(x), frequency = f), seasonal) : time series has no or less than 2 periods
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
