mpiktas / midasr

R package for mixed frequency time series data analysis.
http://mpiktas.github.io/midasr/
Other
73 stars 34 forks source link

Simple MIDAS forecast yields: Error in mls(indic, 1:11, 3) : Incomplete high frequency data #67

Closed p-wegmueller closed 5 years ago

p-wegmueller commented 5 years ago

Hi there, I am new to the midasr package and still encounter some difficulties in what should be a simple exercise. My target variable is Swiss GDP up to 2018Q2, my indicator is KOF business situation for which I have two observations already in 2018Q3 (July and August). Now I would like to make a simple Nowcast of GDP in 2018Q3 with midasr, however I am running into the error in the title.

Any help is greatly appreciated. Philipp

bip <- structure(c(NA, 0.262247222573242, 0.70269694142977, 0.10713717070685, 
0.253143998874772, -0.269413344218672, -0.292628619825386, 0.533011803536065, 
0.76194670967773, 0.710540031399076, 1.18722465264625, 0.918106343019698, 
0.699432509875009, 1.18172547103716, -0.100577853483264, -0.338555703685117, 
0.0630965359078361, 0.910534405785501, 0.622666053071508, 2.36347238655108, 
0.775635682062381, 0.417096983794818, 0.776758887991136, 0.982136505719655, 
0.0380841422672251, 0.243741335743208, -0.307321622301659, -0.0472835623253065, 
0.269063570677397, 0.0857848124087512, 0.158716592060215, -0.384877368811087, 
-0.691512970248076, 0.211446170718665, 0.976761394986947, 1.2226327078954, 
0.671644753536849, 0.406112829187077, 0.260477310618956, 0.14745797243485, 
1.20898353582957, 1.13663455270825, 0.993710435663075, 0.896641650617669, 
1.11474900220188, 0.855156641542631, 0.825464435586509, 1.57268277165259, 
0.859769890054984, 1.0956403993978, 0.810381926140558, 0.630726430429496, 
0.892060335178924, 0.642109858862883, 0.115191313837926, -1.91399892438129, 
-1.55652639441269, -0.0108950037221001, 0.994731997900589, 0.248703676636253, 
1.02443051103138, 0.981324912348081, 0.442511361134845, 0.700683734088448, 
0.480226926546523, 0.487727968379947, -0.320376178625814, 0.610472478077995, 
0.0903967542405848, 0.247965811258855, 0.515752039642448, 0.20154221453077, 
0.413321273294298, 0.786377025315765, 0.699046335598119, 0.174053432067445, 
0.739521258634279, 0.600895495232656, 0.78321168202462, 0.814073071810473, 
-0.317738185021732, 0.0275125961917366, 0.631406875219254, 0.379026308920372, 
0.574741163191206, 0.310681799807289, 0.398571321626395, -0.138319437766343, 
0.389750510107256, 0.731238190659078, 0.682738195203436, 0.805409776113519, 
0.985454909227679, 0.720297903646738), .Tsp = c(1995, 2018.25, 
4), class = "ts")

