Hi all,
I want to ask you if somebody could tell me why my code with Holt-Winters calculation doesn't work.
I use this code for different countries and it works fine but for one country it doesn't work correctly.
I've never used R before so, I'm not sure what is wrong. Please could somebody help?
Below is my code.
It takes data from csv file and creates 3 new files.
But when I use data below the code, it creates only 2 files (SMA and Seasonality)
I've added picture of code error as well
Loading Packages
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
packages <- c("Rcpp","tseries","quadprog","fracdiff","colorspace","zoo","timeDate","timeSeries","forecast","TTR","xts")
ipak(packages)
#Country Models
#================================================================================
ie<-read.csv(file="Y:\\Bayes\\1903\\In\\ie.csv", head=TRUE, sep=",")
ietimeseries<-ts(ie,frequency=12, start=c(2017,1))
ietimeseries
ietimeseriesforecasts <-HoltWinters(ietimeseries)
ietimeseriesforecasts
ietimeseriesforecast2 <-forecast:::forecast.HoltWinters(ietimeseriesforecasts, h=24)
write.csv(ietimeseriesforecast2,"Y:\\Bayes\\1903\\Out\\ie_1903FX.csv")
ietimeseriescomponent <-decompose(ietimeseries)
ietimeseriescomponent
ietimeseriesseasonaladjusted <- ietimeseries - ietimeseriescomponent$seasonal
ieLevelSMA3 <-SMA(ietimeseriesseasonaladjusted, n=3)
write.csv(ieLevelSMA3,"Y:\\Bayes\\1903\\Out\\ie_1903_SMA_Level.csv")
write.csv(ietimeseriescomponent$seasonal, "Y:\\Bayes\\1903\\Out\\ie_1903Seasonality.csv")
#------------------------------------------------------------------------------------------------------------------------
Input data:
46.76
54.12
55.2
52.42
54.69
50.59
52.32
52.54
50.32
46.5
55.71
52.74
54.64
53.7
53.15
65.85
61.13
51.07
60.66
52.25
61.95
63.82
66.24
45.66
58.22
58.44
52.2
59.29