2
$\begingroup$

I have a monthly commodity demand and try to forecast this series for the next 5 years.

Here is a plot:

Plot

Of course, the natural approach to forecast this seasonality would be some kind exponential smoothing (e.g. Holt Winters). But my client requires me to incorporate also information about the state of the economy (e.g. industrial production, household income) as well as other variables (e.g. weather conditions) into the forecast.

What I need is some kind of hybrid model, which combines time series forecasting with exogenous information. I thought ARMAX might be an appropiate method (I am working with R) but perhaps there is simpler model.

Thank you for any suggestions!

edit: Here is the data set in R:

structure(list(Demand = c(7381.08, 6902.08, 7107.08, 5797.08, 
4778.08, 4330.08, 4065.08, 3743.08, 4378.08, 4956.08, 5726.08, 
6167.08, 8497, 7299, 6565, 4746, 4224, 3755, 3398, 3656, 3634, 
4948, 7052, 6268, 7605.75, 8072.75, 6411.75, 5494.75, 3707.75, 
3711.75, 3643.75, 3406.75, 4387.75, 5133.75, 6210.75, 6963.75, 
9158, 7362, 7772, 5136, 5145, 4394, 3647, 3713, 3965, 5451, 6674, 
7419, 7198.42, 7387.42, 7402.42, 5556.42, 4204.42, 4092.42, 3882.42, 
3886.42, 4413.42, 5330.42, 7458.42, 7653.42, 7999, 7012, 6063, 
5811, 4993, 4299, 3795, 3888, 4395, 5806, 7547, 8249, 8311.42, 
6626.42, 6702.42, 5713.42, 4137.42, 3878.42, 3624.42, 3699.42, 
5033.42, 6061.42, 7363.42, 8571.42, 8789.08, 8831.08, 6693.08, 
6040.08, 5353.08, 4047.08, 3038.08, 3134.08, 3719.08, 6310.08, 
8257.08, 9153.08, 9292, 7998, 7566, 6008, 4095, 3143, 3393, 3025, 
4063, 6886, 7606, 8823, 8161.83, 8618.83, 7522.83, 6153.83, 4093.83, 
3660.83, 3462.83, 3666.83, 4427.83, 6860.83, 8874.83, 9304.83, 
9147.42, 9182.42, 7315.42, 6579.42, 4707.42, 4033.42, 3640.42, 
3620.42, 4568.42, 7725.42, 8039.42, 9411.42, 10957.42, 8023.42, 
9125.42, 6218.42, 5482.42, 4306.42, 3408.42, 3664.42, 4756.42, 
5627.42, 9513.42, 12294.42, 11093.67, 10030.67, 10320.67, 6067.67, 
5065.67, 5841.67, 4453.67, 3228.67, 5381.67, 7069.67, 8816.67, 
12187.67, 12044.58, 9240.58, 8378.58, 6899.58, 6250.58, 4336.58, 
2446.58, 4370.58, 3699.58, 7849.58, 9588.58, 10180.58, 10594.67, 
9046.67, 9480.67, 7074.67, 4808.67, 3983.67, 4307.67, 4114.67, 
5306.67, 7847.67, 10868.67, 11193.67, 10881.33, 10884.33, 9474.33, 
6932.33, 4884.33, 4264.33, 4011.33, 4144.33, 4029.33, 7630.33, 
10502.33, 11586.33, 11636.58, 10192.58, 9839.58, 6800.58, 4806.58, 
4402.58, 4900.58, 3963.58, 4528.58, 7053.58, 8887.58, 10715.58, 
11931.92, 10158.92, 9172.92, 7805.92, 5314.92, 3846.92, 5080.92, 
4067.92, 5220.92, 6575.92, 10495.92, 12055.92, 12324.92, 9260.92, 
8769.92, 8536.92, 4985.92, 3573.92, 3908.92, 4825.92, 5335.92, 
7837.92, 9700.92, 12087.92, 12492.42, 11627.42, 9152.42, 6915.42, 
5407.42, 4093.42, 3237.42, 3162.42, 4995.42, 7655.42, 9599.42, 
11165.42, 12057.42, 10179.42, 10732.42, 6444.42, 5920.42, 4211.42, 
3583.42, 3553.42, 4747.42, 7345.42, 9999.42, 11077.42, 11465.67, 
11612.67, 10513.67, 6298.67, 5507.67, 4535.67, 4099.67, 4135.67, 
4607.67, 6508.67, 9387.67, 12012.67, 15081.5, 12394.5, 11656.5, 
6847.5, 5725.5, 3865.5, 3646.5, 4590.5, 4737.5, 6302.5, 8313.5, 
9504.5, 10294.75, 9161.75, 8754.75, 5898.75, 5236.75, 4521.75, 
4892.75, 4051.75, 6163.75, 7932.75, 10898.75, 11179.75, 10801.17, 
9011.17, 10266.17, 8102.17, 5678.17, 5000.17, 4732.17, 4763.17, 
6525.17, 7826.17, 9381.17, 10295.17, 10931.75, 9485.75, 8388.75, 
6467.75, 4432.75, 4873.75, 5822.75, 4701.75, 4487.75, 7133.75, 
8191.75, 10964.75, 12690.08, 10770.08, 9304.08, 7196.08, 6567.08, 
5117.08, 4208.08, 4414.08, 5102.08, 7019.08, 9009.08, 12855.08, 
11287.58, 10241.58, 9757.58, 6152.58, 6034.58, 4787.58, 4481.58, 
4139.58, 4115.58, 6271.58, 8960.58, 9766.58, 10222.33, 12102.33, 
7783.33, 7708.33, 5416.33, 4264.33, 4523.33, 3762.33, 5482.33, 
6843.33, 8289.33, 10803.33, 11292.33, 10816.33, 13084.33, 8347.33, 
5733.33, 4946.33, 4759.33, 5288.33, 6281.33, 5076.33, 8047.33, 
10062.33), Weather = c(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, 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, 836.6924493, 
864.3506976, 581.6976848, 517.7491028, 262.9073017, 125.8485446, 
6.378750412, 47.44717309, 224.2027809, 564.7883676, 534.5681729, 
804.9532423, 1008.232273, 661.7460732, 797.811819, 473.8225, 
243.5474283, 196.7520236, 3.349023044, 66.17021767, 255.3949123, 
273.7186901, 754.5074287, 1074.443123, 1138.053058, 1040.979912, 
920.0242833, 500.2516119, 361.6047682, 148.0344631, 110.9923818, 
59.62586443, 334.3492223, 460.5606125, 718.9706934, 1103.239148, 
1135.812042, 680.8131205, 656.6975921, 603.0120248, 280.2865251, 
113.6086427, 40.56542192, 13.99500372, 205.1454271, 537.9852507, 
740.414947, 863.9388574, 840.1871901, 655.3627691, 689.800506, 
450.142815, 214.0762313, 96.84368144, 94.40207546, 102.6299095, 
219.5820493, 482.6409888, 849.0681028, 930.1270804, 836.8685145, 
870.3884301, 666.1091718, 457.8937971, 223.2997102, 135.3552585, 
29.08801136, 63.35303783, 56.79015527, 463.0870952, 753.1634369, 
854.9329799, 926.6413953, 701.4458617, 685.8712135, 391.1133558, 
172.7297975, 114.0125259, 118.8340228, 39.93146937, 195.3704427, 
368.0819926, 608.7092419, 801.0635085, 938.8709503, 774.4973879, 
747.6592081, 537.4781963, 192.260989, 188.0866469, 43.94658034, 
36.07426405, 284.7563021, 271.1165662, 724.9144894, 998.2149659, 
904.3262439, 618.0036623, 674.6240644, 513.5043282, 200.8462624, 
67.53863402, 49.55548149, 13.91408483, 226.4356358, 512.7364786, 
652.9808563, 977.2313968, 987.9207143, 980.2207144, 676.2825783, 
481.8598638, 188.9155341, 18.81403734, 17.87685266, 22.92422788, 
191.2999234, 628.7164688, 623.9494986, 877.1366222, 993.6142777, 
780.0251185, 734.4778804, 433.5276702, 327.9133614, 143.3598735, 
92.41551972, 43.18090657, 193.5962228, 418.4997331, 710.0634849, 
918.6149901, 866.0983273, 943.8945311, 804.4710259, 451.2019972, 
299.2649129, 130.4053496, 57.39215607, 109.9076214, 166.5745851, 
363.4026804, 727.2489427, 942.2479917, 1140.126083, 920.1753988, 
899.0587303, 506.487232, 258.806951, 121.5292418, 1.37176059, 
108.8383996, 65.19810738, 305.5901759, 569.2363481, 731.8804303, 
710.1873727, 683.3470574, 628.7776364, 348.321329, 233.8441238, 
61.74325304, 79.11932747, 69.1111157, 257.976228, 518.1000209, 
751.3500331, 884.8741716, 770.6473749, 705.6736025, 731.5307109, 
524.8816439, 201.3512057, 79.29200986, 58.30966457, 46.91051312, 
277.9127552, 466.5113866, 673.8802828, 908.1044645, 1101.706185, 
858.9625893, 725.4699465, 315.9941158, 224.7973081, 163.5971151, 
47.04241939, 25.25869003, 156.7798246, 519.0503168, 545.8445539, 
963.5458059, 1193.839102, 917.7867611, 737.4186353, 480.8523752, 
390.7623601, 116.7815813, 19.4804422, 76.28805273, 270.397472, 
518.7399707, 697.1215068, 1193.349175, 933.5835268, 853.5872036, 
713.9427207, 333.4000969, 215.9254222, 87.12224683, 96.06514093, 
63.11633281, 149.1157803, 448.3832879, 704.5634245, 754.4911486, 
872.9159352, 1050.3147, 598.0685504, 510.0915466, 214.3145038, 
146.4499474, 60.86600378, 38.81855226, 206.9537231, 490.4757385, 
697.0382613, 943.3598201, 985.8553275, 913.1275834, 995.459711, 
503.2853052, 285.0997045, 134.6185906, 18.61433414, 41.02519091, 
233.8134415, 386.077747, 696.2700349, 784.2664915), IndProduction = c(66.13584172, 
66.75780888, 65.72119694, 65.2374447, 65.72119694, 59.50152531, 
66.82691634, 66.13584172, 67.51799097, 67.24156112, 67.79442082, 
68.2090656, 68.2090656, 68.27817306, 68.90014022, 68.13995813, 
68.96924768, 69.79853724, 70.48961186, 68.69281783, 69.52210739, 
70.35139694, 71.66443873, 68.96924768, 70.35139694, 70.62782679, 
70.76604171, 71.11157903, 70.4205044, 70.76604171, 71.80265365, 
70.55871932, 70.14407455, 70.35139694, 71.11157903, 70.21318201, 
69.10746261, 70.48961186, 70.07496709, 71.04247156, 72.0790835, 
70.76604171, 69.93675216, 71.45711634, 70.55871932, 71.66443873, 
72.0790835, 72.14819096, 71.80265365, 72.35551335, 72.00997604, 
72.49372828, 72.49372828, 73.80677007, 72.0790835, 75.05070439, 
74.15230738, 74.42873723, 74.77427454, 76.43285365, 75.32713424, 
75.05070439, 75.6035641, 77.88411036, 74.15230738, 77.12392827, 
77.53857305, 77.33125066, 77.74589544, 77.95321782, 78.29875514, 
79.61179693, 79.473582, 79.12804469, 79.88822678, 78.50607752, 
80.51019394, 80.51019394, 81.27037603, 81.75412827, 82.51431036, 
82.65252528, 82.65252528, 82.99806259, 85.35009976, 84.09758258, 
83.5607895, 83.29239296, 82.57666885, 85.17116874, 83.29239296, 
82.39773782, 81.41361718, 82.9345309, 83.91865155, 83.29239296, 
84.45544463, 84.9027722, 83.47132398, 83.47132398, 82.75559988, 
81.5925482, 80.60842756, 81.23468615, 80.16109999, 80.07163448, 
78.9085828, 77.29820356, 76.2246174, 75.24049675, 75.68782432, 
74.97210021, 75.06156573, 74.70370367, 73.36172097, 76.40354843, 
75.77728983, 75.68782432, 75.59835881, 75.95622086, 74.8826347, 
76.40354843, 76.31408291, 77.02980702, 77.02980702, 77.38766907, 
77.20873805, 77.5666001, 78.10339318, 79.5348414, 79.80323794, 
79.89270345, 77.38766907, 78.55072075, 78.55072075, 78.55072075, 
79.26644486, 78.46125523, 78.19285869, 77.65606561, 78.99804831, 
76.76141048, 77.65606561, 77.5666001, 77.5666001, 77.11927253, 
77.74553113, 77.47713459, 78.37178972, 78.28232421, 77.47713459, 
78.99804831, 79.44537588, 78.37178972, 79.35591037, 79.26644486, 
78.46125523, 79.35591037, 79.89270345, 80.07163448, 79.17697934, 
81.50308269, 82.12934128, 79.98216896, 80.69789307, 82.03987577, 
82.30827231, 82.84506539, 83.47132398, 83.47132398, 84.2765136, 
83.91865155, 84.09758258, 83.5607895, 85.26063425, 84.09758258, 
83.20292744, 83.73972052, 82.66613436, 82.75559988, 83.91865155, 
82.75559988, 83.11346193, 83.65025501, 84.00811706, 84.2765136, 
84.63437566, 85.43956528, 85.35009976, 86.15528939, 86.33422041, 
86.42368593, 85.11066398, 87.22334004, 87.32394366, 88.4305835, 
90.54325956, 88.53118712, 90.04024145, 90.84507042, 90.94567404, 
90.7444668, 91.34808853, 92.05231388, 91.75050302, 92.75653924, 
91.24748491, 89.63782696, 90.64386318, 91.04627767, 88.32997988, 
90.7444668, 89.53722334, 88.02816901, 86.92152918, 87.42454728, 
87.92756539, 88.12877264, 88.32997988, 88.4305835, 87.52515091, 
90.04024145, 88.32997988, 90.34205231, 89.23541247, 88.53118712, 
90.14084507, 88.53118712, 89.23541247, 89.23541247, 89.03420523, 
88.73239437, 88.02816901, 87.62575453, 89.73843058, 87.52515091, 
87.22334004, 89.93963783, 90.7444668, 91.14688129, 90.44265594, 
90.94567404, 90.34205231, 91.6498994, 92.65593561, 92.05231388, 
93.15895372, 92.25352113, 91.95171026, 93.0583501, 91.54929577, 
91.14688129, 93.9637827, 92.45472837, 93.56136821, 94.36619718, 
93.15895372, 95.17102616, 96.57947686, 93.86317907, 96.47887324, 
98.39034205, 97.18309859, 97.08249497, 97.58551308, 98.08853119, 
97.18309859, 99.49698189, 100.9054326, 100.3018109, 102.1126761, 
102.8169014, 102.7162978, 102.4144869, 104.2253521, 105.331992, 
105.7344064, 106.2374245, 106.7404427, 105.8350101, 107.7464789, 
107.6458753, 108.4507042, 108.6519115, 109.7585513, 109.8591549, 
109.6579477, 110.8651911, 112.3742455, 112.0724346, 111.3682093, 
111.6700201, 109.3561368, 110.5633803, 108.7525151, 110.9657948, 
108.3501006, 105.9356137, 101.4084507, 97.48490946, 89.73843058, 
86.92152918, 87.32394366, 84.7082495, 88.63179074, 89.3360161, 
88.4305835, 89.63782696, 93.56136821, 91.54929577, 92.65593561, 
92.65593561, 93.46076459, 92.85714286, 96.07645875, 97.48490946, 
100.3018109, 100.2012072, 99.69818913, 101.1066398, 102.6156942, 
104.527163, 104.527163, 105.8350101, 106.0362173, 107.444668, 
108.249497, 108.5513078, 109.6579477, 108.0482897, 111.6700201, 
110.4627767, 108.5513078, 109.5573441, 109.2555332, 107.5452716, 
108.3501006, 108.4507042, 109.7585513, 107.444668, 109.3561368, 
108.249497, 109.8591549, 109.1549296, 107.6458753, 105.9356137, 
105.8350101, 106.9416499, 106.2374245, 107.0422535, 107.444668, 
108.4507042, 107.0422535, 109.054326, 107.5452716, 109.8591549, 
108.7525151, 107.5452716, 110.7645875, 110.1609658)), .Names = c("Demand", 
"Weather", "IndProduction"), class = "data.frame", row.names = c(NA, 
-360L))
$\endgroup$
  • $\begingroup$ May be auto.arima in forecast package with exogenous variables? Can you post your data? $\endgroup$ – forecaster Jul 6 '14 at 14:29
  • $\begingroup$ I have added my data set. would be nice if you could make a short example with auto.arima and my data. I would accept this as an answer. thank you in advance $\endgroup$ – Daniel Ryback Jul 6 '14 at 20:38
