install.packages("readr", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("skimr", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("dplyr", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("tidyverse", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("lubridate", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("RMySQL", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("plotly", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("circular", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("ggeasy", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("RColorBrewer", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("viridis", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("reshape2", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("fpp2", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
install.packages("shiny", repos = "http://cran.us.r-project.org")
##
## The downloaded binary packages are in
## /var/folders/4g/91cbwfqd3b3_n7gm9tn8vtp00000gn/T//Rtmp6wL78C/downloaded_packages
library("readr")
## Warning: package 'readr' was built under R version 4.1.2
library("skimr")
library("dplyr")
## Warning: package 'dplyr' was built under R version 4.1.2
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library("tidyverse")
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ stringr 1.4.0
## ✓ tidyr 1.2.0 ✓ forcats 0.5.1
## Warning: package 'tidyr' was built under R version 4.1.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library("lubridate")
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library("RMySQL")
## Loading required package: DBI
library("plotly")
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library("circular")
##
## Attaching package: 'circular'
## The following object is masked from 'package:plotly':
##
## wind
## The following objects are masked from 'package:stats':
##
## sd, var
library("ggeasy")
library("RColorBrewer")
library("viridis")
## Loading required package: viridisLite
library("viridisLite")
library("reshape2")
##
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
##
## smiths
library("forecast")
## Warning: package 'forecast' was built under R version 4.1.2
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library("fpp2")
## ── Attaching packages ────────────────────────────────────────────── fpp2 2.4 ──
## ✓ fma 2.4 ✓ expsmooth 2.3
##
library("shiny")
options(scipen = 999) # force R not to use exponential notation
#write.csv(df789, file="~/2810_uc3_R/T1C4/df789.csv")
df789 <- read.csv(file="~/2810_uc3_R/T1C4/df789.csv")
df789_met<-df789%>%
group_by(year, month)%>%
summarise(sumKitchen=sum(Kitchen),
sumLaundromat=sum(Laundromat),
sumTC=sum(Temp_control),
sumOEE=sum(otherEE),
sumAll=sum(gapW))
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
df789_met
## # A tibble: 36 × 7
## # Groups: year [3]
## year month sumKitchen sumLaundromat sumTC sumOEE sumAll
## <int> <chr> <int> <int> <int> <dbl> <dbl>
## 1 2007 Apr 41591 38446 191629 317887. 589553.
## 2 2007 Aug 35834 49642 225277 256356. 567109.
## 3 2007 Dec 74090 82927 361356 690437. 1208810.
## 4 2007 Feb 47584 64623 270274 559051. 941532.
## 5 2007 Jan 56433 79251 329578 684618. 1149880.
## 6 2007 Jul 43052 55734 154973 243117. 496876.
## 7 2007 Jun 59672 69981 189615 274420. 593688.
## 8 2007 Mar 60758 104675 288235 522849. 976517.
## 9 2007 May 76235 72151 228526 356324. 733236.
## 10 2007 Nov 50823 73687 299690 507719. 931919.
## # … with 26 more rows
ts789_Kitchen <- ts(df789_met$sumKitchen, frequency = 12, start=c(2007,1))
ts789_Laundromat <- ts(df789_met$sumLaundromat, frequency = 12, start=c(2007,1))
ts789_TC <- ts(df789_met$sumTC, frequency = 12, start=c(2007,1))
ts789_OEE <- ts(df789_met$sumOEE, frequency = 12, start=c(2007,1))
ts789_all <- ts(df789_met$sumAll, frequency = 12, start=c(2007,1))
# package fpp2
ggseasonplot(ts789_Kitchen)
ggseasonplot(ts789_Laundromat)
ggseasonplot(ts789_TC)
ggseasonplot(ts789_OEE)
ggseasonplot(ts789_all)
# package fpp2
ggseasonplot(ts789_Kitchen, polar=TRUE)
ggseasonplot(ts789_Laundromat, polar=TRUE)
ggseasonplot(ts789_TC, polar=TRUE)
ggseasonplot(ts789_OEE, polar=TRUE)
ggseasonplot(ts789_all, polar=TRUE)
par(mfrow=c(3,2))
plot(ts789_Kitchen, col="orange", main="Monthly Consumption Kitchen")
plot(ts789_Laundromat, col="blue", main="Monthly Consumption Laundromat")
plot(ts789_TC, col="green", main="Monthly Consumption Temp Control")
plot(ts789_OEE, col="lightgrey", main="Monthly Consumption Everything Else")
plot(ts789_all, col="red", main="Monthly Consumption Total")
#decompose
tsKd <- decompose(ts789_Kitchen) #kitchen
tsLd <- decompose(ts789_Laundromat) #laundromat
tsTd <- decompose(ts789_TC) # temperature control
tsOd <- decompose(ts789_OEE) # other appliances
tsAd <- decompose(ts789_all) # total
#plot
plot(tsKd)
plot(tsLd)
plot(tsTd)
plot(tsOd)
plot(tsAd)
#naive forecasting
naiveKitchen <- naive(ts789_Kitchen, h=12)
naiveLaundromat <- naive(ts789_Laundromat, h=12)
naiveTC <- naive(ts789_TC, h=12)
naiveOEE <- naive(ts789_OEE, h=12)
naiveAll <- naive(ts789_all, h=12)
#plotting the naives
autoplot(naiveKitchen)
autoplot(naiveLaundromat)
autoplot(naiveTC)
autoplot(naiveOEE)
autoplot(naiveAll)
#summary of naives
summary(naiveKitchen)
##
## Forecast method: Naive method
##
## Model Information:
## Call: naive(y = ts789_Kitchen, h = 12)
##
## Residual sd: 21470.0437
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 287.4857 21470.04 17147.43 -38.6244 68.46997 1.427827 -0.5593082
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 51653 24138.032 79167.97 9572.488 93733.51
## Feb 2010 51653 12740.959 90565.04 -7857.831 111163.83
## Mar 2010 51653 3995.677 99310.32 -21232.585 124538.59
## Apr 2010 51653 -3376.936 106682.94 -32508.025 135814.02
## May 2010 51653 -9872.339 113178.34 -42441.886 145747.89
## Jun 2010 51653 -15744.632 119050.63 -51422.783 154728.78
## Jul 2010 51653 -21144.763 124450.76 -59681.571 162987.57
## Aug 2010 51653 -26171.082 129477.08 -67368.663 170674.66
## Sep 2010 51653 -30891.904 134197.90 -74588.537 177894.54
## Oct 2010 51653 -35356.969 138662.97 -81417.264 184723.26
## Nov 2010 51653 -39603.825 142909.83 -87912.271 191218.27
## Dec 2010 51653 -43661.645 146967.65 -94118.171 197424.17
summary(naiveLaundromat)
##
## Forecast method: Naive method
##
## Model Information:
## Call: naive(y = ts789_Laundromat, h = 12)
##
## Residual sd: 18850.9605
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 215.4 18850.96 15578.26 -6.448364 30.50085 0.9155087 -0.3091428
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 45985 21826.522 70143.48 9037.796 82932.20
## Feb 2010 45985 11819.753 80150.25 -6266.237 98236.24
## Mar 2010 45985 4141.289 87828.71 -18009.434 109979.43
## Apr 2010 45985 -2331.956 94301.96 -27909.407 119879.41
## May 2010 45985 -8034.999 100005.00 -36631.459 128601.46
## Jun 2010 45985 -13190.944 105160.94 -44516.796 136486.80
## Jul 2010 45985 -17932.325 109902.32 -51768.113 143738.11
## Aug 2010 45985 -22345.494 114315.49 -58517.473 150487.47
## Sep 2010 45985 -26490.434 118460.43 -64856.611 156826.61
## Oct 2010 45985 -30410.815 122380.82 -70852.317 162822.32
## Nov 2010 45985 -34139.607 126109.61 -76555.012 168525.01
## Dec 2010 45985 -37702.422 129672.42 -82003.868 173973.87
summary(naiveTC)
##
## Forecast method: Naive method
##
## Model Information:
## Call: naive(y = ts789_TC, h = 12)
##
## Residual sd: 92251.7255
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 2977.543 92251.73 70389.2 -9.055431 32.75646 1.415657 -0.6281436
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 295843 177617.657 414068.3 115032.94 476653.1
## Feb 2010 295843 128647.116 463038.9 40138.96 551547.0
## Mar 2010 295843 91070.699 500615.3 -17329.21 609015.2
## Apr 2010 295843 59392.314 532293.7 -65777.12 657463.1
## May 2010 295843 31483.096 560202.9 -108460.58 700146.6
## Jun 2010 295843 6251.234 585434.8 -147049.39 738735.4
## Jul 2010 295843 -16951.857 608637.9 -182535.45 774221.5
## Aug 2010 295843 -38548.768 630234.8 -215565.08 807251.1
## Sep 2010 295843 -58833.030 650519.0 -246587.18 838273.2
## Oct 2010 295843 -78018.362 669704.4 -275928.61 867614.6
## Nov 2010 295843 -96266.104 687952.1 -303836.13 895522.1
## Dec 2010 295843 -113701.602 705387.6 -330501.42 922187.4
summary(naiveOEE)
##
## Forecast method: Naive method
##
## Model Information:
## Call: naive(y = ts789_OEE, h = 12)
##
## Residual sd: 211139.0047
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -75.58096 211139 173091.3 -18.73948 51.09778 3.156825 -0.5078119
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 315241.2 44655.68 585826.7 -98583.65 729066.0
## Feb 2010 315241.2 -67424.52 697906.9 -269995.51 900477.9
## Mar 2010 315241.2 -153426.67 783909.1 -401524.46 1032006.9
## Apr 2010 315241.2 -225929.84 856412.2 -512408.49 1142890.9
## May 2010 315241.2 -289806.42 920288.8 -610099.28 1240581.7
## Jun 2010 315241.2 -347555.26 978037.7 -698418.51 1328900.9
## Jul 2010 315241.2 -400660.80 1031143.2 -779636.43 1410118.8
## Aug 2010 315241.2 -450090.23 1080572.6 -855232.22 1485714.6
## Sep 2010 315241.2 -496515.37 1126997.8 -926233.33 1556715.7
## Oct 2010 315241.2 -540425.35 1170907.8 -993387.86 1623870.3
## Nov 2010 315241.2 -582189.45 1212671.9 -1057260.54 1687742.9
## Dec 2010 315241.2 -622094.54 1252576.9 -1118290.11 1748772.5
summary(naiveAll)
##
## Forecast method: Naive method
##
## Model Information:
## Call: naive(y = ts789_all, h = 12)
##
## Residual sd: 325226.8157
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 3404.848 325226.8 263542.6 -12.97477 40.81994 2.860911 -0.5513107
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 708722.2 291927.3 1125517 71289.35 1346155
## Feb 2010 708722.2 119285.2 1298159 -192743.98 1610188
## Mar 2010 708722.2 -13187.8 1430632 -395343.88 1812788
## Apr 2010 708722.2 -124867.7 1542312 -566143.49 1983588
## May 2010 708722.2 -223259.6 1640704 -716620.97 2134065
## Jun 2010 708722.2 -312212.7 1729657 -852663.02 2270107
## Jul 2010 708722.2 -394013.5 1811458 -977766.59 2395211
## Aug 2010 708722.2 -470151.9 1887596 -1094210.15 2511655
## Sep 2010 708722.2 -541662.6 1959107 -1203576.34 2621021
## Oct 2010 708722.2 -609299.1 2026744 -1307017.45 2724462
## Nov 2010 708722.2 -673630.2 2091075 -1405403.38 2822848
## Dec 2010 708722.2 -735097.8 2152542 -1499409.95 2916854
#naive forecasting
snaiveKitchen <- snaive(ts789_Kitchen, h=12)
snaiveLaundromat <- snaive(ts789_Laundromat, h=12)
snaiveTC <- snaive(ts789_TC, h=12)
snaiveOEE <- snaive(ts789_OEE, h=12)
snaiveAll <- snaive(ts789_all, h=12)
#plotting the naives
autoplot(snaiveKitchen)
autoplot(snaiveLaundromat)
autoplot(snaiveTC)
autoplot(snaiveOEE)
autoplot(snaiveAll)
#summary of naives
summary(snaiveKitchen)
##
## Forecast method: Seasonal naive method
##
## Model Information:
## Call: snaive(y = ts789_Kitchen, h = 12)
##
## Residual sd: 16332.9625
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -2078.792 16332.96 12009.46 -42.07327 62.34647 1 0.3190801
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 54506 33574.466 75437.53 22493.9818 86518.02
## Feb 2010 33480 12548.466 54411.53 1467.9818 65492.02
## Mar 2010 57801 36869.466 78732.53 25788.9818 89813.02
## Apr 2010 47099 26167.466 68030.53 15086.9818 79111.02
## May 2010 74650 53718.466 95581.53 42637.9818 106662.02
## Jun 2010 18226 -2705.534 39157.53 -13786.0182 50238.02
## Jul 2010 31885 10953.466 52816.53 -127.0182 63897.02
## Aug 2010 64645 43713.466 85576.53 32632.9818 96657.02
## Sep 2010 43047 22115.466 63978.53 11034.9818 75059.02
## Oct 2010 60445 39513.466 81376.53 28432.9818 92457.02
## Nov 2010 55220 34288.466 76151.53 23207.9818 87232.02
## Dec 2010 51653 30721.466 72584.53 19640.9818 83665.02
summary(snaiveLaundromat)
##
## Forecast method: Seasonal naive method
##
## Model Information:
## Call: snaive(y = ts789_Laundromat, h = 12)
##
## Residual sd: 20430.4031
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -10924.12 20430.4 17015.96 -26.44356 37.14882 1 0.1887518
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 52650 26467.385 78832.62 12607.146 92692.85
## Feb 2010 38298 12115.385 64480.62 -1744.854 78340.85
## Mar 2010 53490 27307.385 79672.62 13447.146 93532.85
## Apr 2010 50681 24498.385 76863.62 10638.146 90723.85
## May 2010 72984 46801.385 99166.62 32941.146 113026.85
## Jun 2010 42418 16235.385 68600.62 2375.146 82460.85
## Jul 2010 29789 3606.385 55971.62 -10253.854 69831.85
## Aug 2010 48348 22165.385 74530.62 8305.146 88390.85
## Sep 2010 50094 23911.385 76276.62 10051.146 90136.85
## Oct 2010 53473 27290.385 79655.62 13430.146 93515.85
## Nov 2010 53967 27784.385 80149.62 13924.146 94009.85
## Dec 2010 45985 19802.385 72167.62 5942.146 86027.85
summary(snaiveTC)
##
## Forecast method: Seasonal naive method
##
## Model Information:
## Call: snaive(y = ts789_TC, h = 12)
##
## Residual sd: 61816.5813
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 22247.67 61816.58 49721.92 2.136891 23.65514 1 0.0678801
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 305811 226589.9 385032.1 184652.73 426969.3
## Feb 2010 192081 112859.9 271302.1 70922.73 313239.3
## Mar 2010 382896 303674.9 462117.1 261737.73 504054.3
## Apr 2010 296735 217513.9 375956.1 175576.73 417893.3
## May 2010 328521 249299.9 407742.1 207362.73 449679.3
## Jun 2010 187949 108727.9 267170.1 66790.73 309107.3
## Jul 2010 260554 181332.9 339775.1 139395.73 381712.3
## Aug 2010 329213 249991.9 408434.1 208054.73 450371.3
## Sep 2010 312270 233048.9 391491.1 191111.73 433428.3
## Oct 2010 335532 256310.9 414753.1 214373.73 456690.3
## Nov 2010 328312 249090.9 407533.1 207153.73 449470.3
## Dec 2010 295843 216621.9 375064.1 174684.73 417001.3
summary(snaiveOEE)
##
## Forecast method: Seasonal naive method
##
## Model Information:
## Call: snaive(y = ts789_OEE, h = 12)
##
## Residual sd: 70314.1012
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -23385.64 70314.1 54830.82 -9.35725 18.93775 1 0.2771404
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 404128.4 314017.2 494239.5 266315.26 541941.5
## Feb 2010 219580.3 129469.2 309691.4 81767.19 357393.4
## Mar 2010 519623.9 429512.7 609735.0 381810.76 657437.0
## Apr 2010 444336.1 354224.9 534447.2 306522.96 582149.2
## May 2010 570483.4 480372.3 660594.6 432670.33 708296.5
## Jun 2010 211490.0 121378.9 301601.2 73676.93 349303.1
## Jul 2010 239249.7 149138.6 329360.9 101436.63 377062.8
## Aug 2010 470697.0 380585.9 560808.1 332883.89 608510.1
## Sep 2010 349871.8 259760.7 439983.0 212058.73 487684.9
## Oct 2010 468271.8 378160.6 558382.9 330458.66 606084.9
## Nov 2010 417280.3 327169.2 507391.4 279467.19 555093.4
## Dec 2010 315241.2 225130.1 405352.3 177428.09 453054.3
summary(snaiveAll)
##
## Forecast method: Seasonal naive method
##
## Model Information:
## Call: snaive(y = ts789_all, h = 12)
##
## Residual sd: 132935.5961
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -14140.89 132935.6 92118.41 -6.459704 18.2881 1 0.2250479
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 817095.4 646731.5 987459.2 556546.4 1077644.3
## Feb 2010 483439.3 313075.5 653803.1 222890.3 743988.3
## Mar 2010 1013810.9 843447.0 1184174.7 753261.9 1274359.8
## Apr 2010 838851.1 668487.2 1009214.9 578302.1 1099400.0
## May 2010 1046638.4 876274.6 1217002.3 786089.5 1307187.4
## Jun 2010 460083.0 289719.2 630446.9 199534.1 720632.0
## Jul 2010 561477.7 391113.9 731841.6 300928.8 822026.7
## Aug 2010 912903.0 742539.2 1083266.8 652354.0 1173452.0
## Sep 2010 755282.8 584919.0 925646.7 494733.9 1015831.8
## Oct 2010 917721.8 747357.9 1088085.6 657172.8 1178270.7
## Nov 2010 854779.3 684415.5 1025143.1 594230.3 1115328.3
## Dec 2010 708722.2 538358.4 879086.0 448173.2 969271.2
#library(forecast)
fitKitchen <- tslm(ts789_Kitchen~ trend + season)
summary(fitKitchen)
##
## Call:
## tslm(formula = ts789_Kitchen ~ trend + season)
##
## Residuals:
## Min 1Q Median 3Q Max
## -20522.7 -5210.9 228.9 6728.7 16700.9
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 50158.4 7294.5 6.876 0.000000519 ***
## trend -173.2 200.7 -0.863 0.3970
## season2 -23337.4 9635.6 -2.422 0.0237 *
## season3 11439.5 9641.8 1.186 0.2476
## season4 -2428.3 9652.3 -0.252 0.8036
## season5 17067.9 9666.9 1.766 0.0907 .
## season6 -10843.2 9685.6 -1.120 0.2745
## season7 6561.4 9708.5 0.676 0.5059
## season8 15963.3 9735.4 1.640 0.1147
## season9 10934.9 9766.4 1.120 0.2744
## season10 10097.8 9801.4 1.030 0.3136
## season11 1509.7 9840.3 0.153 0.8794
## season12 6254.9 9883.2 0.633 0.5331
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11800 on 23 degrees of freedom
## Multiple R-squared: 0.5796, Adjusted R-squared: 0.3602
## F-statistic: 2.642 on 12 and 23 DF, p-value: 0.02186
fitLaundromat <- tslm(ts789_Laundromat~ trend + season)
summary(fitLaundromat)
##
## Call:
## tslm(formula = ts789_Laundromat ~ trend + season)
##
## Residuals:
## Min 1Q Median 3Q Max
## -26462 -4047 1225 6742 16873
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 65818.8 7709.9 8.537 0.0000000138 ***
## trend -910.3 212.1 -4.292 0.000272 ***
## season2 -16071.3 10184.3 -1.578 0.128210
## season3 6460.7 10190.9 0.634 0.532358
## season4 6076.4 10201.9 0.596 0.557253
## season5 21360.7 10217.4 2.091 0.047807 *
## season6 -2197.6 10237.2 -0.215 0.831916
## season7 5901.1 10261.3 0.575 0.570821
## season8 29802.1 10289.8 2.896 0.008142 **
## season9 13676.1 10322.5 1.325 0.198225
## season10 15214.8 10359.5 1.469 0.155466
## season11 23513.8 10400.7 2.261 0.033541 *
## season12 11337.4 10446.0 1.085 0.289018
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 12470 on 23 degrees of freedom
## Multiple R-squared: 0.6518, Adjusted R-squared: 0.4702
## F-statistic: 3.588 on 12 and 23 DF, p-value: 0.00413
fitTC <- tslm(ts789_TC~ trend + season)
summary(fitTC)
##
## Call:
## tslm(formula = ts789_TC ~ trend + season)
##
## Residuals:
## Min 1Q Median 3Q Max
## -86828 -18452 4621 17636 82260
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 240955.0 23239.4 10.368 0.000000000385 ***
## trend 1854.0 639.4 2.900 0.00808 **
## season2 -101645.6 30697.9 -3.311 0.00305 **
## season3 82068.1 30717.9 2.672 0.01363 *
## season4 4049.8 30751.2 0.132 0.89637
## season5 50948.4 30797.7 1.654 0.11165
## season6 -84333.5 30857.3 -2.733 0.01185 *
## season7 -29516.8 30930.1 -0.954 0.34985
## season8 20293.9 31015.9 0.654 0.51941
## season9 -2941.8 31114.6 -0.095 0.92549
## season10 23236.6 31226.1 0.744 0.46433
## season11 3909.6 31350.2 0.125 0.90184
## season12 -16529.4 31486.9 -0.525 0.60463
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 37590 on 23 degrees of freedom
## Multiple R-squared: 0.7566, Adjusted R-squared: 0.6297
## F-statistic: 5.959 on 12 and 23 DF, p-value: 0.0001292
fitOe <- tslm(ts789_OEE~ trend + season)
summary(fitOe)
##
## Call:
## tslm(formula = ts789_OEE ~ trend + season)
##
## Residuals:
## Min 1Q Median 3Q Max
## -90659 -22182 -120 25076 78527
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 396144.6 28934.4 13.691 0.00000000000152 ***
## trend -1948.8 796.1 -2.448 0.022415 *
## season2 -176222.7 38220.7 -4.611 0.000123 ***
## season3 221611.7 38245.6 5.794 0.00000665375944 ***
## season4 126314.8 38287.0 3.299 0.003137 **
## season5 271446.8 38344.9 7.079 0.00000032704706 ***
## season6 -119610.9 38419.2 -3.113 0.004891 **
## season7 -89280.7 38509.8 -2.318 0.029671 *
## season8 141989.0 38616.6 3.677 0.001250 **
## season9 -745.4 38739.5 -0.019 0.984815
## season10 173279.4 38878.3 4.457 0.000180 ***
## season11 86897.8 39032.9 2.226 0.036076 *
## season12 -19856.1 39203.0 -0.506 0.617330
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 46800 on 23 degrees of freedom
## Multiple R-squared: 0.9297, Adjusted R-squared: 0.893
## F-statistic: 25.33 on 12 and 23 DF, p-value: 0.0000000002065
fitAll <- tslm(ts789_all~ trend + season)
summary(fitAll)
##
## Call:
## tslm(formula = ts789_all ~ trend + season)
##
## Residuals:
## Min 1Q Median 3Q Max
## -211944 -32155 -9648 43483 137689
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 753077 54488 13.821 0.00000000000126 ***
## trend -1178 1499 -0.786 0.439867
## season2 -317277 71976 -4.408 0.000204 ***
## season3 321580 72022 4.465 0.000177 ***
## season4 134013 72100 1.859 0.075915 .
## season5 360824 72210 4.997 0.00004700251521 ***
## season6 -216985 72349 -2.999 0.006403 **
## season7 -106335 72520 -1.466 0.156110
## season8 208048 72721 2.861 0.008838 **
## season9 20924 72953 0.287 0.776823
## season10 221828 73214 3.030 0.005957 **
## season11 115831 73505 1.576 0.128723
## season12 -18793 73825 -0.255 0.801324
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 88130 on 23 degrees of freedom
## Multiple R-squared: 0.8882, Adjusted R-squared: 0.8298
## F-statistic: 15.22 on 12 and 23 DF, p-value: 0.00000003464
forecastfitKitchen <- forecast(fitKitchen, h=12)
plot(forecastfitKitchen)
forecastfitLaundromat <- forecast(fitLaundromat, h=12)
plot(forecastfitLaundromat)
forecastfitTC <- forecast(fitTC, h=12)
plot(forecastfitTC)
forecastfitOe <- forecast(fitOe, h=12)
plot(forecastfitOe)
forecastfitAll <- forecast(fitAll, h=12)
plot(forecastfitAll)
fcKitchen <- hw(ts789_Kitchen, seasonal="additive", h=12)
checkresiduals(fcKitchen)
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' additive method
## Q* = 29.152, df = 3, p-value = 0.000002081
##
## Model df: 16. Total lags used: 19
autoplot(fcKitchen)
fcLaundromat <- hw(ts789_Laundromat, seasonal="additive", h=12)
checkresiduals(fcLaundromat)
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' additive method
## Q* = 27.308, df = 3, p-value = 0.000005074
##
## Model df: 16. Total lags used: 19
autoplot(fcLaundromat)
fcTC <- hw(ts789_TC, seasonal="additive", h=12)
checkresiduals(fcTC)
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' additive method
## Q* = 39.339, df = 3, p-value = 0.00000001471
##
## Model df: 16. Total lags used: 19
autoplot(fcTC)
fcOe <- hw(ts789_OEE, seasonal="additive", h=12)
checkresiduals(fcOe)
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' additive method
## Q* = 26.731, df = 3, p-value = 0.000006704
##
## Model df: 16. Total lags used: 19
autoplot(fcOe)
fcAll <- hw(ts789_all, seasonal="additive", h=12)
checkresiduals(fcAll)
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' additive method
## Q* = 25.04, df = 3, p-value = 0.00001515
##
## Model df: 16. Total lags used: 19
autoplot(fcAll)
Residuals should look like white noise+ Assumptions: - residuals are uncorrelated - mean(residuals=0) - variance of residuals is constant - residuals are normally distributed
checkresiduals(forecastfitKitchen) #regression
##
## Ljung-Box test
##
## data: Residuals from Linear regression model
## Q* = 36.665, df = 3, p-value = 0.00000005416
##
## Model df: 13. Total lags used: 16
checkresiduals(snaiveKitchen) #seasonal naive
##
## Ljung-Box test
##
## data: Residuals from Seasonal naive method
## Q* = 11.881, df = 7, p-value = 0.1046
##
## Model df: 0. Total lags used: 7
checkresiduals(fcKitchen) #holtwinters
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' additive method
## Q* = 29.152, df = 3, p-value = 0.000002081
##
## Model df: 16. Total lags used: 19
checkresiduals(forecastfitLaundromat) #regression
##
## Ljung-Box test
##
## data: Residuals from Linear regression model
## Q* = 20.741, df = 3, p-value = 0.0001192
##
## Model df: 13. Total lags used: 16
checkresiduals(snaiveLaundromat) #seasonal naive
##
## Ljung-Box test
##
## data: Residuals from Seasonal naive method
## Q* = 5.7088, df = 7, p-value = 0.5741
##
## Model df: 0. Total lags used: 7
checkresiduals(fcLaundromat) #holtwinters
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' additive method
## Q* = 27.308, df = 3, p-value = 0.000005074
##
## Model df: 16. Total lags used: 19
checkresiduals(forecastfitTC) #regression
##
## Ljung-Box test
##
## data: Residuals from Linear regression model
## Q* = 37.52, df = 3, p-value = 0.00000003572
##
## Model df: 13. Total lags used: 16
checkresiduals(snaiveTC) #seasonal naive
##
## Ljung-Box test
##
## data: Residuals from Seasonal naive method
## Q* = 8.077, df = 7, p-value = 0.3259
##
## Model df: 0. Total lags used: 7
checkresiduals(fcTC) #holtwinters
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' additive method
## Q* = 39.339, df = 3, p-value = 0.00000001471
##
## Model df: 16. Total lags used: 19
checkresiduals(forecastfitOe) #regression
##
## Ljung-Box test
##
## data: Residuals from Linear regression model
## Q* = 25.748, df = 3, p-value = 0.00001077
##
## Model df: 13. Total lags used: 16
checkresiduals(snaiveOEE) #seasonal naive
##
## Ljung-Box test
##
## data: Residuals from Seasonal naive method
## Q* = 3.6713, df = 7, p-value = 0.8168
##
## Model df: 0. Total lags used: 7
checkresiduals(fcOe) #holtwinters
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' additive method
## Q* = 26.731, df = 3, p-value = 0.000006704
##
## Model df: 16. Total lags used: 19
checkresiduals(forecastfitAll) #regression
##
## Ljung-Box test
##
## data: Residuals from Linear regression model
## Q* = 26.729, df = 3, p-value = 0.00000671
##
## Model df: 13. Total lags used: 16
checkresiduals(snaiveAll) #seasonal naive
##
## Ljung-Box test
##
## data: Residuals from Seasonal naive method
## Q* = 3.1215, df = 7, p-value = 0.8735
##
## Model df: 0. Total lags used: 7
checkresiduals(fcAll) #holtwinters
##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' additive method
## Q* = 25.04, df = 3, p-value = 0.00001515
##
## Model df: 16. Total lags used: 19
#Plot overlay actual vs. fitted
autoplot(ts789_Kitchen, series="Actual values")+
autolayer(fitted(fcKitchen), series="Fitted values")+
ggtitle("Electricity consumption - Kitchen")
autoplot(ts789_Laundromat, series="Actual values")+
autolayer(fitted(fcLaundromat), series="Fitted values")+
ggtitle("Electricity consumption - Laundromat")
autoplot(ts789_TC, series="Actual values")+
autolayer(fitted(fcTC), series="Fitted values")+
ggtitle("Electricity consumption - Temp control")
autoplot(ts789_OEE, series="Actual values")+
autolayer(fitted(fcOe), series="Fitted values")+
ggtitle("Electricity consumption - Other appliances")
autoplot(ts789_all, series="Actual values")+
autolayer(fitted(fcAll), series="Fitted values")+
ggtitle("Electricity consumption - Total")
#Prep test set
# bind together Date and Time, which are now chr
#write_csv(yr_2010, file="~/2810_uc3_R/T1C4/yr_2010.csv")
yr_2010 <- read_csv(file="~/2810_uc3_R/T1C4/yr_2010.csv")
## Rows: 457394 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (8): id, Global_active_power, Global_reactive_power, Global_intensity, ...
## date (1): Date
## time (1): Time
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
df10 <- cbind(yr_2010, paste(yr_2010$Date,yr_2010$Time), stringsAsFactors=FALSE)
## Give the new attribute in the 9th column a header name
colnames(df10)[11] <-"DateTime"
# since we're at renaming columns, will rename the sub_meters too
colnames(df10)[8] <-"Kitchen"
colnames(df10)[9] <-"Laundromat"
colnames(df10)[10] <-"Temp_control"
#move the DateTime attribute within the dataset
df10 <- df10[,c(ncol(df10),1:(ncol(df10)-1))]
# drop original date and time columns, ID and voltage
df10 <- subset(df10, select = -c(Date, Time, id, Voltage))
#convert from chr to POSIXct
df10$DateTime <- as.POSIXct(df10$DateTime, "%Y-%m-%d %H:%M:%S")
## Warning in strptime(xx, f, tz = tz): unknown timezone '%Y-%m-%d %H:%M:%S'
## Warning in as.POSIXct.POSIXlt(x): unknown timezone '%Y-%m-%d %H:%M:%S'
## Warning in strptime(x, f, tz = tz): unknown timezone '%Y-%m-%d %H:%M:%S'
## Warning in as.POSIXct.POSIXlt(as.POSIXlt(x, tz, ...), tz, ...): unknown timezone
## '%Y-%m-%d %H:%M:%S'
#set time-zone
attr(df10$DateTime, "tzone") <- "GMT"
#inspect new data types
str(df10)
## 'data.frame': 457394 obs. of 7 variables:
## $ DateTime : POSIXct, format: "2010-01-01 00:00:00" "2010-01-01 00:01:00" ...
## $ Global_active_power : num 1.79 1.78 1.78 1.75 1.69 ...
## $ Global_reactive_power: num 0.236 0.234 0.234 0.186 0.102 0.1 0.1 0.102 0.072 0 ...
## $ Global_intensity : num 7.4 7.4 7.4 7.2 7 7 7 7 6.8 6.6 ...
## $ Kitchen : num 0 0 0 0 0 0 0 0 0 0 ...
## $ Laundromat : num 0 0 0 0 0 0 0 0 0 0 ...
## $ Temp_control : num 18 18 19 18 18 19 18 18 19 18 ...
df10$year <- year(df10$DateTime)
df10$month <- month(df10$DateTime, label=TRUE)
df10$week <- week(df10$DateTime)
df10$day <- day(df10$DateTime)
df10$hour <- hour(df10$DateTime)
df10$minute <- minute(df10$DateTime)
df10$quarter <- quarter(df10$DateTime)
df10$weekDay <- wday(df10$DateTime, label=TRUE, week_start=getOption("lubridate.week.start", 1))
# sum sub meters
df10$sumMeters <- df10$Kitchen + df10$Laundromat + df10$Temp_control
# compute total consumption
df10$gapW <- df10$Global_active_power*1000/60
# compute other electricals
df10$otherEE <- df10$gapW - df10$sumMeters
df10_met<-df10%>%
group_by(year, month)%>%
summarise(sumKitchen=sum(Kitchen),
sumLaundromat=sum(Laundromat),
sumTC=sum(Temp_control),
sumOEE=sum(otherEE),
sumAll=sum(gapW))
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
df10_met
## # A tibble: 11 × 7
## # Groups: year [1]
## year month sumKitchen sumLaundromat sumTC sumOEE sumAll
## <dbl> <ord> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2010 Jan 53887 56568 395913 483293. 989661.
## 2 2010 Feb 49268 53590 411714 409956. 924528.
## 3 2010 Mar 35089 60872 324352 382285. 802598.
## 4 2010 Apr 38196 36476 336091 328872. 739635.
## 5 2010 May 48107 52376 364625 349765. 814873.
## 6 2010 Jun 65747 47675 306934 277734. 698090.
## 7 2010 Jul 17667 34359 192912 291525. 536463.
## 8 2010 Aug 12499 26983 160189 168719. 368390.
## 9 2010 Sep 36865 32508 257861 277923. 605157.
## 10 2010 Oct 48199 60220 315669 441461. 865549.
## 11 2010 Nov 46162 42282 247113 407749. 743306.
ts10_Kitchen <- ts(df10_met$sumKitchen, frequency = 11, start=c(2010,1))
ts10_Laundromat <- ts(df10_met$sumLaundromat, frequency = 11, start=c(2010,1))
ts10_TC <- ts(df10_met$sumTC, frequency = 11, start=c(2010,1))
ts10_OEE <- ts(df10_met$sumOEE, frequency = 11, start=c(2010,1))
ts10_all <- ts(df10_met$sumAll, frequency = 11, start=c(2010,1))
trainingK <- ts789_Kitchen
testK <- ts10_Kitchen
fcK <- hw(trainingK, h=11)
autoplot(fcK)+autolayer(testK, series="Test data: Kitchen")
accuracy(fcK,testK)
## ME RMSE MAE MPE MAPE MASE
## Training set 10.37171 10341.45 8305.971 -13.79947 29.79065 0.6916191
## Test set -6087.30633 26579.96 22266.747 -57.83856 86.58067 1.8541008
## ACF1 Theil's U
## Training set 0.08740131 NA
## Test set 0.01092548 1.481096
summary(fcK)
##
## Forecast method: Holt-Winters' additive method
##
## Model Information:
## Holt-Winters' additive method
##
## Call:
## hw(y = trainingK, h = 11)
##
## Smoothing parameters:
## alpha = 0.0001
## beta = 0.0001
## gamma = 0.0001
##
## Initial states:
## l = 54001.5701
## b = -187.0126
## s = 1031.819 -5047.28 3193.73 13016.58 9631.69 12388.69
## -16727.38 18925.23 -5184.269 4158.327 -30663.85 -4723.291
##
## sigma: 13874.51
##
## AIC AICc BIC
## 828.5686 862.5686 855.4884
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 10.37171 10341.45 8305.971 -13.79947 29.79065 0.6916191 0.08740131
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 42356.71 24575.817 60137.61 15163.178 69550.25
## Feb 2010 16229.96 -1550.933 34010.86 -10963.572 43423.50
## Mar 2010 50865.16 33084.258 68646.05 23671.619 78058.69
## Apr 2010 41334.23 23553.331 59115.13 14140.691 68527.77
## May 2010 65255.37 47474.470 83036.27 38061.829 92448.91
## Jun 2010 29418.12 11637.215 47199.03 2224.573 56611.67
## Jul 2010 58343.70 40562.794 76124.61 31150.149 85537.26
## Aug 2010 55403.38 37622.464 73184.29 28209.816 82596.94
## Sep 2010 58598.77 40817.852 76379.70 31405.201 85792.35
## Oct 2010 48591.65 30810.718 66372.58 21398.061 75785.24
## Nov 2010 40163.56 22382.622 57944.51 12969.960 67357.17
trainingL <- ts789_Laundromat
testL <- ts10_Laundromat
fcL <- hw(trainingL, h=11)
autoplot(fcL)+autolayer(testL, series="Test data: Laundromat")
accuracy(fcL,testL)
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -102.333 10488.65 8152.085 -3.540696 16.67837 0.4790847 0.2459795
## Test set 9479.141 22907.35 18091.734 9.527445 40.37041 1.0632216 0.3691601
## Theil's U
## Training set NA
## Test set 1.429546
summary(fcL)
##
## Forecast method: Holt-Winters' additive method
##
## Model Information:
## Holt-Winters' additive method
##
## Call:
## hw(y = trainingL, h = 11)
##
## Smoothing parameters:
## alpha = 0.0001
## beta = 0.0001
## gamma = 0.0001
##
## Initial states:
## l = 75383.3826
## b = -903.0244
## s = -602.9715 12743.48 2428.693 1329.752 26907.62 1760.726
## -11384.39 12241.64 -3134.848 -6587.58 -28648.49 -7053.634
##
## sigma: 14072
##
## AIC AICc BIC
## 829.5862 863.5862 856.5060
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -102.333 10488.65 8152.085 -3.540696 16.67837 0.4790847 0.2459795
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 34908.60 16874.601 52942.60 7327.979 62489.22
## Feb 2010 12412.01 -5621.992 30446.01 -15168.614 39992.63
## Mar 2010 33569.66 15535.662 51603.66 5989.040 61150.28
## Apr 2010 36117.85 18083.846 54151.85 8537.223 63698.47
## May 2010 50590.91 32556.912 68624.92 23010.287 78171.54
## Jun 2010 26061.51 8027.501 44095.51 -1519.126 53642.14
## Jul 2010 38301.71 20267.704 56335.72 10721.075 65882.35
## Aug 2010 62544.84 44510.825 80578.86 34964.193 90125.49
## Sep 2010 36066.41 18032.389 54100.44 8485.754 63647.07
## Oct 2010 36262.09 18228.059 54296.12 8681.418 63842.76
## Nov 2010 45672.88 27638.832 63706.92 18092.186 73253.57
trainingTC <- ts789_TC
testTC <- ts10_TC
fcTC <- hw(trainingTC, h=11)
autoplot(fcTC)+autolayer(testTC, series="Test data: Temperature control")
accuracy(fcTC,testTC)
## ME RMSE MAE MPE MAPE MASE
## Training set -2631.161 31029.56 23925.06 -4.050852 11.70847 0.4811773
## Test set -4028.034 103129.77 81511.91 -11.251604 31.58864 1.6393558
## ACF1 Theil's U
## Training set 0.01681433 NA
## Test set 0.25253908 1.473236
summary(fcTC)
##
## Forecast method: Holt-Winters' additive method
##
## Model Information:
## Holt-Winters' additive method
##
## Call:
## hw(y = trainingTC, h = 11)
##
## Smoothing parameters:
## alpha = 0.0005
## beta = 0.0001
## gamma = 0.0001
##
## Initial states:
## l = 243861.8042
## b = 1617.2792
## s = -6309.157 5998.606 29127.61 -290.1132 23068.28 -18412.04
## -69008.79 46779.39 5510.321 76802.22 -107168.9 13902.59
##
## sigma: 41630.52
##
## AIC AICc BIC
## 907.6808 941.6808 934.6006
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -2631.161 31029.56 23925.06 -4.050852 11.70847 0.4811773
## ACF1
## Training set 0.01681433
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 317288.7 263937.1 370640.4 235694.4 398883.1
## Feb 2010 197830.6 144479.0 251182.3 116236.3 279425.0
## Mar 2010 383409.2 330057.5 436760.9 301814.8 465003.6
## Apr 2010 313722.8 260371.1 367074.5 232128.4 395317.1
## May 2010 356601.0 303249.3 409952.8 275006.6 438195.5
## Jun 2010 242414.4 189062.7 295766.2 160820.0 324008.9
## Jul 2010 294620.0 241268.2 347971.8 213025.5 376214.5
## Aug 2010 337710.3 284358.5 391062.2 256115.8 419304.9
## Sep 2010 315959.5 262607.6 369311.4 234364.8 397554.1
## Oct 2010 346983.7 293631.8 400335.7 265389.0 428578.5
## Nov 2010 325463.4 272111.4 378815.4 243868.5 407058.2
trainingOe <- ts789_OEE
testOe <- ts10_OEE
fcOe <- hw(trainingOe, h=11)
autoplot(fcOe)+autolayer(testOe, series="Test data: Other appliances")
accuracy(fcOe,testOe)
## ME RMSE MAE MPE MAPE MASE
## Training set -4325.446 39330.59 31813.66 -3.111138 9.82253 0.5802149
## Test set -44808.030 171227.44 145471.13 -23.221811 48.88759 2.6530903
## ACF1 Theil's U
## Training set 0.29015475 NA
## Test set 0.03576891 1.504348
summary(fcOe)
##
## Forecast method: Holt-Winters' additive method
##
## Model Information:
## Holt-Winters' additive method
##
## Call:
## hw(y = trainingOe, h = 11)
##
## Smoothing parameters:
## alpha = 0.0001
## beta = 0.0001
## gamma = 0.0001
##
## Initial states:
## l = 441866.5723
## b = -1414.2471
## s = -69023.76 39974.06 142206.3 -62656.2 89631.23 -137596
## -157525.5 210773.4 68147.97 162556.5 -235285.9 -51202.11
##
## sigma: 52767.53
##
## AIC AICc BIC
## 924.7493 958.7493 951.6691
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set -4325.446 39330.59 31813.66 -3.111138 9.82253 0.5802149 0.2901547
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 338289.1 270664.7 405913.4 234866.60 441711.5
## Feb 2010 152777.6 85153.3 220401.9 49355.15 256200.1
## Mar 2010 549190.1 481565.7 616814.4 445767.59 652612.5
## Apr 2010 453351.3 385727.0 520975.6 349928.81 556773.8
## May 2010 594547.5 526923.2 662171.8 491125.01 697970.0
## Jun 2010 224811.8 157187.4 292436.1 121389.29 328234.3
## Jul 2010 243314.4 175690.1 310938.8 139891.88 346736.9
## Aug 2010 469112.9 401488.5 536737.3 365690.32 572535.4
## Sep 2010 315398.3 247773.9 383022.7 211975.73 418820.9
## Oct 2010 518821.6 451197.2 586446.1 415398.97 622244.3
## Nov 2010 415164.1 347539.7 482788.6 311741.43 518586.9
trainingA <- ts789_all
testA <- ts10_all
fcA <- hw(trainingA, h=11)
autoplot(fcA)+autolayer(testA, series="Test data: Everything")
accuracy(fcA,testA)
## ME RMSE MAE MPE MAPE MASE
## Training set 690.2251 71966.0 53500.31 -2.210425 9.407374 0.5807776
## Test set -28823.5231 288684.7 232674.76 -13.585037 36.598130 2.5258225
## ACF1 Theil's U
## Training set 0.1984186 NA
## Test set 0.1229548 1.423504
summary(fcA)
##
## Forecast method: Holt-Winters' additive method
##
## Model Information:
## Holt-Winters' additive method
##
## Call:
## hw(y = trainingA, h = 11)
##
## Smoothing parameters:
## alpha = 0.0001
## beta = 0.0001
## gamma = 0.0001
##
## Initial states:
## l = 815113.4406
## b = -1311.6344
## s = -76788.74 50968.87 175971.8 -48599.95 149238.7 -141858.7
## -254646.1 288217.4 57157.85 244691 -394851.5 -49500.58
##
## sigma: 96552.52
##
## AIC AICc BIC
## 968.2510 1002.2510 995.1708
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 690.2251 71966 53500.31 -2.210425 9.407374 0.5807776 0.1984186
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2010 717123.3 593386.3 840860.3 527883.8 906362.8
## Feb 2010 370471.7 246734.6 494208.7 181232.2 559711.1
## Mar 2010 1008704.9 884967.8 1132441.9 819465.4 1197944.4
## Apr 2010 819862.6 696125.5 943599.7 630623.1 1009102.1
## May 2010 1049611.8 925874.7 1173348.9 860372.3 1238851.3
## Jun 2010 505428.7 381691.6 629165.7 316189.1 694668.2
## Jul 2010 616906.3 493169.2 740643.4 427666.7 806145.9
## Aug 2010 906701.6 782964.5 1030438.8 717462.0 1095941.3
## Sep 2010 707557.1 583819.8 831294.3 518317.3 896796.8
## Oct 2010 930812.6 807075.3 1054549.9 741572.8 1120052.4
## Nov 2010 804506.3 680768.9 928243.6 615266.3 993746.2
fcArimaK <- auto.arima(trainingK)
forKitchenArima <- forecast(fcArimaK, h=length(testK))
autoplot(forKitchenArima)+autolayer(testK, series="Test data: Kitchen")
accuracy(forKitchenArima,testK)
## ME RMSE MAE MPE MAPE MASE
## Training set -417.1997 13366.14 9682.022 -34.91416 49.14496 0.8061997
## Test set -9409.6426 20295.43 16242.987 -58.97536 69.99768 1.3525162
## ACF1 Theil's U
## Training set 0.06349605 NA
## Test set -0.01046993 1.266538
fcArimaL <- auto.arima(trainingL)
forLaundromatArima <- forecast(fcArimaL, h=length(testL))
autoplot(forLaundromatArima)+autolayer(testL, series="Test data: Laundromat")
accuracy(forLaundromatArima,testL)
## ME RMSE MAE MPE MAPE MASE
## Training set -659.0812 14216.38 10297.84 -8.288154 21.24246 0.6051873
## Test set -1166.2209 11206.85 10099.82 -9.553697 25.28697 0.5935498
## ACF1 Theil's U
## Training set -0.02126564 NA
## Test set 0.23195550 0.8530575
fcArimaTC <- auto.arima(trainingTC)
forTCArima <- forecast(fcArimaTC, h=length(testTC))
autoplot(forTCArima)+autolayer(testTC, series="Test data: Temperature control")
accuracy(forTCArima,testTC)
## ME RMSE MAE MPE MAPE MASE
## Training set -1143.872 29540.11 19216.78 -3.391218 9.628482 0.3864852
## Test set -1664.921 114786.50 84532.35 -11.239243 32.682680 1.7001025
## ACF1 Theil's U
## Training set 0.02449484 NA
## Test set 0.25498464 1.580597
fcArimaOe <- auto.arima(trainingOe)
forOEArima <- forecast(fcArimaOe, h=length(testOe))
autoplot(forOEArima)+autolayer(testOe, series="Test data: Other electronics")
accuracy(forOEArima,testOe)
## ME RMSE MAE MPE MAPE MASE
## Training set 137.7839 40527.94 24958.83 -1.909886 8.778239 0.455197
## Test set -32579.6514 167739.75 140015.99 -19.327530 47.150300 2.553600
## ACF1 Theil's U
## Training set -0.03533667 NA
## Test set 0.03561466 1.464766
fcArimaAll <- auto.arima(trainingA)
forAllArima <- forecast(fcArimaAll, h=length(testA))
autoplot(forAllArima)+autolayer(testA, series="Test data: Everything")
accuracy(forAllArima,testA)
## ME RMSE MAE MPE MAPE MASE
## Training set -6157.267 69375.87 41094.14 -3.559722 8.178051 0.4461012
## Test set -48874.646 306400.93 245102.24 -16.889687 38.843626 2.6607302
## ACF1 Theil's U
## Training set -0.1073350 NA
## Test set 0.1621909 1.546002
#Forecasts:
accHWk <- accuracy(fcK,testK)
accAaK <- accuracy(forKitchenArima,testK)
accHWk <- as.data.frame(accHWk)
accHWk$run <- c("Holt-Winters")
accHWk$tt <- row.names(accHWk)
accAaK <- as.data.frame(accAaK)
accAaK$run <- c("Auto Arima")
accAaK$tt <- row.names(accAaK)
accK <- bind_rows(accAaK, accHWk)
row.names(accK) <- NULL
accK <- accK[,c(ncol(accK),1:(ncol(accK)-1))]
accK <- accK[,c(ncol(accK),1:(ncol(accK)-1))]
accK
## run tt ME RMSE MAE MPE MAPE
## 1 Auto Arima Training set -417.19972 13366.14 9682.022 -34.91416 49.14496
## 2 Auto Arima Test set -9409.64257 20295.43 16242.987 -58.97536 69.99768
## 3 Holt-Winters Training set 10.37171 10341.45 8305.971 -13.79947 29.79065
## 4 Holt-Winters Test set -6087.30633 26579.96 22266.747 -57.83856 86.58067
## MASE ACF1 Theil's U
## 1 0.8061997 0.06349605 NA
## 2 1.3525162 -0.01046993 1.266538
## 3 0.6916191 0.08740131 NA
## 4 1.8541008 0.01092548 1.481096
autoplot(window(ts789_Kitchen, start=2007))+
autolayer(fcK$mean, series="Holt-Winters")+
autolayer(forKitchenArima$mean, series="Auto Arima")+
autolayer(ts10_Kitchen, series="Real values")+
xlab("Year") + ylab("Kilowatts")+
ggtitle("2010 Forecast: Kitchen")
autoplot(window(ts789_Laundromat, start=2007))+
autolayer(fcL$mean, series="Holt-Winters")+
autolayer(forLaundromatArima$mean, series="Auto Arima")+
autolayer(ts10_Laundromat, series="Real values")+
xlab("Year") + ylab("Kilowatts")+
ggtitle("2010 Forecast: Laundromat")
autoplot(window(ts789_TC, start=2007))+
autolayer(fcTC$mean, series="Holt-Winters")+
autolayer(forTCArima$mean, series="Auto Arima")+
autolayer(ts10_TC, series="Real values")+
xlab("Year") + ylab("Kilowatts")+
ggtitle("2010 Forecast: Temp Control")
autoplot(window(ts789_OEE, start=2007))+
autolayer(fcOe$mean, series="Holt-Winters")+
autolayer(forOEArima$mean, series="Auto Arima")+
autolayer(ts10_OEE, series="Real values")+
xlab("Year") + ylab("Kilowatts")+
ggtitle("2010 Forecast: Other Apliances")
autoplot(window(ts789_all, start=2007))+
autolayer(fcA$mean, series="Holt-Winters")+
autolayer(forAllArima$mean, series="Auto Arima")+
autolayer(ts10_all, series="Real values")+
xlab("Year") + ylab("Kilowatts")+
ggtitle("2010 Forecast: Everything")