# Prediction period is coming wrong in the HoltWinters in R

I am Using Holt-Winters model for the forecasting.

Below is the way I am proceeding:

x<-read.csv("C:/Users/Navneet/Desktop/retail_data_12_08.csv", header=TRUE)
xf<-data.frame(year_quarter=as.yearqtr(x$year_quarter),sales_revenue=x$sales_revenue)
dput(xf)


output of the dput(xf) is:

structure(list(year_quarter = structure(c(2009, 2009.25, 2009.5,
2009.75, 2010, 2010.25, 2010.5, 2010.75, 2011, 2011.25, 2011.5,
2011.75, 2012, 2012.25), class = "yearqtr"), sales_revenue = c(3008L,
3244L, 8000L, 8719L, 3008L, 3244L, 78L, 7379L, 3735L, 7339L,
17240L, 20465L, 13134L, 15039L)), .Names = c("year_quarter",
"sales_revenue"), row.names = c(NA, -14L), class = "data.frame")

xf.ts<-ts(xf, frequency=4, start=c(2009,1), end=c(2012,2))
print(xf.ts)


output of the above line is:

        year_quarter sales_revenue
2009 Q1      2009.00          3008
2009 Q2      2009.25          3244
2009 Q3      2009.50          8000
2009 Q4      2009.75          8719
2010 Q1      2010.00          3008
2010 Q2      2010.25          3244
2010 Q3      2010.50            78
2010 Q4      2010.75          7379
2011 Q1      2011.00          3735
2011 Q2      2011.25          7339
2011 Q3      2011.50         17240
2011 Q4      2011.75         20465
2012 Q1      2012.00         13134
2012 Q2      2012.25         15039


Now if I am applying the HoltWinters function

fit<-HoltWinters(xf.ts, alpha=NULL, beta=NULL, gamma=NULL, seasonal="additive")
forecast(fit,6)


it shows the 2016 quarters like this:

        Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
2016 Q1       17742.13 18025.67 17458.60 18175.77 17308.50
2016 Q2       18393.12      NaN      NaN      NaN      NaN
2016 Q3       13141.48      NaN      NaN      NaN      NaN
2016 Q4       15606.02 18076.96 13135.09 19385.00 11827.05


It should provide the 2012 Q3, 2012 Q4, 2013 Q1, 2013 Q2, 2013 Q3 and 2013 Q4.

Is there any thing I am doing wrong?

Why are NaN values are coming out in the forecasting?

You are feeding your entire data frame to HoltWinters(), which of course doesn't know it is supposed to work on the sales_revenue column.

This column is already in a quarterly time series format:

> xf.ts[,"sales_revenue"]
Qtr1  Qtr2  Qtr3  Qtr4
2009  3008  3244  8000  8719
2010  3008  3244    78  7379
2011  3735  7339 17240 20465
2012 13134 15039


So all you need to do is call HoltWinters() on that specific column:

> fit <- HoltWinters(xf.ts[,"sales_revenue"],