2
$\begingroup$

Your predictor variable/independent variable contained NA/Missing value, auto.arima does not permit missing value I think, so I excluded them. when modeling predicting problems like yours, It is always nice to check predictive accuracy of the model, so I held out last 12 months of the data. In addition, it is always best practice to compare multivariate models with univariate (without predictor variables) in time series.Based on my experience, most of the times univarite models work better thank multivariate models. So I modeled your data both as univariate and multivarite ARIMA and compared the 2 models using mean absolute error(MAE). There are other error measures you could use to compare models.

The MAE for multivariate model = 9020.995 The MAE for univariate model = 11515.52

In this case multivariate model had better predictive accuracy than univariate model.

Please note that this type of model is called regression with arima errors. There is another type of modeling called transfer function modeling that you could use to incorporate lead and lag effects etc., A commercial package called AUTOBOX implements this automatically. You could also try SPSS or SAS. SPSS is automatic, SAS is is not. I don't know if there is an R package for transfer function modeling.

See also http://robjhyndman.com/hyndsight/arimax/

##******Multivariate Arima************##
## Training Data set

dep.train <- ts(mm[121:348, 1], frequency=12)
plot(dep.train)

ind.train <- cbind(mm[121:348, 2], mm[121:348, 3])
colnames(ind.train) <- c("Weather","IndProduction")

