library(seasonal)
library(forecast)
library(stats)
library(xts)
Read Data
df <- read.csv("C:/Users/ASUS/Downloads/energy consumption.csv", header=TRUE, sep=",")
rate <- df$rate
df$ts <- as.POSIXct(df$ts, format="%Y-%m-%dT%H:%M:%OSZ", tz="UTC")
rate_ts <- xts(df$rate, order.by = df$ts)
plot(rate_ts)

ACF & PACF
acf(rate_ts)

pacf(rate_ts)

Model
sarima <- arima(rate_ts, order=c(0,0,0), seasonal=list(order=c(1,1,1),period=6))
summary(sarima)
##
## Call:
## arima(x = rate_ts, order = c(0, 0, 0), seasonal = list(order = c(1, 1, 1), period = 6))
##
## Coefficients:
## sar1 sma1
## 0.7029 -0.4929
## s.e. 0.0228 0.0251
##
## sigma^2 estimated as 300.1: log likelihood = -15350.53, aic = 30707.06
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.03400666 17.31012 12.98331 -0.4615703 10.64666 1.745105
## ACF1
## Training set 0.5865472
Forecasting
forecasting <- forecast(sarima, h=84)
plot(forecasting)

print(forecasting)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2160001 141.9227 119.7203340 164.1250 107.9671368 175.8782
## 2160601 130.2988 108.0965172 152.5012 96.3433200 164.2544
## 2161201 145.1015 122.8992146 167.3039 111.1460175 179.0570
## 2161801 148.6209 126.4186302 170.8233 114.6654331 182.5765
## 2162401 142.8986 120.6962519 165.1009 108.9430547 176.8541
## 2163001 144.2837 122.0813978 166.4860 110.3282007 178.2392
## 2163601 137.6508 102.7983237 172.5033 84.3485369 190.9531
## 2164201 124.1827 89.3301900 159.0351 70.8804033 177.4849
## 2164801 140.9554 106.1029420 175.8079 87.6531552 194.2577
## 2165401 145.5429 110.6903757 180.3953 92.2405889 198.8451
## 2166001 139.3127 104.4602277 174.1652 86.0104409 192.6150
## 2166601 141.6715 106.8190117 176.5240 88.3692250 194.9738
## 2167201 134.6481 88.5686795 180.7274 64.1757303 205.1204
## 2167801 119.8835 73.8041503 165.9629 49.4112011 190.3559
## 2168401 138.0411 91.9616806 184.1204 67.5687313 208.5134
## 2169001 143.3792 97.2998388 189.4586 72.9068896 213.8515
## 2169601 136.7922 90.7127726 182.8715 66.3198233 207.2645
## 2170201 139.8353 93.7559402 185.9147 69.3629910 210.3076
## 2170801 132.5374 76.1802144 188.8946 46.3465287 218.7282
## 2171401 116.8616 60.5044309 173.2188 30.6707452 203.0525
## 2172001 135.9925 79.6353409 192.3497 49.8016552 222.1834
## 2172601 141.8584 85.5011937 198.2155 55.6675080 228.0492
## 2173201 135.0204 78.6632447 191.3776 48.8295590 221.2113
## 2173801 138.5446 82.1874750 194.9018 52.3537893 224.7355
## 2174401 131.0538 65.2003496 196.9072 30.3396546 231.7679
## 2175001 114.7375 48.8840329 180.5909 14.0233380 215.4516
## 2175601 134.5526 68.6991449 200.4060 33.8384499 235.2667
## 2176201 140.7893 74.9359214 206.6428 40.0752265 241.5035
## 2176801 133.7750 67.9216235 199.6285 33.0609285 234.4892
## 2177401 137.6374 71.7839993 203.4908 36.9233043 238.3515
## 2178001 130.0109 55.3378117 204.6840 15.8082589 244.2136
## 2178601 113.2444 38.5712555 187.9175 -0.9582972 227.4470
## 2179201 133.5404 58.8673024 208.2135 19.3377496 247.7431
## 2179801 140.0379 65.3648064 214.7110 25.8352536 254.2406
## 2180401 132.8997 58.2265504 207.5728 18.6969977 247.1023
## 2181001 136.9997 62.3266133 211.6728 22.7970605 251.2024
## 2181601 129.2779 46.3776196 212.1781 2.4928743 256.0629
## 2182201 112.1948 29.2945839 195.0951 -14.5901614 238.9798
## 2182801 132.8289 49.9286865 215.7292 6.0439413 259.6139
## 2183401 139.5097 56.6094594 222.4100 12.7247141 266.2947
## 2184001 132.2843 49.3840716 215.1846 5.4993263 259.0693
## 2184601 136.5515 53.6512080 219.4517 9.7664627 263.3365
## 2185201 128.7626 38.1554833 219.3697 -9.8090347 267.3343
## 2185801 111.4571 20.8499898 202.0643 -27.1145282 250.0288
## 2186401 132.3288 41.7217164 222.9360 -6.2428015 270.9005
## 2187001 139.1384 48.5313115 229.7456 0.5667936 277.7101
## 2187601 131.8518 41.2446775 222.4589 -6.7198404 270.4235
## 2188201 136.2364 45.6292522 226.8435 -2.3352657 274.8080
## 2188801 128.4004 30.5437850 226.2571 -21.2583935 278.0593
## 2189401 110.9386 13.0819229 208.7952 -38.7202557 260.5974
## 2190001 131.9773 34.1206787 229.8340 -17.6814998 281.6361
## 2190601 138.8775 41.0208247 236.7341 -10.7813539 288.5363
## 2191201 131.5478 33.6911399 229.4044 -18.1110386 281.2066
## 2191801 136.0149 38.1582636 233.8716 -13.6439149 285.6737
## 2192401 128.1458 23.4423821 232.8493 -31.9842831 288.2760
## 2193001 110.5741 5.8706063 215.2775 -49.5560589 270.7042
## 2193601 131.7302 27.0267693 236.4337 -28.3998959 291.8604
## 2194201 138.6940 33.9905647 243.3975 -21.4361005 298.8242
## 2194801 131.3341 26.6306190 236.0375 -28.7960462 291.4642
## 2195401 135.8592 31.1557675 240.5627 -24.2708977 295.9894
## 2196001 127.9669 16.7720424 239.1617 -42.0909563 298.0247
## 2196601 110.3179 -0.8769932 221.5127 -59.7399919 280.3757
## 2197201 131.5565 20.3616968 242.7514 -38.5013019 301.6144
## 2197801 138.5651 27.3702324 249.7599 -31.4927664 308.6229
## 2198401 131.1839 19.9890158 242.3787 -38.8739829 301.2417
## 2199001 135.7498 24.5549507 246.9447 -34.3080480 305.8077
## 2199601 127.8411 10.4695840 245.2126 -51.6631470 307.3454
## 2200201 110.1378 -7.2337587 227.5093 -69.3664897 289.6420
## 2200801 131.4345 14.0629408 248.8060 -48.0697902 310.9387
## 2201401 138.4744 21.1029247 255.8460 -41.0298063 317.9787
## 2202001 131.0783 13.7067566 248.4498 -48.4259744 310.5825
## 2202601 135.6729 18.3013608 253.0444 -43.8313702 315.1771
## 2203201 127.7527 4.4842181 251.0212 -60.7701687 316.2755
## 2203801 110.0112 -13.2572976 233.2796 -78.5116845 298.5340
## 2204401 131.3486 8.0801774 254.6171 -57.1742094 319.8715
## 2205001 138.4107 15.1422669 261.6792 -50.1121200 326.9336
## 2205601 131.0041 7.7355891 254.2725 -57.5187978 319.5269
## 2206201 135.6188 12.3503454 258.8873 -52.9040414 324.1417
## 2206801 127.6905 -1.2252217 256.6063 -69.4691033 324.8502
## 2207401 109.9222 -18.9935699 238.8380 -87.2374515 307.0818
## 2208001 131.2883 2.3725669 260.2041 -65.8713147 328.4480
## 2208601 138.3660 9.4501946 267.2817 -58.7936870 335.5256
## 2209201 130.9519 2.0361294 259.8677 -66.2077522 328.1115
## 2209801 135.5808 6.6650509 264.4966 -61.5788306 332.7405
AIC(sarima)
## [1] 30707.06
BIC(sarima)
## [1] 30725.62
accuracy(forecasting)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.03400666 17.31012 12.98331 -0.4615703 10.64666 0.09048426
## ACF1
## Training set 0.5865472
White Noise test
Box.test (rate_ts, lag = 6, type = "Ljung-Box")
##
## Box-Ljung test
##
## data: rate_ts
## X-squared = 19300, df = 6, p-value < 2.2e-16
Normality Test
shapiro.test(as.numeric(rate_ts))
##
## Shapiro-Wilk normality test
##
## data: as.numeric(rate_ts)
## W = 0.93093, p-value < 2.2e-16