# How to perform forecast using combined fitted lm-model, based on Arima and HoltWinthers models

Attempting to produce a forecast using a combined model consisting of 2 other models (in order to achieve best possible fit), produce suspicious plot, making me think something is up.

Here is the R-code, below it I continue.

`IP <- ts(EXAM2CASE1\$IP, frequency = 12)`
`tsdisplay(IP)`

`IP <- ts(EXAM2CASE1\$IP, frequency = 12)`
#we create the objects with the timeseies in them, and states the frequency to 12

`tsdisplay(IP)`
#timeseries show a clear trend.

# In-sample (75%) and out-of-sample (25%) split

#I set the in-sample and out-of-sample
`insamp_1_IP <- ts(IP[1:567], frequency = 12)`
`outsamp_1_IP <- IP[568:756]`

# # Generating the first forecast based on ARIMA models

#auto-arima creates the first fitted model
`fit_IP <- auto.arima(insamp_1_IP)`
#displays the residuals
`tsdisplay(residuals(fit_IP), main='Model Residuals') #residuals look fairly random`
#creates the forecast, based on fitted model, and set lenght to match outsamp_1
`fcast_IP <- forecast(fit_IP, h=length(outsamp_1_IP))`
`plot(fcast_IP)`
`lines(IP)`
#look at the accuracy
`accuracy(fcast_IP, outsamp_1_IP)`

# Let us try and see if a simpler specification will give better forecasts instead of what auto.arima suggested.

#second fitted model, this time I adjust the model proposed by auto.arima
#I know from the ACF and PACF that its most likely that an AR model will be the best fit, I look for the lowest accuracy parameters such as RMSE and MAPE
`fit2_IP <- Arima(insamp_1_IP, order = c(2,1,0), include.drift = TRUE)`
`tsdisplay(residuals(fit2_IP), main='Other Model Residuals')`
`fcast2_IP <- forecast(fit2_IP, h=length(outsamp_1_IP))`
`plot(fcast2_IP)`
`lines(IP)`
#we see that its a better fit, from the accuracy parameters, RMSE:12.20 insted of 12.98
`accuracy(fcast2_IP, outsamp_1_IP)`

# # Now let us get a second forecast. Holt-Winters method could be a good choice.

`fit3_IP <- HoltWinters(insamp_1_IP)`
`fcast3_IP <- forecast(fit3_IP, h=length(outsamp_1_IP))`
`plot(fcast3_IP)`
`lines(IP)`
#an even better fit, RMSE:10.63
`accuracy(fcast3_IP, outsamp_1_IP)`

# # We could also use a Diebold-Mariano test to see if these forecasts are significantly different from each other.

`dm.test(residuals(fcast2_IP), residuals(fcast3_IP), h = length(outsamp_1_IP))`

#Because p-value is much smaller than 0,05 we conclude that there is a significant difference between the two forecasts

# # Finally let us check if combining these two forecasts will lead to an improvement in terms of RMSE.

#create new linear fitted model
`combfit_IP <- lm(outsamp_1_IP ~ fcast2_IP\$mean + fcast3_IP\$mean)`
`combfcast_IP <- ts(combfit_IP\$fitted.values, frequency = 12)`
#this is an even better fitted model, RMSE:4.73
`accuracy(combfcast_IP, outsamp_1_IP)`

`combfcast_IP_25 <- predict(combfit_IP, n.ahead = 300)`
`plot(combfcast_IP_25)`
`lines(IP)`

I'm attempting to prooduce a forecast for the next 25 years, 300 steps ahead, based on combfcast_IP_25.

Things look good up until the last three line of code where I attempt to perform the actual forecast.

The output might be correct, but when placing the lines from the original data-set, it is placed in the "middle" of the plot.

I hope someone can give me some feedback on what the error might be.

Thank you