## Test Dataset

dep.test <- ts(mm[349:360, 1], frequency=12)
plot(dep.test)

ind.test <- cbind(mm[349:360, 2], mm[349:360, 3])
colnames(ind.test) <- c("Weather", "IndProduction")

## Model train data using auto.arima

train.multiarima <- auto.arima(dep.train, xreg=ind.train)

## Predict Out of Sample data

predict.multiarima <- forecast(train.multiarima, xreg=ind.test)
plot(predict.multiarima)

## Test Predictive Accuracy

mae.multiarima <- 
    sum(abs(as.matrix(predict.multiarima$mean) - as.matrix(dep.test)))

##*********Univariate Arima**************##

train.uniarima <- auto.arima(dep.train, approximation=FALSE)

## Predict Out of Sample data

predict.uniarima <- forecast(train.uniarima, h=12)

## Test Predictive Accuracy

mae.uniarima <- 
    sum(abs(as.matrix(predict.uniarima$mean) - as.matrix(dep.test)))

plot of forecast/prediction

Forecast details for multi arima

Series: dep.train 
ARIMA(0,1,2)(0,0,2)[12]                    

    Coefficients:
              ma1      ma2    sma1    sma2  Weather  IndProduction
          -0.8239  -0.1149  0.2686  0.1616   8.0741        21.5982
    s.e.   0.0710   0.0691  0.0691  0.0651   0.1691         8.5757

    sigma^2 estimated as 329326:  log likelihood=-1757.32
    AIC=3528.64   AICc=3529.15   BIC=3552.61

forecast details for uni arima

Series: dep.train 
ARIMA(1,0,0)(2,0,0)[12] with non-zero mean 

Coefficients:
         ar1    sar1    sar2  intercept
      0.3184  0.4648  0.4541  7081.4731
s.e.  0.0687  0.0626  0.0640   688.8523

sigma^2 estimated as 918419:  log likelihood=-1899.35
AIC=3808.71   AICc=3808.98   BIC=3825.85

Forecast plot for multivariate ARIMA

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.