Why am I getting same forecast pattern for both the years (2016 and 2017) in holt winters method? What is wrong with my code?

rstudio
time-series
forecast
#1

image
I am forecasting rainfall of India using holt winters method. Data is from year 2000 to 2015. I am using monthly data.

library(readxl)
require(graphics)
library(forecast)
library(timeSeries)
library (tseries)
library(ggplot2)
library(TTR)
rn <- read.csv("data/karnataka_rain.csv", stringsAsFactors = FALSE)
r <- ts(rn$rain, start = c(2000, 1), end=c(2015,12),frequency = 12)
head(rn$rain)
plot.ts(r, ylab= "rain", xlab= "year")
decomp_rn <- decompose(r)
plot(decomp_rn)
adf.test(r, alternative = "stationary")
forecast_model <- HoltWinters(r)
forecast_model
plot(forecast_model)
forecast_values <- forecast(forecast_model, h = 24,
level = c(0.85,0.95))
forecast_values
plot(forecast_values)

0 Likes

#2

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

0 Likes

#3

1.4
15.5
0.3
46.3
59.3
167.5
200.5
300.6
183.5
206.2
14.1
12.1
0.5
1.1
1.7
90.6
30.4
127.2
168.2
152
189.9
122.7
40
2.1
2
11.4
2.3
20.6
77.2
131.9
92.6
155.1
74.9
168.4
18.8
0.6
0.1
4.2
20.1
36.4
9.6
118.2
162.5
152.2
51.9
192.4
11.5
3.6
9.1
12.8
16.4
62.2
180.2
196.6
191.7
211.1
117.5
101.5
24
10.4
7.2
3.9
3.2
76
74.7
138.7
333.5
233.2
145.5
241.8
56.3
5.3
0.2
0.1
35.4
24.7
127.1
183.7
226.7
172.9
112
61.7
84.9
1.1
Thanks for responding. these are the values of rain from 2000-2007. Kindly help

0 Likes

#4

Hi Deepika,

please put these values, and the rest of your code, in reproducible example as explained in the link I gave you. Did you read the link?

2 Likes

#6

Hi Andrea,
Please find the dataset below in the suggested format.

datapasta::df_paste(head(rn, 85))
data.frame(
Year = c(2000L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA),
month = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L),
rain = c(1.4, 15.5, 0.3, 46.3, 59.3, 167.5, 200.5, 300.6, 183.5, 206.2,
14.1, 12.1, 0.5, 1.1, 1.7, 90.6, 30.4, 127.2, 168.2, 152,
189.9, 122.7, 40, 2.1, 2, 11.4, 2.3, 20.6, 77.2, 131.9, 92.6, 155.1,
74.9, 168.4, 18.8, 0.6, 0.1, 4.2, 20.1, 36.4, 9.6, 118.2,
162.5, 152.2, 51.9, 192.4, 11.5, 3.6, 9.1, 12.8, 16.4, 62.2, 180.2,
196.6, 191.7, 211.1, 117.5, 101.5, 24, 10.4, 7.2, 3.9, 3.2, 76,
74.7, 138.7, 333.5, 233.2, 145.5, 241.8, 56.3, 5.3, 0.2, 0.1,
35.4, 24.7, 127.1, 183.7, 226.7, 172.9, 112, 61.7, 84.9, 1.1, 0.1)
)

0 Likes

#7

#Please find the code in suggested format
library(readxl)
require(graphics)
library(forecast)
library(timeSeries)
library (tseries)
library(ggplot2)
library(TTR)
rn <- read.csv("data/karnataka_rain.csv", stringsAsFactors = FALSE)
head(rn,85)
r <- ts(rn$rain, start = c(2000, 1), end=c(2015,12),frequency = 12)
head(rn$rain)
plot.ts(r, ylab= "rain", xlab= "year")
decomp_rn <- decompose(r)
plot(decomp_rn)
adf.test(r, alternative = "stationary")
forecast_model <- HoltWinters(r)
forecast_model
plot(forecast_model)
forecast_values <- forecast(forecast_model, h = 24,
level = c(0.85,0.95))
forecast_values
plot(forecast_values)

0 Likes

#8

While we're getting no luck with reprex, let me just comment that you are not getting the same forecast for both 2016 and 2017. Your 85 and 95 estimates are obviously wider for 2017 than they are for 2016, this much is visible from your plot. That's the start.

From the code you posted in here, it seems as you haven't tuned your forecasting one bit, which means it will make the best guess and plug in the default parameters.

Regardless, I am not surprised one bit with this result. Your data has obvious seasonality, but no clear trend, and therefore the forecasted values should be static, as there is no trend (I mean, what direction did you really expect it to go?)

Here is a little cheat sheet on that.
hero_8140dd44-0a5b-48e3-bd4e-d290ae843130

2 Likes

#9

Hi taras,

I understand that there is no trend. I feel the model is not capturing seasonality properly. Can you please suggest, what should I do to improve the model and forecast?

0 Likes

#10

The first best thing you can do to get help here is to create a working reproducible example :wink:

The second best thing is to read up more on time-series forecasting in general and exponential smoothing in particular. :wink:

I am as far as it gets from working with time-series forecasting or understanding how it works, but my 2 cents, FWIW, is for you to read up on every parameter that goes into Holt-Winter's forecasting (why this algorithm, BTW?) and tweak them according to your needs.

I am not sure about your conclusions about not capturing seasonality well. From what it looks like, it captures seasonality pretty well, to the best of its ability. It does tend to rely on the most recent values most heavily, but that's the essence of exponential smoothing. Remember that exponential smoothing, in a nutshell, can be described by the formula
24%20AM
where α is your constant and determines the rate of learning (hence exponential smoothing, as the rate of learning "fades away" exponentially).
Tweaking α would give you a different point estimate, but I still think you'd have very similar forecasts for both 2016 and 2017.


My "expertise" in t.s. forecasting begins and ends with this free 6-week-long course on it: https://www.futurelearn.com/courses/business-analytics-forecasting (Plus a bit of implementation at work, but not enough to be an expert). So, take my words with a grain of salt. There are far more qualified people here to help you.

1 Like

#11

I do some forecasting at work and I also don't really see anything obviously wrong with the forecast you've produced in the graph. What is it that makes you think it's not producing a useful forecast? Given the history shown on the graph I'd expect the forecast to basically reproduce the same seasonal pattern into the future and that is what's happening here. And the seasonality is yearly so there's no reason 2016 and 2017 would look very different (apart from wider confidence intervals for 2017 as @taras already noted).

1 Like

#12

Thanks a lot Taras. I will take a look at the link you have provided. :innocent:

1 Like

closed #13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

0 Likes