Data:
Data Year Month IP CPI
1 1947 1 13.5852 21.48
2 1947 2 13.6655 21.62
3 1947 3 13.7457 22.00
4 1947 4 13.6387 22.00
5 1947 5 13.6922 21.95
6 1947 6 13.6922 22.08
7 1947 7 13.6120 22.23
8 1947 8 13.6922 22.40
9 1947 9 13.7992 22.84
10 1947 10 13.9329 22.91
11 1947 11 14.1201 23.06
12 1947 12 14.1736 23.41
13 1948 1 14.2538 23.68
14 1948 2 14.2806 23.67
15 1948 3 14.1201 23.50
16 1948 4 14.1468 23.82
17 1948 5 14.3875 24.01
18 1948 6 14.5747 24.15
19 1948 7 14.5747 24.40
20 1948 8 14.5212 24.43
21 1948 9 14.4143 24.36
22 1948 10 14.5212 24.31
23 1948 11 14.3340 24.16
24 1948 12 14.2003 24.05
25 1949 1 14.0666 24.01
26 1949 2 13.9329 23.91
27 1949 3 13.6655 23.91
28 1949 4 13.5852 23.92
29 1949 5 13.3980 23.91
30 1949 6 13.3713 23.92
31 1949 7 13.3446 23.70
32 1949 8 13.4783 23.70
33 1949 9 13.6120 23.75
34 1949 10 13.1039 23.67
35 1949 11 13.4515 23.70
36 1949 12 13.6922 23.61
37 1950 1 13.9329 23.51
38 1950 2 13.9864 23.61
39 1950 3 14.4410 23.64
40 1950 4 14.9224 23.65
41 1950 5 15.2700 23.77
42 1950 6 15.7246 23.88
43 1950 7 16.2328 24.07
44 1950 8 16.7409 24.20
45 1950 9 16.6339 24.34
46 1950 10 16.7409 24.50
47 1950 11 16.7141 24.60
48 1950 12 17.0083 24.98
49 1951 1 17.0618 25.38
50 1951 2 17.1688 25.83
51 1951 3 17.2490 25.88
52 1951 4 17.2757 25.92
53 1951 5 17.2222 25.99
54 1951 6 17.1420 25.93
55 1951 7 16.8746 25.91
56 1951 8 16.7141 25.86
57 1951 9 16.8211 26.03
58 1951 10 16.7944 26.16
59 1951 11 16.9281 26.32
60 1951 12 17.0350 26.47
61 1952 1 17.2222 26.45
62 1952 2 17.3292 26.41
63 1952 3 17.3827 26.39
64 1952 4 17.2222 26.46
65 1952 5 17.0618 26.47
66 1952 6 16.9013 26.53
67 1952 7 16.6339 26.68
68 1952 8 17.7036 26.69
69 1952 9 18.3454 26.63
70 1952 10 18.5326 26.69
71 1952 11 18.9070 26.69
72 1952 12 19.0140 26.71
73 1953 1 19.0675 26.64
74 1953 2 19.1744 26.59
75 1953 3 19.3349 26.63
76 1953 4 19.4151 26.69
77 1953 5 19.5221 26.70
78 1953 6 19.4419 26.77
79 1953 7 19.6825 26.79
80 1953 8 19.5756 26.85
81 1953 9 19.1744 26.89
82 1953 10 19.0140 26.95
83 1953 11 18.5594 26.85
84 1953 12 18.1047 26.87
85 1954 1 17.9710 26.94
86 1954 2 18.0245 26.99
87 1954 3 17.9175 26.93
88 1954 4 17.8106 26.86
89 1954 5 17.9175 26.93
90 1954 6 17.9710 26.94
91 1954 7 17.9978 26.86
92 1954 8 17.9710 26.85
93 1954 9 17.9978 26.81
94 1954 10 18.2117 26.72
95 1954 11 18.5059 26.78
96 1954 12 18.7465 26.77
97 1955 1 19.1744 26.77
98 1955 2 19.4151 26.82
99 1955 3 19.8697 26.79
100 1955 4 20.1104 26.79
101 1955 5 20.4313 26.77
102 1955 6 20.4581 26.71
103 1955 7 20.6185 26.76
104 1955 8 20.5918 26.72
105 1955 9 20.7255 26.85
106 1955 10 21.0732 26.82
107 1955 11 21.1267 26.88
108 1955 12 21.2069 26.87
109 1956 1 21.3406 26.83
110 1956 2 21.1534 26.86
111 1956 3 21.1534 26.89
112 1956 4 21.3138 26.93
113 1956 5 21.1267 27.03
114 1956 6 20.9395 27.15
115 1956 7 20.2976 27.29
116 1956 8 21.1266 27.31
117 1956 9 21.6080 27.35
118 1956 10 21.7952 27.51
119 1956 11 21.6080 27.51
120 1956 12 21.9289 27.63
121 1957 1 21.8487 27.67
122 1957 2 22.0627 27.80
123 1957 3 22.0359 27.86
124 1957 4 21.7417 27.93
125 1957 5 21.6615 28.00
126 1957 6 21.7150 28.11
127 1957 7 21.8487 28.19
128 1957 8 21.8487 28.28
129 1957 9 21.6615 28.32
130 1957 10 21.3406 28.32
131 1957 11 20.8325 28.41
132 1957 12 20.4313 28.47
133 1958 1 20.0569 28.64
134 1958 2 19.6291 28.70
135 1958 3 19.3884 28.87
136 1958 4 19.0675 28.94
137 1958 5 19.2547 28.94
138 1958 6 19.7628 28.91
139 1958 7 20.0569 28.89
140 1958 8 20.4581 28.94
141 1958 9 20.6453 28.91
142 1958 10 20.8860 28.91
143 1958 11 21.5011 28.95
144 1958 12 21.5278 28.97
145 1959 1 21.8487 29.01
146 1959 2 22.2766 29.00
147 1959 3 22.5975 28.97
148 1959 4 23.0789 28.98
149 1959 5 23.4265 29.04
150 1959 6 23.4533 29.11
151 1959 7 22.8917 29.15
152 1959 8 22.1161 29.18
153 1959 9 22.0894 29.25
154 1959 10 21.9289 29.35
155 1959 11 22.0627 29.35
156 1959 12 23.4265 29.41
157 1960 1 24.0416 29.37
158 1960 2 23.8277 29.41
159 1960 3 23.6137 29.41
160 1960 4 23.4265 29.54
161 1960 5 23.3998 29.57
162 1960 6 23.1056 29.61
163 1960 7 23.0254 29.55
164 1960 8 22.9986 29.61
165 1960 9 22.7579 29.61
166 1960 10 22.7312 29.75
167 1960 11 22.4103 29.78
168 1960 12 21.9824 29.81
169 1961 1 22.0092 29.84
170 1961 2 21.9824 29.84
171 1961 3 22.1161 29.84
172 1961 4 22.5708 29.81
173 1961 5 22.9184 29.84
174 1961 6 23.2393 29.84
175 1961 7 23.5067 29.92
176 1961 8 23.7207 29.94
177 1961 9 23.6940 29.98
178 1961 10 24.1486 29.98
179 1961 11 24.5230 29.98
180 1961 12 24.7369 30.01
181 1962 1 24.5230 30.04
182 1962 2 24.9241 30.11
183 1962 3 25.0578 30.17
184 1962 4 25.1113 30.21
185 1962 5 25.0845 30.24
186 1962 6 25.0311 30.21
187 1962 7 25.2717 30.22
188 1962 8 25.2985 30.28
189 1962 9 25.4590 30.42
190 1962 10 25.4857 30.38
191 1962 11 25.5927 30.38
192 1962 12 25.5927 30.38
193 1963 1 25.7799 30.44
194 1963 2 26.0741 30.48
195 1963 3 26.2345 30.51
196 1963 4 26.4752 30.48
197 1963 5 26.7961 30.51
198 1963 6 26.8763 30.61
199 1963 7 26.7693 30.69
200 1963 8 26.8228 30.75
201 1963 9 27.0902 30.72
202 1963 10 27.2775 30.75
203 1963 11 27.4112 30.78
204 1963 12 27.3577 30.88
205 1964 1 27.5984 30.94
206 1964 2 27.7856 30.91
207 1964 3 27.7856 30.94
208 1964 4 28.2402 30.95
209 1964 5 28.4007 30.98
210 1964 6 28.4809 31.01
211 1964 7 28.6681 31.02
212 1964 8 28.8553 31.05
213 1964 9 28.9622 31.08
214 1964 10 28.5611 31.12
215 1964 11 29.4436 31.21
216 1964 12 29.7913 31.25
217 1965 1 30.1122 31.28
218 1965 2 30.2994 31.28
219 1965 3 30.7005 31.31
220 1965 4 30.8342 31.38
221 1965 5 31.0749 31.48
222 1965 6 31.3156 31.61
223 1965 7 31.6098 31.58
224 1965 8 31.7435 31.55
225 1965 9 31.8237 31.62
226 1965 10 32.1446 31.65
227 1965 11 32.2783 31.75
228 1965 12 32.6795 31.85
229 1966 1 33.0004 31.88
230 1966 2 33.2143 32.08
231 1966 3 33.6689 32.18
232 1966 4 33.7224 32.28
233 1966 5 34.0433 32.35
234 1966 6 34.2038 32.38
235 1966 7 34.3910 32.45
236 1966 8 34.4177 32.65
237 1966 9 34.7386 32.75
238 1966 10 34.9793 32.85
239 1966 11 34.7386 32.88
240 1966 12 34.8189 32.92
241 1967 1 34.9831 32.90
242 1967 2 34.5863 33.00
243 1967 3 34.3914 33.00
244 1967 4 34.7157 33.10
245 1967 5 34.4129 33.10
246 1967 6 34.4086 33.30
247 1967 7 34.3302 33.40
248 1967 8 34.9879 33.50
249 1967 9 34.9311 33.60
250 1967 10 35.2156 33.70
251 1967 11 35.7193 33.90
252 1967 12 36.1040 34.00
253 1968 1 36.0651 34.10
254 1968 2 36.1943 34.20
255 1968 3 36.3073 34.30
256 1968 4 36.3599 34.40
257 1968 5 36.7678 34.50
258 1968 6 36.9028 34.70
259 1968 7 36.8462 34.90
260 1968 8 36.9490 35.00
261 1968 9 37.0890 35.10

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