indic <- structure(c(13.461348, 14.660702, 12.431101, 8.624779, 4.750734, 
-0.2708, 2.747194, 0.265363, -3.714504, -2.809137, -2.811511, 
-3.913924, -6.167648, -5.844633, -6.348298, -7.53791, -9.833, 
-8.232725, -7.640412, -8.350082, -10.026205, -7.532892, -6.994133, 
-6.75796, -6.052772, -3.374599, 2.378277, 1.79219, 5.987095, 
7.636975, 7.161635, 11.985409, 16.220903, 16.192869, 16.283897, 
15.569579, 14.596612, 9.987116, 9.006768, 7.606858, 8.905231, 
9.565563, 7.468125, 4.731921, 1.948242, -1.623501, -0.908288, 
0.485073, 2.120749, 4.151957, 0.986466, 4.909144, 7.682371, 7.653601, 
8.143632, 12.048334, 15.784539, 17.738993, 17.367895, 16.586035, 
14.768478, 15.015168, 19.050741, 18.249247, 13.009816, 17.138729, 
18.473085, 18.040964, 17.799803, 19.090578, 20.172804, 17.726706, 
16.0333, 14.170975, 9.099858, 5.689326, 2.383771, 0.491462, -1.826977, 
-1.021587, -6.132291, -10.645781, -13.836951, -12.226154, -3.859954, 
0.907104, 2.906548, 9.76985, 11.865869, 6.824918, 7.768582, -1.107236, 
0.97908, 0.463812, -3.26615, -0.309543, -4.412746, -8.724845, 
-8.02769, -10.353594, -7.246639, -6.607904, -6.94639, -1.096415, 
7.431201, 10.41878, 17.016695, 14.985041, 13.695827, 15.931614, 
15.908782, 15.87079, 13.376639, 20.964478, 18.114223, 19.513222, 
15.940299, 10.488046, 9.267039, 9.653232, 13.723776, 12.371337, 
12.05741, 12.171462, 9.649246, 7.296007, 9.6278, 10.568275, 9.732627, 
15.409176, 17.334534, 16.135859, 16.298151, 21.380972, 21.792673, 
21.293974, 21.330648, 17.493988, 18.334743, 16.766953, 15.598661, 
18.444517, 15.125962, 16.570156, 21.412481, 22.750597, 21.005045, 
15.479894, 16.387096, 17.074041, 17.791355, 17.107971, 16.446898, 
15.110619, 18.066545, 16.513166, 15.776911, 10.904828, 8.669746, 
10.403622, 8.078406, 5.140325, 3.709297, 1.058593, -2.892592, 
-9.618021, -18.876135, -24.640432, -31.374163, -34.930733, -36.620956, 
-30.85305, -24.655128, -16.655985, -12.806828, -11.126951, -1.009259, 
3.21348, 7.295572, 12.436415, 12.979212, 19.203665, 16.941702, 
18.619726, 18.772736, 17.773777, 14.245872, 21.460382, 18.306744, 
18.658173, 19.309507, 20.89987, 19.694685, 16.074705, 18.31109, 
14.915301, 10.515241, 7.53312, 5.056037, -4.348217, -8.811703, 
-7.75714, -6.102273, -7.463261, -10.158002, -5.841114, -0.167542, 
0.348341, 2.554799, 2.857896, 1.308888, 5.271125, 2.637805, -0.348138, 
-1.923031, -1.394233, 8.214464, 7.948373, 5.25492, 8.536953, 
6.154599, 4.130117, 11.287378, 10.240297, 11.29351, 13.539214, 
14.308599, 15.726928, 12.415162, 13.701179, 14.34241, 9.92694, 
9.613595, 11.926573, 6.582197, 5.429029, 8.540767, 7.990528, 
3.641377, 3.427127, 0.627322, -2.898872, -8.86704, -2.326802, 
-4.330286, -4.259538, -1.685346, -0.426868, -2.621673, -0.82184, 
0.036291, -1.772943, 0.387245, 1.689412, 1.150348, -0.63164, 
-1.743934, 3.850347, 2.650668, 4.03791, 6.548068, 4.424613, 4.226253, 
5.318511, 4.235432, 8.681971, 11.004651, 9.930435, 11.185616, 
9.050154, 12.614633, 12.003175, 12.651925, 12.802332, 16.088049, 
15.997222, 18.695995, 15.411313, 14.980041, 14.569686, 17.673759, 
16.204853), .Tsp = c(1995, 2018.41666666667, 12), class = "ts")

indic_fcst <- structure(c(11.674851, 12.131161), .Tsp = c(2018.5, 2018.58333333333, 
12), class = "ts")

m1 <- midas_r(bip ~ mls(bip, 1, 1) + mls(indic, 1:11, 3), 
              start = NULL)
summary(m1)

forecast(m1, list(indic = indic_fcst), method = "static")
vzemlys commented 5 years ago

forecast.midas_r requires full high frequency data for the low frequency periods. Your low frequency period contains 3 high frequency periods, but you supply data only for two. Hence the error:

 Error in mls(indic, 1:11, 3) : Incomplete high frequency data

If all data is supplied then forecasting succeeds:

forecast(m1, list(indic = c(indic_fcst,NA)), method = "static")
          Qtr3
2018 0.5544495

This is evident from the examples given in forecast.midas_r manual and the examples in JSS articles.

p-wegmueller commented 5 years ago

thanks for your prompt reply. Yet, if I would like to have a forecast also for 2018Q4, then the specificiation c(indic_fcst, rep(NA, 4) would give NA for GDP. How do I compute multiperiod forecasts?

vzemlys commented 5 years ago

Multiperiod forecasts are supported. You just need to supply the data. Your model now currently depends on the previous period data. So forecasting multiple periods ahead you either need to change your model, or supply the forecasts of the variables on the right hand side.