Solved – Mention day-wise seasonality for forecasting in ARIMA using R

arimaforecastingrseasonalitytime series

I have half-hourly electricity data of several homes for a duration of one month. This data is represented in xts time-series format. Now, I need to make half-hourly forecasts using the same data for coming day. The forecasting interval is one day (i.e., very short term forecast). I assume that electricity usage follows daywise seasonality as the number of users/occupants remain fixed. This assumption is obeyed in some homes while some other follow random electricity usage.

Currently, I use historical one month data to make half-hourly forecasts of coming day using auto.arima found in forecast pacakage. Using this approach I do get forecasts for next day (48 forecasted values). 48 forecasted values correspond to 48 half-hours of the day. But, I do not know

  1. How should I specify the seasonality fact, i.e., how should I mention that data is assumed seasonal day-wise. In other words, how should I mention within historical data of one month, there are 30 periods and each period consist of 48 observations.
  2. Is xts representation suitable for this task or I need to represent this in ts format?

Here I have attached half-hourly data of 26 days. I have removed timestamps in order to fit the data according to stackExchange limits. This data does not contain any missing readings. It contains 1248 (26 x 48) observations

data <- structure(c(1642.8, 1467.1, 165.57, 1630.99, 1618.65, 1629.29, 
1598.93, 1839.9, 1604.52, 1606.73, 1473.82, 1669.17, 1698.9, 
2111.21, 2056.41, 3671.29, 2808.01, 1336.15, 794.11, 1212.15, 
377.36, 888.54, 174.58, 218.54, 420.76, 389.58, 397.77, 395.31, 
359.11, 364.8, 376.13, 389.37, 929.5, 1702.38, 519.65, 2452.28, 
1354.45, 1842.96, 725.41, 661.11, 528.44, 733.4, 429.51, 310.47, 
279.72, 407.83, 1791.1, 1754.53, 1536.73, 1608.37, 1432.23, 1401.72, 
1582.14, 1558.75, 1536.24, 1745.59, 1375.61, 1556.71, 1671.12, 
1206.77, 1391.84, 876.23, 1617.3, 1638.99, 1833.61, 1591.42, 
1455, 183.87, 177.55, 184.36, 332.99, 352.95, 425.1, 945.67, 
342.3, 348.45, 227.18, 382.15, 268.91, 335.88, 326.94, 233.23, 
169.71, 179.51, 195.3, 207.23, 1681.9, 1493.32, 941.52, 980.36, 
924.31, 379.02, 1229.89, 1590.21, 1250.92, 1149.24, 1124.04, 
993.78, 883.98, 860.69, 934.17, 969.31, 1049.55, 1104.94, 904.3, 
1220.23, 1183.9, 891.26, 825.33, 787.77, 1060.93, 1029.1, 982.25, 
193.13, 182.65, 181.75, 167.68, 165.89, 291.02, 300.2, 418.4, 
297.66, 231.89, 305.66, 701.18, 338.5, 337.24, 332.11, 332.66, 
187.8, 179.03, 130.22, 177.73, 172.24, 173.45, 334.23, 810.53, 
359.41, 330.23, 333.29, 568.85, 2462.46, 1660.32, 1156.13, 1136.2, 
1189.07, 832.73, 181.91, 185.93, 1076.77, 672.78, 1376.71, 1020.17, 
382.18, 1160.74, 791.36, 1569.4, 817.78, 850.71, 747.21, 826.12, 
1306.46, 506.23, 140.05, 132.6, 304.19, 308.14, 406.13, 290.73, 
188.9, 165.59, 174.56, 145.97, 151.83, 142.29, 443.58, 799.9, 
279.36, 223.88, 221.03, 291.26, 374.97, 431.36, 598.98, 625.82, 
1052.02, 2036.83, 1230.03, 1429.81, 1099.34, 1646.03, 1668.56, 
1631.79, 1604.04, 2849.49, 2998.63, 2476.96, 1601.04, 1216.42, 
2004.2, 1868.51, 1961.91, 1813.35, 1500.22, 1276.94, 1369.29, 
632.43, 238.15, 488.76, 467.6, 330.27, 144.67, 153.36, 924.12, 
1348.18, 799.01, 524.3, 420.5, 264.34, 283.86, 198.95, 206.52, 
217.33, 356.16, 207.83, 197.6, 194.03, 193.01, 249.85, 271.22, 
244.25, 442.5, 660.49, 245.66, 356.13, 443.32, 336.15, 849.74, 
1709.21, 1542.09, 1315.69, 2628.6, 2261.8, 1576.42, 1776.48, 
1239.64, 1401.12, 1106.17, 1378.55, 1315.57, 1141, 1642.63, 2484.13, 
1968.94, 3059.42, 1317.32, 905.05, 484.42, 486.86, 96.79, 183.45, 
173.94, 342, 255.96, 320.54, 106.19, 147.88, 150.77, 176.17, 
344.75, 371.73, 309.46, 237.86, 187.32, 202.61, 292.5, 248.28, 
259.3, 283.67, 365.09, 230.47, 326.15, 350.92, 335.42, 419.39, 
345.31, 1093.22, 1392.87, 1298.11, 919.16, 1654.53, 1045.99, 
558.42, 437.29, 857.9, 758.34, 1220.04, 1390.62, 956.74, 909.93, 
584.67, 409.87, 387.3, 387.93, 1276.28, 871.06, 413.8, 313.2, 
199.5, 330.21, 210.9, 358.28, 352.13, 233.62, 259.18, 123.57, 
255.58, 411.78, 427.65, 318.95, 298.5, 283.23, 279.85, 200.45, 
205.97, 254.24, 307.98, 1090.53, 289.71, 215.14, 286.63, 328.55, 
288.96, 1281.19, 1354.8, 1302.05, 1254.46, 261.95, 270.09, 243.28, 
696.61, 314.27, 241.73, 245.68, 157.74, 222.55, 294.36, 185.46, 
203.49, 182.14, 246.69, 178.26, 397.5, 330.2, 212.02, 248.72, 
265.48, 249.37, 130.59, 248.97, 279.94, 319.07, 358.5, 278.98, 
251.92, 304.66, 455.05, 365.95, 340.93, 287.51, 264.82, 260.18, 
34.35, 35.11, 184.09, 247.18, 160.9, 139.27, 284.96, 296.31, 
252.3, 342.65, 353.03, 380.52, 346.19, 350.06, 218.52, 133.94, 
173.7, 128.26, 167.8, 112.77, 147.8, 129, 170.54, 89.88, 243.08, 
97.61, 190.31, 193.94, 268.17, 233.5, 205.27, 92.29, 167.43, 
168.34, 151.99, 193.84, 379.1, 318.69, 327.28, 487.39, 414.01, 
336.06, 278.02, 168.05, 155.6, 236.4, 264.94, 296.05, 326.46, 
357.43, 356.31, 340.29, 319.81, 312.79, 341.53, 317.36, 309.62, 
440.6, 285.5, 282.06, 288.99, 334.48, 196.54, 144.24, 218.55, 
173.64, 242.29, 251.78, 186.81, 184.36, 141.62, 208.91, 157.53, 
154.03, 139.44, 137.66, 256.75, 1202.05, 177.36, 177.93, 72.83, 
252.9, 231.35, 1090.39, 442.91, 363.12, 248.96, 478.75, 249.64, 
297.29, 227.28, 365.82, 879.7, 488.93, 184.79, 138.13, 151.77, 
123.18, 175.76, 251.84, 208.06, 126.68, 246.3, 307.34, 319.79, 
324.3, 379.6, 309.53, 253.17, 221.91, 228.42, 150.24, 148.59, 
118.79, 86.89, 140.51, 200.43, 212.15, 276.14, 441.81, 125.77, 
152.42, 329.28, 269.21, 177.35, 1106.29, 128.92, 96.35, 63.53, 
520.62, 940.25, 1014.34, 314.99, 390.2, 330.1, 377.04, 341.35, 
342.79, 241.79, 249.9, 391.92, 292.68, 105.02, 179.99, 118.53, 
154.17, 90.53, 206.7, 345.33, 244.75, 291.68, 820.57, 1777.84, 
1805.83, 1753.73, 1416.7, 279.2, 262.82, 1345.88, 467.98, 1136.66, 
170.02, 159.96, 1478.8, 1414.12, 1347.93, 1505.59, 1341.69, 445.53, 
277.59, 1609.61, 1476.45, 244.08, 192.57, 213.55, 439.02, 112.86, 
128.54, 376.09, 251.15, 116.27, 254.82, 302.56, 304.6, 198.5, 
240.05, 219.35, 70.3, 190.96, 211.95, 328.53, 714.62, 3176.56, 
2604.09, 191.65, 145.25, 93.93, 83.6, 81.13, 146.12, 331.75, 
250.24, 1144.53, 1616.47, 1008.7, 316.65, 311.46, 1152.99, 1504.86, 
1543.21, 1081.54, 1428.07, 1358.23, 1349.75, 190.23, 2398.92, 
2196.11, 1466.94, 2249.77, 2150.2, 2542.25, 618.03, 453.22, 880.99, 
1497.86, 440.96, 161.85, 324.88, 434.11, 316.33, 444.66, 359.14, 
277.41, 1237.28, 761.41, 183.53, 309.44, 213.48, 121.64, 346.7, 
149.86, 2060.39, 1102.13, 347.97, 600.24, 912.6, 590.77, 1805.76, 
1673.93, 1573.91, 505.74, 446.76, 1033.41, 1668.68, 1293.9, 383.81, 
1419.99, 1349.4, 711.55, 218.63, 182, 401.93, 1876, 1486.34, 
1543.11, 2313.8, 478.57, 615.19, 542.68, 971.98, 531.11, 766.21, 
489.76, 344.47, 319.86, 321.26, 311.41, 288.67, 310.67, 305.15, 
419.33, 422.84, 950.08, 2188.88, 3454.92, 1989.54, 590.33, 327.05, 
354.78, 578.41, 1583.29, 2016.66, 1481.03, 293.21, 1864.84, 399.65, 
366.76, 357.7, 2074.97, 1626.86, 1133, 1624.61, 1506.93, 628.4, 
1405.68, 217.8, 1223.11, 1356.97, 1171.72, 1182.86, 1642.11, 
2289.02, 814.39, 595.76, 542.78, 1596.41, 884.97, 235.25, 1540.68, 
781.95, 115.71, 1204.98, 718.66, 452.09, 305.58, 444.67, 356.76, 
182.54, 674.47, 153.8, 862.25, 1322.88, 323.33, 1659.64, 496.72, 
304.74, 246.6, 327.12, 239.31, 246.72, 225.72, 234.7, 324.07, 
304.27, 171.86, 97.64, 242.69, 295, 324.53, 513.81, 1100.65, 
1151.77, 231.56, 189.88, 786.3, 1164.87, 676.09, 882.82, 1496.3, 
1027.91, 872.92, 809.1, 840.31, 1302.18, 2055.87, 677.74, 934.66, 
263.91, 186.68, 248.5, 214.62, 371.54, 298, 294.52, 304.86, 1295.77, 
942.5, 305, 265.78, 255.89, 255.63, 151.54, 108.16, 116.81, 100.19, 
224.75, 84.11, 1143.89, 262.15, 784.21, 1728.29, 1506.79, 434.94, 
374.29, 265.43, 560.74, 1651.49, 1063.07, 1054.69, 1298.4, 1261.59, 
1132.75, 692.82, 660.57, 198.25, 97.81, 1258.67, 833.64, 796.35, 
868.76, 999.86, 2240.02, 885.72, 1317.52, 1267.18, 167.93, 133.22, 
364.44, 267.17, 406.13, 412.52, 1036.04, 779.34, 655.43, 1901.2, 
270.18, 266.31, 284.21, 288.66, 135.38, 176.11, 154.86, 160.21, 
146.28, 163.72, 139.75, 278.12, 253.51, 319.62, 396.39, 1662.69, 
1577.09, 1059.71, 241.64, 407.54, 290.49, 846.17, 1325.31, 1418.23, 
1432.5, 1412.6, 1015.87, 1619.88, 1426.58, 1333.32, 1963.35, 
1638.11, 1081.89, 285.56, 1084.58, 2038.77, 1022.39, 1145.92, 
513.87, 107.7, 176.19, 143.77, 374.3, 373.99, 221.76, 148.3, 
331.01, 2323.12, 1502.09, 347.17, 296.7, 306.06, 313.03, 221.69, 
295.35, 301.95, 250.92, 231.54, 140.6, 717.63, 863.5, 402.15, 
1337.78, 1575.44, 1738.49, 1675.57, 1617.66, 1365.58, 242.8, 
286.29, 712.34, 1559.59, 1600.34, 3447.88, 3432.89, 3337.23, 
1472.21, 1323.76, 1265.31, 1221.65, 1312.63, 2016.09, 2972.13, 
1451.67, 735.67, 130.13, 379.87, 162.21, 226.48, 417.18, 357.51, 
346.37, 200.89, 190.15, 276.05, 942.74, 1471.99, 1047.53, 1240.06, 
742.62, 169.34, 144.28, 220.58, 165.23, 344.8, 227.47, 254.64, 
742.37, 1809.01, 436.11, 1692.87, 1697.74, 1474.91, 1635.68, 
1664.2, 1489.85, 1316.4, 1364.07, 1510.02, 1497.89, 1709.17, 
2846.71, 2736.08, 1015.43, 1017.08, 1195.21, 751.18, 523.89, 
199.69, 2148.71, 1151.39, 1182.84, 788.91, 259.31, 146.29, 141.09, 
299.38, 349.53, 404.08, 449.9, 391.77, 251.89, 222.25, 281.04, 
565.4, 371.24, 219.75, 324.45, 227, 157.67, 212.48, 201.69, 140.84, 
220.67, 187.64, 399.79, 157.92, 275.49, 326.99, 1340.51, 1578.68, 
1599.41, 1667.74, 1129.07, 1312.55, 1393.09, 1368.69, 1130.85, 
968.71, 1130.2, 1223.1, 1124.5, 1077.09, 1052.42, 1255.31, 918.21, 
1263.93, 706.21, 3080.29, 1620.18, 1122.48, 750.06, 262.89, 110.02, 
236.83, 413, 227.53, 355, 277.51, 258.03, 368.44, 656.68, 1808.17, 
1493.41, 1272.21, 330.67, 1674.18, 719.45, 1089.68, 784.01, 275.73, 
312.69, 345.11, 761.8, 1020.11, 259.16, 345.98, 270.23, 580.15, 
1303.68, 1659.7, 1732.94, 204.9, 373.58, 373.36, 1381.52, 1437.74, 
1262.78, 1264.6, 1184.54, 1175.12, 857.09, 1428.34, 841.92, 232.47, 
223.22, 473.24, 382.7, 189.84, 1737.48, 1689.34, 378.48, 872.56, 
180.12, 363.03, 301.38, 412.57, 401.17, 387.35, 417.63, 300.61, 
376.82, 284.31, 232.31, 269.96, 188.41, 203.79, 134.88, 193.66, 
57.86, 89.71, 167.66, 60.84, 197.03, 703.66, 1638.7, 1467.03, 
347.22, 1397.23, 1511.92, 1362.25, 1397.18, 1106.19, 826.5, 1033.04, 
1039.46, 584.98, 706.35, 548.07, 373.39, 681.6, 1231.28, 288.94, 
649.36, 79.28, 209.23, 290.75, 304.12, 132.57, 91.2, 355.37, 
197.45, 343.17, 339.2, 284.65, 229, 234.73, 322.36, 323.43, 295.1, 
197.03, 308.17, 223.88, 235.08, 225.16, 172.83, 236.26, 135.17, 
394.89, 479.2, 315.34, 280.9, 282.36, 204.78, 367.24, 1712.29, 
1521, 1686.09, 960.19, 1019.12, 1062.77, 851.88, 1369.98, 689.2, 
580.5, 751.74, 547.67, 556.64, 493.85, 404.15, 428.07, 716.2, 
1442.05, 1045.81, 1497.07, 567.59, 155.07, 537.72, 446.03, 282.57, 
642.88, 409.37, 338.91, 173.89, 358.63, 195.42, 209.95, 186.44, 
152.34, 105.51, 132.26, 82.14, 122.88, 149.38, 211.42, 350.17, 
429.72, 336.4, 982.21, 1436.25, 1726.87, 1830.42, 1282.05, 1293.4, 
1121.01, 946.2, 707.1, 154.53, 767.56, 607.78, 448, 288.23, 270.32, 
223.93, 166.22, 262.45, 223.74, 159.31, 210.44, 257.94, 183.99, 
151.38, 206.11, 193.43, 388.95, 577.98, 304.64, 285.13, 256.59, 
420.26, 289.34, 356.02, 358.08, 325.22, 275.95, 164.46, 213.23, 
142.99, 221.66, 270.61, 206.56, 213.68, 254.33, 250.15, 267.99, 
403.95, 671.2, 1574.11, 396.34, 477.88, 631.08, 618.25, 1366.88, 
298.19, 287.05, 290.38, 332.44, 235.9, 229.79, 831.6, 1320.86, 
477.31, 944.84, 547.33, 411.21, 705.43, 873.49, 572.81, 585.36, 
1229.69, 701.01, 653.49, 74.81, 162.47, 179.54, 330.27, 544.51, 
332.41, 296.66, 130.66, 1055.61, 556.79, 265.43, 383.44, 398.22, 
362.66, 223.99, 130.35, 193.67, 217.68, 273.3, 247.84, 161.66, 
320.08, 322.52, 274.61, 811.44, 353.85, 323.41, 383.61, 389.5
), .Dim = c(1248L, 1L), .Dimnames = list(NULL, "power"))

Best Answer

On the one hand, you can certainly use ts objects. Specify the season length through the frequency parameter:

auto.arima(ts(data[,1],frequency=48))

However, electricity consumption usually has multiple seasonalities. You have the intra-day seasonality, but you will usually also have weekly seasonality, since weekends have different power consumption than weekdays - people are at home instead of at work, industrial production is reduced etc. Plus, there may be yearly seasonality, with air conditioners and heaters consuming a lot of electricity in summer/winter.

Use msts objects to encode time series with multiple seasonalities:

msts(data[,1],seasonal.periods=c(48,7*48))

You can then fit models with multiple seasonalities using tbats:

tbats(msts(data[,1],seasonal.periods=c(48,7*48)))

Both are again in the forecast package. You may want to look at earlier questions on "multiple seasonalities".