1 Intro

In this project, I will be forecasting the US Energy consumption. the data is recorded monthly Now let’s import the data set

2 Import Data Set

Energy <- read.csv("electricity_data.csv")

3 EDA

let’s see our data set

Energy |> head(3)
##            X United.States...all.sectors United.States...electric.utility
## 1 2001-01-01                      332493                           236467
## 2 2001-02-01                      282940                           199802
## 3 2001-03-01                      300707                           211942
##   United.States...independent.power.producers United.States...all.commercial
## 1                                       82269                            629
## 2                                       71169                            548
## 3                                       75758                            553
##   United.States...all.industrial New.England...all.sectors
## 1                          13128                     10005
## 2                          11421                      8662
## 3                          12454                      9506
##   New.England...electric.utility New.England...independent.power.producers
## 1                           2467                                      6959
## 2                           2289                                      5873
## 3                           2061                                      6882
##   New.England...all.commercial New.England...all.industrial
## 1                           68                          510
## 2                           65                          435
## 3                           70                          493
##   Connecticut...all.sectors Connecticut...electric.utility
## 1                      2930                           1411
## 2                      1853                            661
## 3                      2386                            695
##   Connecticut...independent.power.producers Connecticut...all.commercial
## 1                                      1503                            2
## 2                                      1178                            2
## 3                                      1673                            3
##   Connecticut...all.industrial Maine...all.sectors Maine...electric.utility
## 1                           14                1648                       --
## 2                           11                1463                       --
## 3                           16                1503                       --
##   Maine...independent.power.producers Maine...all.commercial
## 1                                1213                     12
## 2                                1092                     13
## 3                                1088                     12
##   Maine...all.industrial Massachusetts...all.sectors
## 1                    424                        3802
## 2                    358                        3146
## 3                    404                        3597
##   Massachusetts...electric.utility Massachusetts...independent.power.producers
## 1                              146                                        3571
## 2                               97                                        2969
## 3                              167                                        3343
##   Massachusetts...all.commercial Massachusetts...all.industrial
## 1                             47                             38
## 2                             45                             34
## 3                             49                             38
##   New.Hampshire...all.sectors New.Hampshire...electric.utility
## 1                         652                              446
## 2                        1280                             1123
## 3                         958                              795
##   New.Hampshire...independent.power.producers New.Hampshire...all.commercial
## 1                                         173                              4
## 2                                         126                              3
## 3                                         128                              3
##   New.Hampshire...all.industrial Rhode.Island...all.sectors
## 1                             30                        424
## 2                             28                        444
## 3                             33                        590
##   Rhode.Island...electric.utility Rhode.Island...independent.power.producers
## 1                              --                                        420
## 2                              --                                        440
## 3                              --                                        585
##   Rhode.Island...all.commercial Rhode.Island...all.industrial
## 1                             3                             0
## 2                             3                             0
## 3                             4                             0
##   Vermont...all.sectors Vermont...electric.utility
## 1                   548                        464
## 2                   478                        407
## 3                   472                        404
##   Vermont...independent.power.producers Vermont...all.commercial
## 1                                    80                       --
## 2                                    68                       --
## 3                                    64                       --
##   Vermont...all.industrial Middle.Atlantic...all.sectors
## 1                        4                         36792
## 2                        3                         31219
## 3                        3                         33903
##   Middle.Atlantic...electric.utility
## 1                               8428
## 2                               7254
## 3                               8014
##   Middle.Atlantic...independent.power.producers
## 1                                         27519
## 2                                         23202
## 3                                         25048
##   Middle.Atlantic...all.commercial Middle.Atlantic...all.industrial
## 1                              100                              745
## 2                               87                              676
## 3                               87                              753
##   New.Jersey...all.sectors New.Jersey...electric.utility
## 1                     5306                           195
## 2                     4706                           146
## 3                     4947                           122
##   New.Jersey...independent.power.producers New.Jersey...all.commercial
## 1                                     4815                          14
## 2                                     4290                          13
## 3                                     4547                          14
##   New.Jersey...all.industrial New.York...all.sectors
## 1                         282                  12622
## 2                         257                  11460
## 3                         265                  12115
##   New.York...electric.utility New.York...independent.power.producers
## 1                        5795                                   6606
## 2                        4891                                   6370
## 3                        5373                                   6524
##   New.York...all.commercial New.York...all.industrial
## 1                        48                       173
## 2                        43                       155
## 3                        46                       171
##   Pennsylvania...all.sectors Pennsylvania...electric.utility
## 1                      18864                            2437
## 2                      15053                            2217
## 3                      16841                            2520
##   Pennsylvania...independent.power.producers Pennsylvania...all.commercial
## 1                                      16098                            38
## 2                                      12542                            31
## 3                                      13978                            27
##   Pennsylvania...all.industrial East.North.Central...all.sectors
## 1                           290                            55695
## 2                           264                            48200
## 3                           317                            51377
##   East.North.Central...electric.utility
## 1                                 39970
## 2                                 34347
## 3                                 36133
##   East.North.Central...independent.power.producers
## 1                                            14658
## 2                                            12900
## 3                                            14193
##   East.North.Central...all.commercial East.North.Central...all.industrial
## 1                                  74                                 994
## 2                                  67                                 886
## 3                                  71                                 981
##   Illinois...all.sectors Illinois...electric.utility
## 1                  16039                        2854
## 2                  13914                        2378
## 3                  14882                        2239
##   Illinois...independent.power.producers Illinois...all.commercial
## 1                                  12923                        21
## 2                                  11319                        19
## 3                                  12393                        20
##   Illinois...all.industrial Indiana...all.sectors Indiana...electric.utility
## 1                       241                 10947                      10335
## 2                       198                  9661                       9051
## 3                       230                  9951                       9320
##   Indiana...independent.power.producers Indiana...all.commercial
## 1                                   304                       19
## 2                                   301                       18
## 3                                   289                       16
##   Indiana...all.industrial Michigan...all.sectors Michigan...electric.utility
## 1                      289                  10183                        9154
## 2                      291                   8871                        7933
## 3                      326                   9681                        8610
##   Michigan...independent.power.producers Michigan...all.commercial
## 1                                    877                        19
## 2                                    813                        17
## 3                                    926                        20
##   Michigan...all.industrial Ohio...all.sectors Ohio...electric.utility
## 1                       133              13163                   12531
## 2                       107              11162                   10669
## 3                       125              12108                   11545
##   Ohio...independent.power.producers Ohio...all.commercial
## 1                                512                     2
## 2                                395                     1
## 3                                458                     2
##   Ohio...all.industrial Wisconsin...all.sectors Wisconsin...electric.utility
## 1                   118                    5364                         5097
## 2                    97                    4594                         4316
## 3                   103                    4755                         4419
##   Wisconsin...independent.power.producers Wisconsin...all.commercial
## 1                                      41                         13
## 2                                      73                         11
## 3                                     127                         13
##   Wisconsin...all.industrial West.North.Central...all.sectors
## 1                        213                            25600
## 2                        194                            22084
## 3                        197                            22011
##   West.North.Central...electric.utility
## 1                                 25026
## 2                                 21578
## 3                                 21506
##   West.North.Central...independent.power.producers
## 1                                              238
## 2                                              204
## 3                                              180
##   West.North.Central...all.commercial West.North.Central...all.industrial
## 1                                  36                                 300
## 2                                  33                                 269
## 3                                  32                                 293
##   Iowa...all.sectors Iowa...electric.utility Iowa...independent.power.producers
## 1               3761                    3590                                 59
## 2               3244                    3095                                 47
## 3               3576                    3419                                 52
##   Iowa...all.commercial Iowa...all.industrial Kansas...all.sectors
## 1                    13                    99                 4108
## 2                    12                    90                 3274
## 3                    10                    96                 3340
##   Kansas...electric.utility Kansas...independent.power.producers
## 1                      4105                                   --
## 2                      3271                                   --
## 3                      3336                                   --
##   Kansas...all.commercial Kansas...all.industrial Minnesota...all.sectors
## 1                       0                       3                    4333
## 2                       0                       3                    3840
## 3                       0                       3                    3663
##   Minnesota...electric.utility Minnesota...independent.power.producers
## 1                         3984                                     178
## 2                         3531                                     157
## 3                         3371                                     128
##   Minnesota...all.commercial Minnesota...all.industrial Missouri...all.sectors
## 1                         12                        158                   7120
## 2                         11                        142                   6216
## 3                         11                        153                   5891
##   Missouri...electric.utility Missouri...independent.power.producers
## 1                        7092                                     --
## 2                        6189                                     --
## 3                        5864                                      0
##   Missouri...all.commercial Missouri...all.industrial Nebraska...all.sectors
## 1                         9                        20                   2899
## 2                         8                        18                   2425
## 3                        10                        17                   2250
##   Nebraska...electric.utility Nebraska...independent.power.producers
## 1                        2893                                      1
## 2                        2418                                      1
## 3                        2243                                      1
##   Nebraska...all.commercial Nebraska...all.industrial
## 1                         2                         4
## 2                         2                         5
## 3                         1                         5
##   North.Dakota...all.sectors North.Dakota...electric.utility
## 1                       2751                            2734
## 2                       2514                            2502
## 3                       2690                            2670
##   North.Dakota...independent.power.producers North.Dakota...all.commercial
## 1                                         --                            --
## 2                                         --                            --
## 3                                         --                            --
##   North.Dakota...all.industrial South.Dakota...all.sectors
## 1                            16                        628
## 2                            12                        572
## 3                            20                        601
##   South.Dakota...electric.utility South.Dakota...independent.power.producers
## 1                             628                                         --
## 2                             572                                         --
## 3                             601                                         --
##   South.Dakota...all.commercial South.Dakota...all.industrial
## 1                            --                            --
## 2                            --                            --
## 3                            --                            --
##   South.Atlantic...all.sectors South.Atlantic...electric.utility
## 1                        67187                             54761
## 2                        54571                             43905
## 3                        58511                             48419
##   South.Atlantic...independent.power.producers South.Atlantic...all.commercial
## 1                                        10533                              93
## 2                                         9051                              54
## 3                                         8371                              51
##   South.Atlantic...all.industrial Delaware...all.sectors
## 1                            1799                    626
## 2                            1561                    521
## 3                            1670                    867
##   Delaware...electric.utility Delaware...independent.power.producers
## 1                         373                                    205
## 2                         332                                    150
## 3                         330                                    481
##   Delaware...all.commercial Delaware...all.industrial
## 1                        --                        48
## 2                        --                        39
## 3                        --                        55
##   District.Of.Columbia...all.sectors District.Of.Columbia...electric.utility
## 1                                  9                                      --
## 2                                  0                                      --
## 3                                  0                                      --
##   District.Of.Columbia...independent.power.producers
## 1                                                  9
## 2                                                  0
## 3                                                  0
##   District.Of.Columbia...all.commercial District.Of.Columbia...all.industrial
## 1                                    --                                    --
## 2                                    --                                    --
## 3                                    --                                    --
##   Florida...all.sectors Florida...electric.utility
## 1                 16937                      15251
## 2                 12761                      11369
## 3                 14115                      12555
##   Florida...independent.power.producers Florida...all.commercial
## 1                                  1257                       10
## 2                                  1010                        8
## 3                                  1165                        9
##   Florida...all.industrial Georgia...all.sectors Georgia...electric.utility
## 1                      419                 11084                      10510
## 2                      375                  8332                       7825
## 3                      386                  9844                       9345
##   Georgia...independent.power.producers Georgia...all.commercial
## 1                                    70                        0
## 2                                    54                        0
## 3                                    43                        0
##   Georgia...all.industrial Maryland...all.sectors Maryland...electric.utility
## 1                      504                   4603                          19
## 2                      452                   4182                           1
## 3                      456                   3597                          51
##   Maryland...independent.power.producers Maryland...all.commercial
## 1                                   4576                         3
## 2                                   4174                         2
## 3                                   3539                         2
##   Maryland...all.industrial North.Carolina...all.sectors
## 1                         5                        10512
## 2                         5                         8862
## 3                         5                         9303
##   North.Carolina...electric.utility
## 1                              9839
## 2                              8284
## 3                              8643
##   North.Carolina...independent.power.producers North.Carolina...all.commercial
## 1                                          356                              14
## 2                                          298                              11
## 3                                          315                               8
##   North.Carolina...all.industrial South.Carolina...all.sectors
## 1                             303                         7646
## 2                             270                         6638
## 3                             338                         7385
##   South.Carolina...electric.utility
## 1                              7432
## 2                              6484
## 3                              7231
##   South.Carolina...independent.power.producers South.Carolina...all.commercial
## 1                                           46                               5
## 2                                           45                               4
## 3                                           42                               5
##   South.Carolina...all.industrial Virginia...all.sectors
## 1                             162                   7117
## 2                             104                   5894
## 3                             108                   6358
##   Virginia...electric.utility Virginia...independent.power.producers
## 1                        5826                                   1013
## 2                        4906                                    784
## 3                        5288                                    870
##   Virginia...all.commercial Virginia...all.industrial
## 1                        62                       216
## 2                        28                       177
## 3                        27                       173
##   West.Virginia...all.sectors West.Virginia...electric.utility
## 1                        8653                             5512
## 2                        7381                             4704
## 3                        7041                             4976
##   West.Virginia...independent.power.producers West.Virginia...all.commercial
## 1                                        2999                             --
## 2                                        2537                             --
## 3                                        1915                             --
##   West.Virginia...all.industrial East.South.Central...all.sectors
## 1                            143                            32115
## 2                            140                            27307
## 3                            150                            29402
##   East.South.Central...electric.utility
## 1                                 29979
## 2                                 25454
## 3                                 27369
##   East.South.Central...independent.power.producers
## 1                                             1102
## 2                                             1031
## 3                                             1167
##   East.South.Central...all.commercial East.South.Central...all.industrial
## 1                                   9                                1025
## 2                                   9                                 813
## 3                                   9                                 856
##   Alabama...all.sectors Alabama...electric.utility
## 1                 11327                      10695
## 2                  9576                       9070
## 3                  9364                       8829
##   Alabama...independent.power.producers Alabama...all.commercial
## 1                                    48                       --
## 2                                    45                       --
## 3                                    47                       --
##   Alabama...all.industrial Kentucky...all.sectors Kentucky...electric.utility
## 1                      583                   8118                        7058
## 2                      461                   7534                        6562
## 3                      489                   8202                        7208
##   Kentucky...independent.power.producers Kentucky...all.commercial
## 1                                   1043                        --
## 2                                    956                        --
## 3                                    977                        --
##   Kentucky...all.industrial Mississippi...all.sectors
## 1                        18                      3564
## 2                        16                      2743
## 3                        16                      3643
##   Mississippi...electric.utility Mississippi...independent.power.producers
## 1                           3376                                         8
## 2                           2578                                        28
## 3                           3371                                       141
##   Mississippi...all.commercial Mississippi...all.industrial
## 1                            1                          179
## 2                            1                          136
## 3                            1                          130
##   Tennessee...all.sectors Tennessee...electric.utility
## 1                    9106                         8851
## 2                    7454                         7244
## 3                    8193                         7961
##   Tennessee...independent.power.producers Tennessee...all.commercial
## 1                                       2                          8
## 2                                       2                          9
## 3                                       2                          8
##   Tennessee...all.industrial West.South.Central...all.sectors
## 1                        245                            46990
## 2                        200                            39136
## 3                        221                            40834
##   West.South.Central...electric.utility
## 1                                 34843
## 2                                 28424
## 3                                 29355
##   West.South.Central...independent.power.producers
## 1                                             6424
## 2                                             5604
## 3                                             5892
##   West.South.Central...all.commercial West.South.Central...all.industrial
## 1                                  41                                5684
## 2                                  36                                5072
## 3                                  41                                5546
##   Arkansas...all.sectors Arkansas...electric.utility
## 1                   3903                        3704
## 2                   3372                        3200
## 3                   3125                        2958
##   Arkansas...independent.power.producers Arkansas...all.commercial
## 1                                      0                         1
## 2                                      0                         1
## 3                                      0                         1
##   Arkansas...all.industrial Louisiana...all.sectors
## 1                       199                    7595
## 2                       171                    6105
## 3                       166                    6321
##   Louisiana...electric.utility Louisiana...independent.power.producers
## 1                         4599                                    1158
## 2                         3175                                    1184
## 3                         3348                                    1145
##   Louisiana...all.commercial Louisiana...all.industrial Oklahoma...all.sectors
## 1                          2                       1837                   4491
## 2                          2                       1744                   4033
## 3                          2                       1826                   3808
##   Oklahoma...electric.utility Oklahoma...independent.power.producers
## 1                        4090                                    287
## 2                        3691                                    242
## 3                        3568                                    151
##   Oklahoma...all.commercial Oklahoma...all.industrial Texas...all.sectors
## 1                         2                       112               31001
## 2                         2                        98               25627
## 3                         2                        87               27580
##   Texas...electric.utility Texas...independent.power.producers
## 1                    22450                                4979
## 2                    18357                                4178
## 3                    19482                                4596
##   Texas...all.commercial Texas...all.industrial Mountain...all.sectors
## 1                     36                   3537                  27506
## 2                     32                   3059                  25227
## 3                     36                   3466                  25870
##   Mountain...electric.utility Mountain...independent.power.producers
## 1                       24203                                   3050
## 2                       22107                                   2881
## 3                       22859                                   2748
##   Mountain...all.commercial Mountain...all.industrial Arizona...all.sectors
## 1                        25                       229                  7574
## 2                        25                       215                  6617
## 3                        29                       234                  7326
##   Arizona...electric.utility Arizona...independent.power.producers
## 1                       7499                                    41
## 2                       6547                                    37
## 3                       7252                                    41
##   Arizona...all.commercial Arizona...all.industrial Colorado...all.sectors
## 1                        2                       33                   4163
## 2                        1                       31                   3777
## 3                        2                       31                   3842
##   Colorado...electric.utility Colorado...independent.power.producers
## 1                        3664                                    477
## 2                        3281                                    473
## 3                        3344                                    470
##   Colorado...all.commercial Colorado...all.industrial Idaho...all.sectors
## 1                        17                         6                 605
## 2                        17                         6                 503
## 3                        20                         7                 595
##   Idaho...electric.utility Idaho...independent.power.producers
## 1                      505                                  35
## 2                      410                                  33
## 3                      486                                  39
##   Idaho...all.commercial Idaho...all.industrial Montana...all.sectors
## 1                     --                     65                  2301
## 2                     --                     60                  2105
## 3                     --                     71                  1921
##   Montana...electric.utility Montana...independent.power.producers
## 1                        453                                  1841
## 2                        459                                  1639
## 3                        310                                  1604
##   Montana...all.commercial Montana...all.industrial Nevada...all.sectors
## 1                       --                        7                 2966
## 2                       --                        7                 2969
## 3                       --                        7                 3040
##   Nevada...electric.utility Nevada...independent.power.producers
## 1                      2461                                  504
## 2                      2417                                  552
## 3                      2596                                  444
##   Nevada...all.commercial Nevada...all.industrial New.Mexico...all.sectors
## 1                      --                      --                     2919
## 2                      --                      --                     2713
## 3                      --                      --                     2617
##   New.Mexico...electric.utility New.Mexico...independent.power.producers
## 1                          2787                                       93
## 2                          2578                                       95
## 3                          2484                                       90
##   New.Mexico...all.commercial New.Mexico...all.industrial Utah...all.sectors
## 1                           5                          34               2957
## 2                           5                          35               2796
## 3                           5                          38               2435
##   Utah...electric.utility Utah...independent.power.producers
## 1                    2899                                 35
## 2                    2742                                 31
## 3                    2369                                 39
##   Utah...all.commercial Utah...all.industrial Wyoming...all.sectors
## 1                     1                    23                  4021
## 2                     1                    22                  3747
## 3                     1                    27                  4093
##   Wyoming...electric.utility Wyoming...independent.power.producers
## 1                       3935                                    24
## 2                       3673                                    21
## 3                       4020                                    21
##   Wyoming...all.commercial Wyoming...all.industrial
## 1                       --                       61
## 2                       --                       53
## 3                       --                       53
##   Pacific.Contiguous...all.sectors Pacific.Contiguous...electric.utility
## 1                            29087                                 15774
## 2                            25186                                 13566
## 3                            27833                                 15194
##   Pacific.Contiguous...independent.power.producers
## 1                                            11446
## 2                                            10106
## 3                                            10999
##   Pacific.Contiguous...all.commercial Pacific.Contiguous...all.industrial
## 1                                 173                                1694
## 2                                 154                                1360
## 3                                 146                                1494
##   California...all.sectors California...electric.utility
## 1                    16619                          5187
## 2                    14380                          4415
## 3                    15849                          5119
##   California...independent.power.producers California...all.commercial
## 1                                     9798                         163
## 2                                     8603                         145
## 3                                     9301                         136
##   California...all.industrial Oregon...all.sectors Oregon...electric.utility
## 1                        1470                 4150                      3658
## 2                        1217                 3718                      3309
## 3                        1293                 4209                      3714
##   Oregon...independent.power.producers Oregon...all.commercial
## 1                                  398                       1
## 2                                  367                       1
## 3                                  407                       1
##   Oregon...all.industrial Washington...all.sectors
## 1                      94                     8318
## 2                      41                     7088
## 3                      86                     7776
##   Washington...electric.utility Washington...independent.power.producers
## 1                          6929                                     1250
## 2                          5842                                     1136
## 3                          6360                                     1291
##   Washington...all.commercial Washington...all.industrial
## 1                           9                         131
## 2                           8                         102
## 3                           9                         115
##   Pacific.Noncontiguous...all.sectors Pacific.Noncontiguous...electric.utility
## 1                                1515                                     1017
## 2                                1347                                      880
## 3                                1460                                     1032
##   Pacific.Noncontiguous...independent.power.producers
## 1                                                 340
## 2                                                 315
## 3                                                 276
##   Pacific.Noncontiguous...all.commercial Pacific.Noncontiguous...all.industrial
## 1                                     10                                    148
## 2                                     18                                    134
## 3                                     18                                    134
##   Alaska...all.sectors Alaska...electric.utility
## 1                  590                       493
## 2                  546                       423
## 3                  587                       459
##   Alaska...independent.power.producers Alaska...all.commercial
## 1                                   20                      10
## 2                                   22                      18
## 3                                   23                      18
##   Alaska...all.industrial Hawaii...all.sectors Hawaii...electric.utility
## 1                      67                  925                       524
## 2                      84                  801                       457
## 3                      88                  873                       573
##   Hawaii...independent.power.producers Hawaii...all.commercial
## 1                                  320                      --
## 2                                  293                      --
## 3                                  254                      --
##   Hawaii...all.industrial
## 1                      81
## 2                      51
## 3                      46
Energy |> tail(3)
##              X United.States...all.sectors United.States...electric.utility
## 253 2022-01-01                      378967                           205875
## 254 2022-02-01                      327767                           172436
## 255 2022-03-01                      325952                           166277
##     United.States...independent.power.producers United.States...all.commercial
## 253                                      159328                           1203
## 254                                      143311                           1033
## 255                                      146938                           1054
##     United.States...all.industrial New.England...all.sectors
## 253                          12560                      9739
## 254                          10987                      8065
## 255                          11684                      8570
##     New.England...electric.utility New.England...independent.power.producers
## 253                            363                                      9041
## 254                            243                                      7513
## 255                            179                                      8081
##     New.England...all.commercial New.England...all.industrial
## 253                          107                          228
## 254                          100                          209
## 255                           99                          211
##     Connecticut...all.sectors Connecticut...electric.utility
## 253                      3619                              7
## 254                      3336                              8
## 255                      3735                              9
##     Connecticut...independent.power.producers Connecticut...all.commercial
## 253                                      3535                           28
## 254                                      3256                           27
## 255                                      3653                           26
##     Connecticut...all.industrial Maine...all.sectors Maine...electric.utility
## 253                           49                1227                       NM
## 254                           46                 984                       NM
## 255                           48                1091                       NM
##     Maine...independent.power.producers Maine...all.commercial
## 253                                1068                     11
## 254                                 841                     10
## 255                                 949                     10
##     Maine...all.industrial Massachusetts...all.sectors
## 253                    148                        2251
## 254                    132                        1584
## 255                    131                        1497
##     Massachusetts...electric.utility
## 253                               NM
## 254                               29
## 255                               35
##     Massachusetts...independent.power.producers Massachusetts...all.commercial
## 253                                        2134                             56
## 254                                        1487                             52
## 255                                        1397                             48
##     Massachusetts...all.industrial New.Hampshire...all.sectors
## 253                             17                        1812
## 254                             17                        1397
## 255                             17                        1463
##     New.Hampshire...electric.utility
## 253                              218
## 254                              114
## 255                               38
##     New.Hampshire...independent.power.producers New.Hampshire...all.commercial
## 253                                        1585                              7
## 254                                        1275                              6
## 255                                        1416                              6
##     New.Hampshire...all.industrial Rhode.Island...all.sectors
## 253                              2                        634
## 254                              2                        566
## 255                              3                        558
##     Rhode.Island...electric.utility Rhode.Island...independent.power.producers
## 253                               0                                        617
## 254                               0                                        549
## 255                               0                                        538
##     Rhode.Island...all.commercial Rhode.Island...all.industrial
## 253                             5                            NM
## 254                            NM                            12
## 255                             9                            NM
##     Vermont...all.sectors Vermont...electric.utility
## 253                   195                         93
## 254                   197                         93
## 255                   226                         98
##     Vermont...independent.power.producers Vermont...all.commercial
## 253                                   102                        0
## 254                                   104                        0
## 255                                   128                        0
##     Vermont...all.industrial Middle.Atlantic...all.sectors
## 253                       --                         39233
## 254                       --                         34871
## 255                       --                         34851
##     Middle.Atlantic...electric.utility
## 253                               3312
## 254                               2723
## 255                               2947
##     Middle.Atlantic...independent.power.producers
## 253                                         35274
## 254                                         31549
## 255                                         31262
##     Middle.Atlantic...all.commercial Middle.Atlantic...all.industrial
## 253                              214                              434
## 254                              175                              425
## 255                              197                              445
##     New.Jersey...all.sectors New.Jersey...electric.utility
## 253                     4742                             1
## 254                     4743                             6
## 255                     5046                            12
##     New.Jersey...independent.power.producers New.Jersey...all.commercial
## 253                                     4638                          60
## 254                                     4653                          47
## 255                                     4937                          58
##     New.Jersey...all.industrial New.York...all.sectors
## 253                          43                  11198
## 254                          37                   9441
## 255                          39                   8999
##     New.York...electric.utility New.York...independent.power.producers
## 253                        3301                                   7706
## 254                        2708                                   6558
## 255                        2922                                   5896
##     New.York...all.commercial New.York...all.industrial
## 253                        NM                        78
## 254                        96                        79
## 255                       104                        77
##     Pennsylvania...all.sectors Pennsylvania...electric.utility
## 253                      23293                              10
## 254                      20687                               8
## 255                      20806                              13
##     Pennsylvania...independent.power.producers Pennsylvania...all.commercial
## 253                                      22930                            41
## 254                                      20338                            31
## 255                                      20428                            35
##     Pennsylvania...all.industrial East.North.Central...all.sectors
## 253                           312                            56998
## 254                           309                            49234
## 255                           329                            46990
##     East.North.Central...electric.utility
## 253                                 19855
## 254                                 16596
## 255                                 14549
##     East.North.Central...independent.power.producers
## 253                                            36049
## 254                                            31662
## 255                                            31393
##     East.North.Central...all.commercial East.North.Central...all.industrial
## 253                                 161                                 933
## 254                                 124                                 852
## 255                                 130                                 918
##     Illinois...all.sectors Illinois...electric.utility
## 253                  17542                         527
## 254                  15237                         244
## 255                  15374                         195
##     Illinois...independent.power.producers Illinois...all.commercial
## 253                                  16764                        42
## 254                                  14755                        29
## 255                                  14926                        24
##     Illinois...all.industrial Indiana...all.sectors Indiana...electric.utility
## 253                       209                  9078                       5688
## 254                       209                  8345                       5194
## 255                       229                  7391                       4316
##     Indiana...independent.power.producers Indiana...all.commercial
## 253                                  2990                       23
## 254                                  2802                       10
## 255                                  2683                       20
##     Indiana...all.industrial Michigan...all.sectors Michigan...electric.utility
## 253                      377                  10820                        7278
## 254                      340                   8602                        5512
## 255                      372                   8487                        5323
##     Michigan...independent.power.producers Michigan...all.commercial
## 253                                   3351                        65
## 254                                   2922                        58
## 255                                   2993                        55
##     Michigan...all.industrial Ohio...all.sectors Ohio...electric.utility
## 253                       125              13310                    1350
## 254                       111              11480                    1189
## 255                       116              10943                    1053
##     Ohio...independent.power.producers Ohio...all.commercial
## 253                              11868                    18
## 254                              10206                    17
## 255                               9802                    18
##     Ohio...all.industrial Wisconsin...all.sectors Wisconsin...electric.utility
## 253                    75                    6249                         5013
## 254                    70                    5569                         4457
## 255                    70                    4795                         3662
##     Wisconsin...independent.power.producers Wisconsin...all.commercial
## 253                                    1077                         13
## 254                                     978                         11
## 255                                     990                         12
##     Wisconsin...all.industrial West.North.Central...all.sectors
## 253                        147                            36145
## 254                        124                            31809
## 255                        131                            31919
##     West.North.Central...electric.utility
## 253                                 27109
## 254                                 23085
## 255                                 22270
##     West.North.Central...independent.power.producers
## 253                                             8639
## 254                                             8372
## 255                                             9262
##     West.North.Central...all.commercial West.North.Central...all.industrial
## 253                                  68                                 330
## 254                                  57                                 296
## 255                                  56                                 331
##     Iowa...all.sectors Iowa...electric.utility
## 253               6596                    5277
## 254               6014                    4788
## 255               5997                    4691
##     Iowa...independent.power.producers Iowa...all.commercial
## 253                               1128                    17
## 254                               1063                    11
## 255                               1115                    17
##     Iowa...all.industrial Kansas...all.sectors Kansas...electric.utility
## 253                   174                 5464                      3088
## 254                   151                 5099                      2674
## 255                   174                 5240                      2471
##     Kansas...independent.power.producers Kansas...all.commercial
## 253                                 2364                      NM
## 254                                 2413                      NM
## 255                                 2756                      NM
##     Kansas...all.industrial Minnesota...all.sectors
## 253                      11                    6256
## 254                      11                    5205
## 255                      11                    4879
##     Minnesota...electric.utility Minnesota...independent.power.producers
## 253                         4558                                    1583
## 254                         3705                                    1391
## 255                         3317                                    1453
##     Minnesota...all.commercial Minnesota...all.industrial
## 253                         31                         84
## 254                         28                         82
## 255                         20                         88
##     Missouri...all.sectors Missouri...electric.utility
## 253                   7970                        7229
## 254                   6631                        5949
## 255                   6588                        5893
##     Missouri...independent.power.producers Missouri...all.commercial
## 253                                    718                        17
## 254                                    663                        15
## 255                                    674                        16
##     Missouri...all.industrial Nebraska...all.sectors
## 253                         6                   3680
## 254                         5                   3368
## 255                         5                   3458
##     Nebraska...electric.utility Nebraska...independent.power.producers
## 253                        2575                                   1065
## 254                        2267                                   1067
## 255                        2136                                   1283
##     Nebraska...all.commercial Nebraska...all.industrial
## 253                         2                        38
## 254                         2                        32
## 255                         2                        37
##     North.Dakota...all.sectors North.Dakota...electric.utility
## 253                       4378                            3368
## 254                       3800                            2821
## 255                       3916                            2839
##     North.Dakota...independent.power.producers North.Dakota...all.commercial
## 253                                        996                             0
## 254                                        966                             0
## 255                                       1064                             0
##     North.Dakota...all.industrial South.Dakota...all.sectors
## 253                            NM                       1800
## 254                            NM                       1692
## 255                            13                       1841
##     South.Dakota...electric.utility South.Dakota...independent.power.producers
## 253                            1014                                        784
## 254                             881                                        809
## 255                             923                                        916
##     South.Dakota...all.commercial South.Dakota...all.industrial
## 253                            NM                            NM
## 254                            NM                            NM
## 255                            NM                            NM
##     South.Atlantic...all.sectors South.Atlantic...electric.utility
## 253                        72042                             59865
## 254                        58834                             48772
## 255                        59886                             48382
##     South.Atlantic...independent.power.producers
## 253                                        10472
## 254                                         8552
## 255                                         9942
##     South.Atlantic...all.commercial South.Atlantic...all.industrial
## 253                             183                            1522
## 254                             163                            1347
## 255                             125                            1437
##     Delaware...all.sectors Delaware...electric.utility
## 253                    300                           3
## 254                    294                           2
## 255                    206                           2
##     Delaware...independent.power.producers Delaware...all.commercial
## 253                                    230                         1
## 254                                    239                         1
## 255                                    131                         1
##     Delaware...all.industrial District.Of.Columbia...all.sectors
## 253                        66                                 14
## 254                        53                                 13
## 255                        72                                 19
##     District.Of.Columbia...electric.utility
## 253                                      --
## 254                                      --
## 255                                      --
##     District.Of.Columbia...independent.power.producers
## 253                                                 NM
## 254                                                  2
## 255                                                  2
##     District.Of.Columbia...all.commercial District.Of.Columbia...all.industrial
## 253                                    13                                    --
## 254                                    11                                    --
## 255                                    16                                    --
##     Florida...all.sectors Florida...electric.utility
## 253                 19566                      18127
## 254                 17317                      16054
## 255                 18893                      17567
##     Florida...independent.power.producers Florida...all.commercial
## 253                                  1007                       37
## 254                                   886                       30
## 255                                   904                       31
##     Florida...all.industrial Georgia...all.sectors Georgia...electric.utility
## 253                      395                 11457                       9373
## 254                      347                  9216                       7412
## 255                      391                  9228                       7412
##     Georgia...independent.power.producers Georgia...all.commercial
## 253                                  1640                       NM
## 254                                  1407                       NM
## 255                                  1389                       NM
##     Georgia...all.industrial Maryland...all.sectors Maryland...electric.utility
## 253                      444                   3434                         193
## 254                      398                   2192                         250
## 255                      427                   3149                         395
##     Maryland...independent.power.producers Maryland...all.commercial
## 253                                   3151                        86
## 254                                   1860                        78
## 255                                   2720                        29
##     Maryland...all.industrial North.Carolina...all.sectors
## 253                         4                        13047
## 254                         4                        10552
## 255                         6                         9595
##     North.Carolina...electric.utility
## 253                             11470
## 254                              8963
## 255                              7874
##     North.Carolina...independent.power.producers
## 253                                         1397
## 254                                         1423
## 255                                         1564
##     North.Carolina...all.commercial North.Carolina...all.industrial
## 253                              25                             155
## 254                              21                             145
## 255                              20                             137
##     South.Carolina...all.sectors South.Carolina...electric.utility
## 253                         9109                              8688
## 254                         7254                              6846
## 255                         8280                              7815
##     South.Carolina...independent.power.producers
## 253                                          266
## 254                                          278
## 255                                          336
##     South.Carolina...all.commercial South.Carolina...all.industrial
## 253                               0                             155
## 254                               0                             131
## 255                               0                             129
##     Virginia...all.sectors Virginia...electric.utility
## 253                   8338                        6885
## 254                   7230                        5929
## 255                   7125                        5457
##     Virginia...independent.power.producers Virginia...all.commercial
## 253                                   1237                        22
## 254                                   1100                        20
## 255                                   1465                        28
##     Virginia...all.industrial West.Virginia...all.sectors
## 253                       194                        6777
## 254                       182                        4766
## 255                       176                        3392
##     West.Virginia...electric.utility
## 253                             5126
## 254                             3319
## 255                             1862
##     West.Virginia...independent.power.producers West.Virginia...all.commercial
## 253                                        1543                             --
## 254                                        1358                             --
## 255                                        1431                             --
##     West.Virginia...all.industrial East.South.Central...all.sectors
## 253                            108                            34609
## 254                             89                            28501
## 255                             99                            27058
##     East.South.Central...electric.utility
## 253                                 30077
## 254                                 25047
## 255                                 23226
##     East.South.Central...independent.power.producers
## 253                                             3731
## 254                                             2752
## 255                                             3063
##     East.South.Central...all.commercial East.South.Central...all.industrial
## 253                                  19                                 781
## 254                                  15                                 687
## 255                                  19                                 750
##     Alabama...all.sectors Alabama...electric.utility
## 253                 13000                       9295
## 254                 11088                       8313
## 255                 11055                       7982
##     Alabama...independent.power.producers Alabama...all.commercial
## 253                                  3327                       --
## 254                                  2414                       --
## 255                                  2692                       --
##     Alabama...all.industrial Kentucky...all.sectors Kentucky...electric.utility
## 253                      377                   6918                        6700
## 254                      360                   5486                        5410
## 255                      380                   4982                        4931
##     Kentucky...independent.power.producers Kentucky...all.commercial
## 253                                    173                        --
## 254                                     36                        --
## 255                                     10                        --
##     Kentucky...all.industrial Mississippi...all.sectors
## 253                        45                      6643
## 254                        40                      5157
## 255                        41                      4420
##     Mississippi...electric.utility Mississippi...independent.power.producers
## 253                           6272                                       198
## 254                           4751                                       268
## 255                           3952                                       303
##     Mississippi...all.commercial Mississippi...all.industrial
## 253                            0                          173
## 254                            0                          139
## 255                            0                          164
##     Tennessee...all.sectors Tennessee...electric.utility
## 253                    8049                         7810
## 254                    6770                         6573
## 255                    6601                         6360
##     Tennessee...independent.power.producers Tennessee...all.commercial
## 253                                      33                         19
## 254                                      34                         15
## 255                                      58                         19
##     Tennessee...all.industrial West.South.Central...all.sectors
## 253                        186                            64818
## 254                        148                            58264
## 255                        164                            56128
##     West.South.Central...electric.utility
## 253                                 21629
## 254                                 18557
## 255                                 16719
##     West.South.Central...independent.power.producers
## 253                                            36354
## 254                                            33882
## 255                                            33331
##     West.South.Central...all.commercial West.South.Central...all.industrial
## 253                                  65                                6771
## 254                                  60                                5765
## 255                                  59                                6019
##     Arkansas...all.sectors Arkansas...electric.utility
## 253                   6340                        5595
## 254                   5031                        4364
## 255                   5343                        4651
##     Arkansas...independent.power.producers Arkansas...all.commercial
## 253                                    629                        NM
## 254                                    558                        NM
## 255                                    581                        NM
##     Arkansas...all.industrial Louisiana...all.sectors
## 253                       110                    9333
## 254                       104                    8100
## 255                       108                    7615
##     Louisiana...electric.utility Louisiana...independent.power.producers
## 253                         5920                                     677
## 254                         5072                                     663
## 255                         4772                                     330
##     Louisiana...all.commercial Louisiana...all.industrial
## 253                         15                       2721
## 254                         14                       2350
## 255                         15                       2498
##     Oklahoma...all.sectors Oklahoma...electric.utility
## 253                   6946                        3103
## 254                   6515                        2701
## 255                   6188                        2139
##     Oklahoma...independent.power.producers Oklahoma...all.commercial
## 253                                   3762                         0
## 254                                   3741                         0
## 255                                   3969                         0
##     Oklahoma...all.industrial Texas...all.sectors Texas...electric.utility
## 253                        81               42199                     7010
## 254                        73               38619                     6420
## 255                        80               36982                     5157
##     Texas...independent.power.producers Texas...all.commercial
## 253                               31286                     45
## 254                               28919                     41
## 255                               28451                     41
##     Texas...all.industrial Mountain...all.sectors Mountain...electric.utility
## 253                   3858                  31345                       22582
## 254                   3238                  27720                       19431
## 255                   3334                  28702                       19856
##     Mountain...independent.power.producers Mountain...all.commercial
## 253                                   8401                       106
## 254                                   7975                        94
## 255                                   8498                        97
##     Mountain...all.industrial Arizona...all.sectors Arizona...electric.utility
## 253                       256                  7739                       6421
## 254                       221                  7211                       5756
## 255                       252                  7705                       6221
##     Arizona...independent.power.producers Arizona...all.commercial
## 253                                  1306                       13
## 254                                  1444                       11
## 255                                  1471                       13
##     Arizona...all.industrial Colorado...all.sectors Colorado...electric.utility
## 253                       --                   4886                        3534
## 254                       --                   4399                        3073
## 255                       --                   4646                        3115
##     Colorado...independent.power.producers Colorado...all.commercial
## 253                                   1332                         2
## 254                                   1306                         2
## 255                                   1508                         2
##     Colorado...all.industrial Idaho...all.sectors Idaho...electric.utility
## 253                        19                1799                     1214
## 254                        18                1530                     1018
## 255                        20                1460                      929
##     Idaho...independent.power.producers Idaho...all.commercial
## 253                                 530                      6
## 254                                 461                      5
## 255                                 476                      6
##     Idaho...all.industrial Montana...all.sectors Montana...electric.utility
## 253                     48                  2789                       1237
## 254                     46                  2330                       1017
## 255                     49                  2560                       1091
##     Montana...independent.power.producers Montana...all.commercial
## 253                                  1549                       --
## 254                                  1311                       --
## 255                                  1467                       --
##     Montana...all.industrial Nevada...all.sectors Nevada...electric.utility
## 253                       NM                 3119                      1887
## 254                       NM                 2788                      1590
## 255                       NM                 3006                      1725
##     Nevada...independent.power.producers Nevada...all.commercial
## 253                                 1153                      65
## 254                                 1127                      57
## 255                                 1204                      57
##     Nevada...all.industrial New.Mexico...all.sectors
## 253                      14                     3640
## 254                      14                     2939
## 255                      21                     2958
##     New.Mexico...electric.utility New.Mexico...independent.power.producers
## 253                          2054                                     1576
## 254                          1525                                     1404
## 255                          1533                                     1413
##     New.Mexico...all.commercial New.Mexico...all.industrial Utah...all.sectors
## 253                           9                           0               3311
## 254                          NM                           0               2855
## 255                          NM                           2               2542
##     Utah...electric.utility Utah...independent.power.producers
## 253                    2919                                342
## 254                    2440                                370
## 255                    2085                                413
##     Utah...all.commercial Utah...all.industrial Wyoming...all.sectors
## 253                    NM                    38                  4062
## 254                    NM                    35                  3669
## 255                    NM                    36                  3825
##     Wyoming...electric.utility Wyoming...independent.power.producers
## 253                       3316                                   613
## 254                       3011                                   552
## 255                       3157                                   546
##     Wyoming...all.commercial Wyoming...all.industrial
## 253                       --                      133
## 254                       --                      107
## 255                       --                      121
##     Pacific.Contiguous...all.sectors Pacific.Contiguous...electric.utility
## 253                            32707                                 20117
## 254                            29316                                 17182
## 255                            30615                                 17327
##     Pacific.Contiguous...independent.power.producers
## 253                                            11103
## 254                                            10787
## 255                                            11779
##     Pacific.Contiguous...all.commercial Pacific.Contiguous...all.industrial
## 253                                 213                                1275
## 254                                 191                                1157
## 255                                 214                                1294
##     California...all.sectors California...electric.utility
## 253                    14642                          5001
## 254                    13548                          4382
## 255                    14883                          4471
##     California...independent.power.producers California...all.commercial
## 253                                     8390                         204
## 254                                     8025                         182
## 255                                     9130                         205
##     California...all.industrial Oregon...all.sectors Oregon...electric.utility
## 253                        1048                 6438                      4810
## 254                         960                 5736                      4091
## 255                        1077                 5710                      4116
##     Oregon...independent.power.producers Oregon...all.commercial
## 253                                 1566                       5
## 254                                 1594                       6
## 255                                 1535                       6
##     Oregon...all.industrial Washington...all.sectors
## 253                      58                    11627
## 254                      45                    10032
## 255                      53                    10022
##     Washington...electric.utility Washington...independent.power.producers
## 253                         10306                                     1147
## 254                          8709                                     1169
## 255                          8740                                     1114
##     Washington...all.commercial Washington...all.industrial
## 253                           3                         170
## 254                           3                         152
## 255                           3                         164
##     Pacific.Noncontiguous...all.sectors
## 253                                1330
## 254                                1152
## 255                                1232
##     Pacific.Noncontiguous...electric.utility
## 253                                      967
## 254                                      800
## 255                                      820
##     Pacific.Noncontiguous...independent.power.producers
## 253                                                 265
## 254                                                 268
## 255                                                 328
##     Pacific.Noncontiguous...all.commercial
## 253                                     67
## 254                                     55
## 255                                     57
##     Pacific.Noncontiguous...all.industrial Alaska...all.sectors
## 253                                     31                  584
## 254                                     28                  474
## 255                                     27                  467
##     Alaska...electric.utility Alaska...independent.power.producers
## 253                       524                                   NM
## 254                       416                                   21
## 255                       409                                   23
##     Alaska...all.commercial Alaska...all.industrial Hawaii...all.sectors
## 253                      32                      10                  745
## 254                      26                      11                  677
## 255                      25                      10                  765
##     Hawaii...electric.utility Hawaii...independent.power.producers
## 253                       443                                  246
## 254                       384                                  247
## 255                       412                                  306
##     Hawaii...all.commercial Hawaii...all.industrial
## 253                      35                      21
## 254                      29                      17
## 255                      32                      16

As we can see that the data contains the energy used in All cities in America and the sum of the whole. In this project, we will be making a model to predict the energy consumption for the country.

4 Data Wrangling

let’s check the data type

glimpse(Energy)
## Rows: 255
## Columns: 311
## $ X                                                   <chr> "2001-01-01", "200…
## $ United.States...all.sectors                         <int> 332493, 282940, 30…
## $ United.States...electric.utility                    <int> 236467, 199802, 21…
## $ United.States...independent.power.producers         <int> 82269, 71169, 7575…
## $ United.States...all.commercial                      <int> 629, 548, 553, 550…
## $ United.States...all.industrial                      <int> 13128, 11421, 1245…
## $ New.England...all.sectors                           <int> 10005, 8662, 9506,…
## $ New.England...electric.utility                      <int> 2467, 2289, 2061, …
## $ New.England...independent.power.producers           <int> 6959, 5873, 6882, …
## $ New.England...all.commercial                        <int> 68, 65, 70, 70, 72…
## $ New.England...all.industrial                        <int> 510, 435, 493, 443…
## $ Connecticut...all.sectors                           <int> 2930, 1853, 2386, …
## $ Connecticut...electric.utility                      <chr> "1411", "661", "69…
## $ Connecticut...independent.power.producers           <int> 1503, 1178, 1673, …
## $ Connecticut...all.commercial                        <chr> "2", "2", "3", "3"…
## $ Connecticut...all.industrial                        <int> 14, 11, 16, 21, 22…
## $ Maine...all.sectors                                 <int> 1648, 1463, 1503, …
## $ Maine...electric.utility                            <chr> "--", "--", "--", …
## $ Maine...independent.power.producers                 <int> 1213, 1092, 1088, …
## $ Maine...all.commercial                              <int> 12, 13, 12, 16, 17…
## $ Maine...all.industrial                              <int> 424, 358, 404, 360…
## $ Massachusetts...all.sectors                         <int> 3802, 3146, 3597, …
## $ Massachusetts...electric.utility                    <chr> "146", "97", "167"…
## $ Massachusetts...independent.power.producers         <int> 3571, 2969, 3343, …
## $ Massachusetts...all.commercial                      <int> 47, 45, 49, 44, 44…
## $ Massachusetts...all.industrial                      <int> 38, 34, 38, 30, 26…
## $ New.Hampshire...all.sectors                         <int> 652, 1280, 958, 14…
## $ New.Hampshire...electric.utility                    <int> 446, 1123, 795, 11…
## $ New.Hampshire...independent.power.producers         <int> 173, 126, 128, 207…
## $ New.Hampshire...all.commercial                      <int> 4, 3, 3, 4, 3, 3, …
## $ New.Hampshire...all.industrial                      <int> 30, 28, 33, 29, 30…
## $ Rhode.Island...all.sectors                          <int> 424, 444, 590, 451…
## $ Rhode.Island...electric.utility                     <chr> "--", "--", "--", …
## $ Rhode.Island...independent.power.producers          <int> 420, 440, 585, 448…
## $ Rhode.Island...all.commercial                       <chr> "3", "3", "4", "3"…
## $ Rhode.Island...all.industrial                       <chr> "0", "0", "0", "0"…
## $ Vermont...all.sectors                               <int> 548, 478, 472, 467…
## $ Vermont...electric.utility                          <int> 464, 407, 404, 374…
## $ Vermont...independent.power.producers               <int> 80, 68, 64, 90, 79…
## $ Vermont...all.commercial                            <chr> "--", "--", "--", …
## $ Vermont...all.industrial                            <chr> "4", "3", "3", "3"…
## $ Middle.Atlantic...all.sectors                       <int> 36792, 31219, 3390…
## $ Middle.Atlantic...electric.utility                  <int> 8428, 7254, 8014, …
## $ Middle.Atlantic...independent.power.producers       <int> 27519, 23202, 2504…
## $ Middle.Atlantic...all.commercial                    <int> 100, 87, 87, 89, 9…
## $ Middle.Atlantic...all.industrial                    <int> 745, 676, 753, 672…
## $ New.Jersey...all.sectors                            <int> 5306, 4706, 4947, …
## $ New.Jersey...electric.utility                       <chr> "195", "146", "122…
## $ New.Jersey...independent.power.producers            <int> 4815, 4290, 4547, …
## $ New.Jersey...all.commercial                         <int> 14, 13, 14, 12, 13…
## $ New.Jersey...all.industrial                         <int> 282, 257, 265, 242…
## $ New.York...all.sectors                              <int> 12622, 11460, 1211…
## $ New.York...electric.utility                         <int> 5795, 4891, 5373, …
## $ New.York...independent.power.producers              <int> 6606, 6370, 6524, …
## $ New.York...all.commercial                           <chr> "48", "43", "46", …
## $ New.York...all.industrial                           <int> 173, 155, 171, 153…
## $ Pennsylvania...all.sectors                          <int> 18864, 15053, 1684…
## $ Pennsylvania...electric.utility                     <int> 2437, 2217, 2520, …
## $ Pennsylvania...independent.power.producers          <int> 16098, 12542, 1397…
## $ Pennsylvania...all.commercial                       <int> 38, 31, 27, 35, 32…
## $ Pennsylvania...all.industrial                       <int> 290, 264, 317, 277…
## $ East.North.Central...all.sectors                    <int> 55695, 48200, 5137…
## $ East.North.Central...electric.utility               <int> 39970, 34347, 3613…
## $ East.North.Central...independent.power.producers    <int> 14658, 12900, 1419…
## $ East.North.Central...all.commercial                 <int> 74, 67, 71, 63, 64…
## $ East.North.Central...all.industrial                 <int> 994, 886, 981, 967…
## $ Illinois...all.sectors                              <int> 16039, 13914, 1488…
## $ Illinois...electric.utility                         <int> 2854, 2378, 2239, …
## $ Illinois...independent.power.producers              <int> 12923, 11319, 1239…
## $ Illinois...all.commercial                           <int> 21, 19, 20, 18, 21…
## $ Illinois...all.industrial                           <int> 241, 198, 230, 220…
## $ Indiana...all.sectors                               <int> 10947, 9661, 9951,…
## $ Indiana...electric.utility                          <int> 10335, 9051, 9320,…
## $ Indiana...independent.power.producers               <int> 304, 301, 289, 245…
## $ Indiana...all.commercial                            <int> 19, 18, 16, 17, 13…
## $ Indiana...all.industrial                            <int> 289, 291, 326, 349…
## $ Michigan...all.sectors                              <int> 10183, 8871, 9681,…
## $ Michigan...electric.utility                         <int> 9154, 7933, 8610, …
## $ Michigan...independent.power.producers              <int> 877, 813, 926, 816…
## $ Michigan...all.commercial                           <int> 19, 17, 20, 18, 20…
## $ Michigan...all.industrial                           <int> 133, 107, 125, 117…
## $ Ohio...all.sectors                                  <int> 13163, 11162, 1210…
## $ Ohio...electric.utility                             <int> 12531, 10669, 1154…
## $ Ohio...independent.power.producers                  <int> 512, 395, 458, 195…
## $ Ohio...all.commercial                               <chr> "2", "1", "2", "1"…
## $ Ohio...all.industrial                               <int> 118, 97, 103, 95, …
## $ Wisconsin...all.sectors                             <int> 5364, 4594, 4755, …
## $ Wisconsin...electric.utility                        <int> 5097, 4316, 4419, …
## $ Wisconsin...independent.power.producers             <int> 41, 73, 127, 33, 3…
## $ Wisconsin...all.commercial                          <int> 13, 11, 13, 9, 9, …
## $ Wisconsin...all.industrial                          <int> 213, 194, 197, 186…
## $ West.North.Central...all.sectors                    <int> 25600, 22084, 2201…
## $ West.North.Central...electric.utility               <int> 25026, 21578, 2150…
## $ West.North.Central...independent.power.producers    <int> 238, 204, 180, 245…
## $ West.North.Central...all.commercial                 <int> 36, 33, 32, 31, 36…
## $ West.North.Central...all.industrial                 <int> 300, 269, 293, 258…
## $ Iowa...all.sectors                                  <int> 3761, 3244, 3576, …
## $ Iowa...electric.utility                             <int> 3590, 3095, 3419, …
## $ Iowa...independent.power.producers                  <int> 59, 47, 52, 68, 62…
## $ Iowa...all.commercial                               <int> 13, 12, 10, 8, 12,…
## $ Iowa...all.industrial                               <int> 99, 90, 96, 76, 82…
## $ Kansas...all.sectors                                <int> 4108, 3274, 3340, …
## $ Kansas...electric.utility                           <int> 4105, 3271, 3336, …
## $ Kansas...independent.power.producers                <chr> "--", "--", "--", …
## $ Kansas...all.commercial                             <chr> "0", "0", "0", "0"…
## $ Kansas...all.industrial                             <chr> "3", "3", "3", "3"…
## $ Minnesota...all.sectors                             <int> 4333, 3840, 3663, …
## $ Minnesota...electric.utility                        <int> 3984, 3531, 3371, …
## $ Minnesota...independent.power.producers             <int> 178, 157, 128, 177…
## $ Minnesota...all.commercial                          <int> 12, 11, 11, 11, 11…
## $ Minnesota...all.industrial                          <int> 158, 142, 153, 140…
## $ Missouri...all.sectors                              <int> 7120, 6216, 5891, …
## $ Missouri...electric.utility                         <int> 7092, 6189, 5864, …
## $ Missouri...independent.power.producers              <chr> "--", "--", "0", "…
## $ Missouri...all.commercial                           <int> 9, 8, 10, 11, 11, …
## $ Missouri...all.industrial                           <int> 20, 18, 17, 16, 16…
## $ Nebraska...all.sectors                              <int> 2899, 2425, 2250, …
## $ Nebraska...electric.utility                         <int> 2893, 2418, 2243, …
## $ Nebraska...independent.power.producers              <int> 1, 1, 1, 1, 1, 1, …
## $ Nebraska...all.commercial                           <int> 2, 2, 1, 2, 2, 1, …
## $ Nebraska...all.industrial                           <int> 4, 5, 5, 3, 5, 5, …
## $ North.Dakota...all.sectors                          <int> 2751, 2514, 2690, …
## $ North.Dakota...electric.utility                     <int> 2734, 2502, 2670, …
## $ North.Dakota...independent.power.producers          <chr> "--", "--", "--", …
## $ North.Dakota...all.commercial                       <chr> "--", "--", "--", …
## $ North.Dakota...all.industrial                       <chr> "16", "12", "20", …
## $ South.Dakota...all.sectors                          <int> 628, 572, 601, 447…
## $ South.Dakota...electric.utility                     <int> 628, 572, 601, 447…
## $ South.Dakota...independent.power.producers          <chr> "--", "--", "--", …
## $ South.Dakota...all.commercial                       <chr> "--", "--", "--", …
## $ South.Dakota...all.industrial                       <chr> "--", "--", "--", …
## $ South.Atlantic...all.sectors                        <int> 67187, 54571, 5851…
## $ South.Atlantic...electric.utility                   <int> 54761, 43905, 4841…
## $ South.Atlantic...independent.power.producers        <int> 10533, 9051, 8371,…
## $ South.Atlantic...all.commercial                     <int> 93, 54, 51, 47, 52…
## $ South.Atlantic...all.industrial                     <int> 1799, 1561, 1670, …
## $ Delaware...all.sectors                              <int> 626, 521, 867, 577…
## $ Delaware...electric.utility                         <int> 373, 332, 330, 301…
## $ Delaware...independent.power.producers              <int> 205, 150, 481, 232…
## $ Delaware...all.commercial                           <chr> "--", "--", "--", …
## $ Delaware...all.industrial                           <int> 48, 39, 55, 44, 39…
## $ District.Of.Columbia...all.sectors                  <chr> "9", "0", "0", "1"…
## $ District.Of.Columbia...electric.utility             <chr> "--", "--", "--", …
## $ District.Of.Columbia...independent.power.producers  <chr> "9", "0", "0", "1"…
## $ District.Of.Columbia...all.commercial               <chr> "--", "--", "--", …
## $ District.Of.Columbia...all.industrial               <chr> "--", "--", "--", …
## $ Florida...all.sectors                               <int> 16937, 12761, 1411…
## $ Florida...electric.utility                          <int> 15251, 11369, 1255…
## $ Florida...independent.power.producers               <int> 1257, 1010, 1165, …
## $ Florida...all.commercial                            <chr> "10", "8", "9", "8…
## $ Florida...all.industrial                            <int> 419, 375, 386, 413…
## $ Georgia...all.sectors                               <int> 11084, 8332, 9844,…
## $ Georgia...electric.utility                          <int> 10510, 7825, 9345,…
## $ Georgia...independent.power.producers               <int> 70, 54, 43, 168, 1…
## $ Georgia...all.commercial                            <chr> "0", "0", "0", "0"…
## $ Georgia...all.industrial                            <int> 504, 452, 456, 459…
## $ Maryland...all.sectors                              <int> 4603, 4182, 3597, …
## $ Maryland...electric.utility                         <chr> "19", "1", "51", "…
## $ Maryland...independent.power.producers              <int> 4576, 4174, 3539, …
## $ Maryland...all.commercial                           <int> 3, 2, 2, 2, 2, 3, …
## $ Maryland...all.industrial                           <int> 5, 5, 5, 5, 5, 5, …
## $ North.Carolina...all.sectors                        <int> 10512, 8862, 9303,…
## $ North.Carolina...electric.utility                   <int> 9839, 8284, 8643, …
## $ North.Carolina...independent.power.producers        <int> 356, 298, 315, 332…
## $ North.Carolina...all.commercial                     <int> 14, 11, 8, 3, 5, 7…
## $ North.Carolina...all.industrial                     <int> 303, 270, 338, 301…
## $ South.Carolina...all.sectors                        <int> 7646, 6638, 7385, …
## $ South.Carolina...electric.utility                   <int> 7432, 6484, 7231, …
## $ South.Carolina...independent.power.producers        <int> 46, 45, 42, 39, 35…
## $ South.Carolina...all.commercial                     <chr> "5", "4", "5", "3"…
## $ South.Carolina...all.industrial                     <int> 162, 104, 108, 114…
## $ Virginia...all.sectors                              <int> 7117, 5894, 6358, …
## $ Virginia...electric.utility                         <int> 5826, 4906, 5288, …
## $ Virginia...independent.power.producers              <int> 1013, 784, 870, 63…
## $ Virginia...all.commercial                           <int> 62, 28, 27, 31, 31…
## $ Virginia...all.industrial                           <int> 216, 177, 173, 151…
## $ West.Virginia...all.sectors                         <int> 8653, 7381, 7041, …
## $ West.Virginia...electric.utility                    <int> 5512, 4704, 4976, …
## $ West.Virginia...independent.power.producers         <int> 2999, 2537, 1915, …
## $ West.Virginia...all.commercial                      <chr> "--", "--", "--", …
## $ West.Virginia...all.industrial                      <int> 143, 140, 150, 124…
## $ East.South.Central...all.sectors                    <int> 32115, 27307, 2940…
## $ East.South.Central...electric.utility               <int> 29979, 25454, 2736…
## $ East.South.Central...independent.power.producers    <int> 1102, 1031, 1167, …
## $ East.South.Central...all.commercial                 <chr> "9", "9", "9", "8"…
## $ East.South.Central...all.industrial                 <int> 1025, 813, 856, 85…
## $ Alabama...all.sectors                               <int> 11327, 9576, 9364,…
## $ Alabama...electric.utility                          <int> 10695, 9070, 8829,…
## $ Alabama...independent.power.producers               <int> 48, 45, 47, 24, 50…
## $ Alabama...all.commercial                            <chr> "--", "--", "--", …
## $ Alabama...all.industrial                            <int> 583, 461, 489, 496…
## $ Kentucky...all.sectors                              <int> 8118, 7534, 8202, …
## $ Kentucky...electric.utility                         <int> 7058, 6562, 7208, …
## $ Kentucky...independent.power.producers              <chr> "1043", "956", "97…
## $ Kentucky...all.commercial                           <chr> "--", "--", "--", …
## $ Kentucky...all.industrial                           <int> 18, 16, 16, 15, 16…
## $ Mississippi...all.sectors                           <int> 3564, 2743, 3643, …
## $ Mississippi...electric.utility                      <int> 3376, 2578, 3371, …
## $ Mississippi...independent.power.producers           <int> 8, 28, 141, 142, 2…
## $ Mississippi...all.commercial                        <int> 1, 1, 1, 1, 1, 2, …
## $ Mississippi...all.industrial                        <int> 179, 136, 130, 141…
## $ Tennessee...all.sectors                             <int> 9106, 7454, 8193, …
## $ Tennessee...electric.utility                        <int> 8851, 7244, 7961, …
## $ Tennessee...independent.power.producers             <int> 2, 2, 2, 8, 16, 29…
## $ Tennessee...all.commercial                          <chr> "8", "9", "8", "7"…
## $ Tennessee...all.industrial                          <int> 245, 200, 221, 203…
## $ West.South.Central...all.sectors                    <int> 46990, 39136, 4083…
## $ West.South.Central...electric.utility               <int> 34843, 28424, 2935…
## $ West.South.Central...independent.power.producers    <int> 6424, 5604, 5892, …
## $ West.South.Central...all.commercial                 <int> 41, 36, 41, 43, 44…
## $ West.South.Central...all.industrial                 <int> 5684, 5072, 5546, …
## $ Arkansas...all.sectors                              <int> 3903, 3372, 3125, …
## $ Arkansas...electric.utility                         <int> 3704, 3200, 2958, …
## $ Arkansas...independent.power.producers              <int> 0, 0, 0, 0, 0, 0, …
## $ Arkansas...all.commercial                           <chr> "1", "1", "1", "1"…
## $ Arkansas...all.industrial                           <int> 199, 171, 166, 184…
## $ Louisiana...all.sectors                             <int> 7595, 6105, 6321, …
## $ Louisiana...electric.utility                        <int> 4599, 3175, 3348, …
## $ Louisiana...independent.power.producers             <int> 1158, 1184, 1145, …
## $ Louisiana...all.commercial                          <chr> "2", "2", "2", "2"…
## $ Louisiana...all.industrial                          <int> 1837, 1744, 1826, …
## $ Oklahoma...all.sectors                              <int> 4491, 4033, 3808, …
## $ Oklahoma...electric.utility                         <int> 4090, 3691, 3568, …
## $ Oklahoma...independent.power.producers              <int> 287, 242, 151, 128…
## $ Oklahoma...all.commercial                           <chr> "2", "2", "2", "2"…
## $ Oklahoma...all.industrial                           <int> 112, 98, 87, 102, …
## $ Texas...all.sectors                                 <int> 31001, 25627, 2758…
## $ Texas...electric.utility                            <int> 22450, 18357, 1948…
## $ Texas...independent.power.producers                 <int> 4979, 4178, 4596, …
## $ Texas...all.commercial                              <int> 36, 32, 36, 38, 40…
## $ Texas...all.industrial                              <int> 3537, 3059, 3466, …
## $ Mountain...all.sectors                              <int> 27506, 25227, 2587…
## $ Mountain...electric.utility                         <int> 24203, 22107, 2285…
## $ Mountain...independent.power.producers              <int> 3050, 2881, 2748, …
## $ Mountain...all.commercial                           <int> 25, 25, 29, 25, 25…
## $ Mountain...all.industrial                           <int> 229, 215, 234, 205…
## $ Arizona...all.sectors                               <int> 7574, 6617, 7326, …
## $ Arizona...electric.utility                          <int> 7499, 6547, 7252, …
## $ Arizona...independent.power.producers               <int> 41, 37, 41, 39, 24…
## $ Arizona...all.commercial                            <int> 2, 1, 2, 2, 2, 2, …
## $ Arizona...all.industrial                            <chr> "33", "31", "31", …
## $ Colorado...all.sectors                              <int> 4163, 3777, 3842, …
## $ Colorado...electric.utility                         <int> 3664, 3281, 3344, …
## $ Colorado...independent.power.producers              <int> 477, 473, 470, 489…
## $ Colorado...all.commercial                           <chr> "17", "17", "20", …
## $ Colorado...all.industrial                           <int> 6, 6, 7, 6, 7, 7, …
## $ Idaho...all.sectors                                 <int> 605, 503, 595, 622…
## $ Idaho...electric.utility                            <int> 505, 410, 486, 494…
## $ Idaho...independent.power.producers                 <int> 35, 33, 39, 60, 12…
## $ Idaho...all.commercial                              <chr> "--", "--", "--", …
## $ Idaho...all.industrial                              <int> 65, 60, 71, 68, 64…
## $ Montana...all.sectors                               <int> 2301, 2105, 1921, …
## $ Montana...electric.utility                          <int> 453, 459, 310, 283…
## $ Montana...independent.power.producers               <int> 1841, 1639, 1604, …
## $ Montana...all.commercial                            <chr> "--", "--", "--", …
## $ Montana...all.industrial                            <chr> "7", "7", "7", "6"…
## $ Nevada...all.sectors                                <int> 2966, 2969, 3040, …
## $ Nevada...electric.utility                           <int> 2461, 2417, 2596, …
## $ Nevada...independent.power.producers                <int> 504, 552, 444, 261…
## $ Nevada...all.commercial                             <chr> "--", "--", "--", …
## $ Nevada...all.industrial                             <chr> "--", "--", "--", …
## $ New.Mexico...all.sectors                            <int> 2919, 2713, 2617, …
## $ New.Mexico...electric.utility                       <int> 2787, 2578, 2484, …
## $ New.Mexico...independent.power.producers            <int> 93, 95, 90, 86, 79…
## $ New.Mexico...all.commercial                         <chr> "5", "5", "5", "5"…
## $ New.Mexico...all.industrial                         <int> 34, 35, 38, 38, 38…
## $ Utah...all.sectors                                  <int> 2957, 2796, 2435, …
## $ Utah...electric.utility                             <int> 2899, 2742, 2369, …
## $ Utah...independent.power.producers                  <int> 35, 31, 39, 22, 26…
## $ Utah...all.commercial                               <chr> "1", "1", "1", "1"…
## $ Utah...all.industrial                               <chr> "23", "22", "27", …
## $ Wyoming...all.sectors                               <int> 4021, 3747, 4093, …
## $ Wyoming...electric.utility                          <int> 3935, 3673, 4020, …
## $ Wyoming...independent.power.producers               <int> 24, 21, 21, 12, 15…
## $ Wyoming...all.commercial                            <chr> "--", "--", "--", …
## $ Wyoming...all.industrial                            <int> 61, 53, 53, 31, 38…
## $ Pacific.Contiguous...all.sectors                    <int> 29087, 25186, 2783…
## $ Pacific.Contiguous...electric.utility               <int> 15774, 13566, 1519…
## $ Pacific.Contiguous...independent.power.producers    <int> 11446, 10106, 1099…
## $ Pacific.Contiguous...all.commercial                 <int> 173, 154, 146, 166…
## $ Pacific.Contiguous...all.industrial                 <int> 1694, 1360, 1494, …
## $ California...all.sectors                            <int> 16619, 14380, 1584…
## $ California...electric.utility                       <int> 5187, 4415, 5119, …
## $ California...independent.power.producers            <int> 9798, 8603, 9301, …
## $ California...all.commercial                         <int> 163, 145, 136, 155…
## $ California...all.industrial                         <int> 1470, 1217, 1293, …
## $ Oregon...all.sectors                                <int> 4150, 3718, 4209, …
## $ Oregon...electric.utility                           <int> 3658, 3309, 3714, …
## $ Oregon...independent.power.producers                <int> 398, 367, 407, 410…
## $ Oregon...all.commercial                             <int> 1, 1, 1, 1, 1, 1, …
## $ Oregon...all.industrial                             <int> 94, 41, 86, 69, 70…
## $ Washington...all.sectors                            <int> 8318, 7088, 7776, …
## $ Washington...electric.utility                       <int> 6929, 5842, 6360, …
## $ Washington...independent.power.producers            <int> 1250, 1136, 1291, …
## $ Washington...all.commercial                         <int> 9, 8, 9, 10, 9, 8,…
## $ Washington...all.industrial                         <int> 131, 102, 115, 116…
## $ Pacific.Noncontiguous...all.sectors                 <int> 1515, 1347, 1460, …
## $ Pacific.Noncontiguous...electric.utility            <int> 1017, 880, 1032, 9…
## $ Pacific.Noncontiguous...independent.power.producers <int> 340, 315, 276, 294…
## $ Pacific.Noncontiguous...all.commercial              <int> 10, 18, 18, 9, 8, …
## $ Pacific.Noncontiguous...all.industrial              <int> 148, 134, 134, 97,…
## $ Alaska...all.sectors                                <int> 590, 546, 587, 489…
## $ Alaska...electric.utility                           <int> 493, 423, 459, 402…
## $ Alaska...independent.power.producers                <chr> "20", "22", "23", …
## $ Alaska...all.commercial                             <chr> "10", "18", "18", …
## $ Alaska...all.industrial                             <int> 67, 84, 88, 61, 65…
## $ Hawaii...all.sectors                                <int> 925, 801, 873, 836…
## $ Hawaii...electric.utility                           <int> 524, 457, 573, 522…
## $ Hawaii...independent.power.producers                <int> 320, 293, 254, 278…
## $ Hawaii...all.commercial                             <chr> "--", "--", "--", …
## $ Hawaii...all.industrial                             <int> 81, 51, 46, 36, 37…

from the data type above, we can see that there are many variables stating the energy consumption, along with each type of energy used in several different cities of US of A. Hence, we will only pick the X which later will we change the name to Date as the column stating the Date. Also, the sum of the all energy consumed in the country, which is the name of the current variable is United States All Sector, will also be renamed into US Energy Consumption. The numbers stated in all observations are in thousand megawatts hours.

Energy_clean <- Energy |> 
  rename(
    Date = X,
    US_Energy_Consumption = United.States...all.sectors
         ) |> 
  mutate(Date = ymd(Date)) |>
  select(c(Date, US_Energy_Consumption))

Energy_clean
##           Date US_Energy_Consumption
## 1   2001-01-01                332493
## 2   2001-02-01                282940
## 3   2001-03-01                300707
## 4   2001-04-01                278079
## 5   2001-05-01                300492
## 6   2001-06-01                327694
## 7   2001-07-01                357614
## 8   2001-08-01                370533
## 9   2001-09-01                306929
## 10  2001-10-01                294734
## 11  2001-11-01                278934
## 12  2001-12-01                305496
## 13  2002-01-01                319941
## 14  2002-02-01                281826
## 15  2002-03-01                302549
## 16  2002-04-01                289848
## 17  2002-05-01                307675
## 18  2002-06-01                341023
## 19  2002-07-01                381542
## 20  2002-08-01                374586
## 21  2002-09-01                331279
## 22  2002-10-01                307059
## 23  2002-11-01                296290
## 24  2002-12-01                324834
## 25  2003-01-01                341989
## 26  2003-02-01                299249
## 27  2003-03-01                304317
## 28  2003-04-01                285756
## 29  2003-05-01                307545
## 30  2003-06-01                328694
## 31  2003-07-01                374396
## 32  2003-08-01                381816
## 33  2003-09-01                323136
## 34  2003-10-01                306741
## 35  2003-11-01                297867
## 36  2003-12-01                331680
## 37  2004-01-01                346546
## 38  2004-02-01                314280
## 39  2004-03-01                308812
## 40  2004-04-01                290560
## 41  2004-05-01                327380
## 42  2004-06-01                345085
## 43  2004-07-01                377332
## 44  2004-08-01                368439
## 45  2004-09-01                335622
## 46  2004-10-01                312450
## 47  2004-11-01                302101
## 48  2004-12-01                341948
## 49  2005-01-01                343121
## 50  2005-02-01                298500
## 51  2005-03-01                317458
## 52  2005-04-01                289562
## 53  2005-05-01                315062
## 54  2005-06-01                363672
## 55  2005-07-01                402274
## 56  2005-08-01                404941
## 57  2005-09-01                350218
## 58  2005-10-01                316398
## 59  2005-11-01                306115
## 60  2005-12-01                348101
## 61  2006-01-01                328658
## 62  2006-02-01                307333
## 63  2006-03-01                318730
## 64  2006-04-01                297858
## 65  2006-05-01                330616
## 66  2006-06-01                364260
## 67  2006-07-01                410421
## 68  2006-08-01                407763
## 69  2006-09-01                332055
## 70  2006-10-01                321567
## 71  2006-11-01                309159
## 72  2006-12-01                336283
## 73  2007-01-01                353531
## 74  2007-02-01                323230
## 75  2007-03-01                320471
## 76  2007-04-01                303129
## 77  2007-05-01                330203
## 78  2007-06-01                362755
## 79  2007-07-01                393226
## 80  2007-08-01                421797
## 81  2007-09-01                355394
## 82  2007-10-01                332615
## 83  2007-11-01                314103
## 84  2007-12-01                346290
## 85  2008-01-01                362998
## 86  2008-02-01                325106
## 87  2008-03-01                324630
## 88  2008-04-01                305865
## 89  2008-05-01                325245
## 90  2008-06-01                373109
## 91  2008-07-01                402900
## 92  2008-08-01                388987
## 93  2008-09-01                338056
## 94  2008-10-01                318547
## 95  2008-11-01                310046
## 96  2008-12-01                343898
## 97  2009-01-01                354993
## 98  2009-02-01                300887
## 99  2009-03-01                310603
## 100 2009-04-01                289537
## 101 2009-05-01                311306
## 102 2009-06-01                347658
## 103 2009-07-01                372542
## 104 2009-08-01                381221
## 105 2009-09-01                327401
## 106 2009-10-01                307040
## 107 2009-11-01                296635
## 108 2009-12-01                350507
## 109 2010-01-01                360957
## 110 2010-02-01                319735
## 111 2010-03-01                312168
## 112 2010-04-01                287800
## 113 2010-05-01                327936
## 114 2010-06-01                375759
## 115 2010-07-01                409725
## 116 2010-08-01                408884
## 117 2010-09-01                346045
## 118 2010-10-01                307921
## 119 2010-11-01                306010
## 120 2010-12-01                362119
## 121 2011-01-01                362872
## 122 2011-02-01                313127
## 123 2011-03-01                318710
## 124 2011-04-01                302401
## 125 2011-05-01                323628
## 126 2011-06-01                367727
## 127 2011-07-01                418693
## 128 2011-08-01                406511
## 129 2011-09-01                337931
## 130 2011-10-01                308699
## 131 2011-11-01                304102
## 132 2011-12-01                335740
## 133 2012-01-01                339526
## 134 2012-02-01                309389
## 135 2012-03-01                309090
## 136 2012-04-01                295229
## 137 2012-05-01                336516
## 138 2012-06-01                360825
## 139 2012-07-01                414641
## 140 2012-08-01                395700
## 141 2012-09-01                334586
## 142 2012-10-01                311652
## 143 2012-11-01                305976
## 144 2012-12-01                334635
## 145 2013-01-01                348967
## 146 2013-02-01                309728
## 147 2013-03-01                325399
## 148 2013-04-01                299333
## 149 2013-05-01                322156
## 150 2013-06-01                356823
## 151 2013-07-01                394846
## 152 2013-08-01                385286
## 153 2013-09-01                340941
## 154 2013-10-01                314925
## 155 2013-11-01                314540
## 156 2013-12-01                353021
## 157 2014-01-01                377250
## 158 2014-02-01                324344
## 159 2014-03-01                331818
## 160 2014-04-01                297625
## 161 2014-05-01                324718
## 162 2014-06-01                357838
## 163 2014-07-01                385773
## 164 2014-08-01                384335
## 165 2014-09-01                339881
## 166 2014-10-01                314516
## 167 2014-11-01                317489
## 168 2014-12-01                337951
## 169 2015-01-01                360449
## 170 2015-02-01                334471
## 171 2015-03-01                324186
## 172 2015-04-01                294128
## 173 2015-05-01                322081
## 174 2015-06-01                362403
## 175 2015-07-01                400412
## 176 2015-08-01                392110
## 177 2015-09-01                350115
## 178 2015-10-01                312106
## 179 2015-11-01                300647
## 180 2015-12-01                324421
## 181 2016-01-01                352714
## 182 2016-02-01                313680
## 183 2016-03-01                304384
## 184 2016-04-01                292889
## 185 2016-05-01                316779
## 186 2016-06-01                367776
## 187 2016-07-01                411881
## 188 2016-08-01                409695
## 189 2016-09-01                351479
## 190 2016-10-01                312940
## 191 2016-11-01                297056
## 192 2016-12-01                345337
## 193 2017-01-01                344325
## 194 2017-02-01                291043
## 195 2017-03-01                319329
## 196 2017-04-01                295354
## 197 2017-05-01                323439
## 198 2017-06-01                358514
## 199 2017-07-01                404425
## 200 2017-08-01                384731
## 201 2017-09-01                335908
## 202 2017-10-01                318662
## 203 2017-11-01                308045
## 204 2017-12-01                350408
## 205 2018-01-01                373230
## 206 2018-02-01                306894
## 207 2018-03-01                321547
## 208 2018-04-01                300756
## 209 2018-05-01                338948
## 210 2018-06-01                371886
## 211 2018-07-01                411290
## 212 2018-08-01                408028
## 213 2018-09-01                356258
## 214 2018-10-01                324932
## 215 2018-11-01                322369
## 216 2018-12-01                342139
## 217 2019-01-01                359509
## 218 2019-02-01                315026
## 219 2019-03-01                326657
## 220 2019-04-01                296663
## 221 2019-05-01                330423
## 222 2019-06-01                352988
## 223 2019-07-01                410038
## 224 2019-08-01                401430
## 225 2019-09-01                360518
## 226 2019-10-01                320352
## 227 2019-11-01                315849
## 228 2019-12-01                338402
## 229 2020-01-01                341850
## 230 2020-02-01                319550
## 231 2020-03-01                309587
## 232 2020-04-01                279583
## 233 2020-05-01                304593
## 234 2020-06-01                351745
## 235 2020-07-01                409562
## 236 2020-08-01                398280
## 237 2020-09-01                333258
## 238 2020-10-01                313531
## 239 2020-11-01                301250
## 240 2020-12-01                344346
## 241 2021-01-01                350796
## 242 2021-02-01                326223
## 243 2021-03-01                312285
## 244 2021-04-01                292504
## 245 2021-05-01                318859
## 246 2021-06-01                373754
## 247 2021-07-01                404749
## 248 2021-08-01                413353
## 249 2021-09-01                348201
## 250 2021-10-01                319638
## 251 2021-11-01                315495
## 252 2021-12-01                339684
## 253 2022-01-01                378967
## 254 2022-02-01                327767
## 255 2022-03-01                325952

now let’s check for missing value

anyNA(Energy_clean)
## [1] FALSE

We can see that the data has no missing value, we can move onto the next phase which is checking if there is any missing year between the start and at the end.

range(Energy_clean$Date)
## [1] "2001-01-01" "2022-03-01"
all(seq.Date(from = as.Date("2001-01-01"), to = as.Date("2022-03-01"), by = "month") == Energy_clean$Date)
## [1] TRUE

Since the data returning TRUE, which means that the year in between are complete, let’s create a time series object

5 Time Series Object

We would want to see the energy consume yearly. Hence, we will be putting 12 for the frequency since the data is presented monthly

Energy_ts = ts(data = Energy_clean$US_Energy_Consumption,
             start = c(2001, 1),
             frequency = 12)

6 Visualizing the Time Series Object

library(forecast)
Energy_ts |> 
  autoplot(ylab = "Total Energy consumed in US of A",
           xlab = "Year")

7 Decompose the Data

Now let’s decompose the data to have a better understanding of it.

Energy_ts |> decompose() |> autoplot()

As we can see that the type of our TS object is additive time series. We can see that the data has a seasonal since the seasonal shows us a recurring pattern in its move. The data also consist of a trend which going up for around 7 years starting 2001, and it drops quite steeply in around 2008 which probably caused by the crisis happened back in 2008 in the USA. However, the trend line does not look so good. this can be caused by 2 possibilities. The first one is that it has a trend inside the trend. The second possibility is that we give the frequency an unjust number. However, we have given it a number of 12 according to our goal, which is to see the move of the data yearly. With that being said, let’s leave it the way it is and get on with it.

8 Splitting the Data

Energy_train <- head(Energy_ts, 15*12)
Energy_test <- tail(Energy_ts, -15*12)

9 Check whether the data is stationer

library(tseries)
adf.test(Energy_train)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  Energy_train
## Dickey-Fuller = -7.591, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary

Since the p value is < 0.05, means that our TS data is already stationer, we can move into next phase. But, this step to differencing the data can be done as follow if our data is not stationer

Energy_train %>% 
  diff(lag = 12) %>% 
  diff() %>% 
  tsdisplay(lag.max = 36)

Now, let’s move into the next phase using the data after differencing (which actually is not necessary to do in the real case, if our TS data is already stationer)

10 Model Fitting

The modeling using auto arima to be used for threshold

library(forecast)
Energy_auto <- auto.arima(Energy_train, trace=T)
## 
##  Fitting models using approximations to speed things up...
## 
##  ARIMA(2,0,2)(1,1,1)[12] with drift         : 3331.541
##  ARIMA(0,0,0)(0,1,0)[12] with drift         : 3428.399
##  ARIMA(1,0,0)(1,1,0)[12] with drift         : 3356.031
##  ARIMA(0,0,1)(0,1,1)[12] with drift         : 3356.376
##  ARIMA(0,0,0)(0,1,0)[12]                    : 3430.594
##  ARIMA(2,0,2)(0,1,1)[12] with drift         : 3335.562
##  ARIMA(2,0,2)(1,1,0)[12] with drift         : 3357.206
##  ARIMA(2,0,2)(2,1,1)[12] with drift         : Inf
##  ARIMA(2,0,2)(1,1,2)[12] with drift         : 3329.39
##  ARIMA(2,0,2)(0,1,2)[12] with drift         : 3335.027
##  ARIMA(2,0,2)(2,1,2)[12] with drift         : Inf
##  ARIMA(1,0,2)(1,1,2)[12] with drift         : 3325.157
##  ARIMA(1,0,2)(0,1,2)[12] with drift         : 3336.888
##  ARIMA(1,0,2)(1,1,1)[12] with drift         : 3329.45
##  ARIMA(1,0,2)(2,1,2)[12] with drift         : Inf
##  ARIMA(1,0,2)(0,1,1)[12] with drift         : 3337.122
##  ARIMA(1,0,2)(2,1,1)[12] with drift         : 3340.082
##  ARIMA(0,0,2)(1,1,2)[12] with drift         : 3339.919
##  ARIMA(1,0,1)(1,1,2)[12] with drift         : 3327.052
##  ARIMA(1,0,3)(1,1,2)[12] with drift         : Inf
##  ARIMA(0,0,1)(1,1,2)[12] with drift         : 3344.015
##  ARIMA(0,0,3)(1,1,2)[12] with drift         : 3335.929
##  ARIMA(2,0,1)(1,1,2)[12] with drift         : 3328.73
##  ARIMA(2,0,3)(1,1,2)[12] with drift         : Inf
##  ARIMA(1,0,2)(1,1,2)[12]                    : 3322.969
##  ARIMA(1,0,2)(0,1,2)[12]                    : 3337.681
##  ARIMA(1,0,2)(1,1,1)[12]                    : 3328.96
##  ARIMA(1,0,2)(2,1,2)[12]                    : Inf
##  ARIMA(1,0,2)(0,1,1)[12]                    : 3337.496
##  ARIMA(1,0,2)(2,1,1)[12]                    : 3338.089
##  ARIMA(0,0,2)(1,1,2)[12]                    : 3349.148
##  ARIMA(1,0,1)(1,1,2)[12]                    : 3329.091
##  ARIMA(2,0,2)(1,1,2)[12]                    : Inf
##  ARIMA(1,0,3)(1,1,2)[12]                    : Inf
##  ARIMA(0,0,1)(1,1,2)[12]                    : 3352.734
##  ARIMA(0,0,3)(1,1,2)[12]                    : 3342.391
##  ARIMA(2,0,1)(1,1,2)[12]                    : Inf
##  ARIMA(2,0,3)(1,1,2)[12]                    : Inf
## 
##  Now re-fitting the best model(s) without approximations...
## 
##  ARIMA(1,0,2)(1,1,2)[12]                    : Inf
##  ARIMA(1,0,2)(1,1,2)[12] with drift         : Inf
##  ARIMA(1,0,1)(1,1,2)[12] with drift         : Inf
##  ARIMA(2,0,1)(1,1,2)[12] with drift         : Inf
##  ARIMA(1,0,2)(1,1,1)[12]                    : Inf
##  ARIMA(1,0,1)(1,1,2)[12]                    : 3561.536
## 
##  Best model: ARIMA(1,0,1)(1,1,2)[12]
Energy_auto
## Series: Energy_train 
## ARIMA(1,0,1)(1,1,2)[12] 
## 
## Coefficients:
##          ar1      ma1     sar1     sma1     sma2
##       0.8424  -0.3264  -0.0050  -0.6900  -0.1465
## s.e.  0.0747   0.1364   0.4259   0.4318   0.3276
## 
## sigma^2 = 83124623:  log likelihood = -1774.51
## AIC=3561.01   AICc=3561.54   BIC=3579.76

ARIMA(1,0,1)(1,1,2)[12]

Now, since the data has a seasonal, let’s tuning the model using SARIMA. but first let’s see the PACF and ACF graph to help us determine the value of p, q, P, and Q

Energy_train %>% 
  diff(lag = 12) %>% 
  diff() %>% 
  tsdisplay(lag.max = 36)

the probability for the value of (p,d,q) and (P,D,Q):

p = 1, 2, 0

q = 1, 2, 0

P = 1, 0

Q = 1, 0

SARIMA model combination

Energy101111 <- Arima(Energy_train, order = c(1,0,1), seasonal = c(1,1,1))
Energy201111 <- Arima(Energy_train, order = c(2,0,1), seasonal = c(1,1,1))
Energy102111 <- Arima(Energy_train, order = c(1,0,2), seasonal = c(1,1,1))
Energy202111 <- Arima(Energy_train, order = c(2,0,2), seasonal = c(1,1,1))

Now let’s pick out the best model

11 Goodness of fit

Energy_auto$aic ; Energy101111$aic ; Energy102111$aic ; Energy201111$aic ; Energy202111$aic
## [1] 3561.014
## [1] 3559.179
## [1] 3556.885
## [1] 3555.086
## [1] 3557.041

from the result, we can see that the model of Energy201111 has the least aic, which means that it has the least errors. Thus, we will pick the model in our forecasting step

12 Forecasting

Energy_fore <- forecast(Energy201111, h = 75)

Visualizing the result

Energy_ts %>% 
  autoplot()+
  autolayer(Energy201111$fitted, series = "training") +
  autolayer(Energy_fore$mean, series = "forecast")

The model training is looking nice from the plot above. Notice that the data train predicting almost flawlessly in early years of 2001 and 2002 give or take (notice the black on the tip of the line during those years)

13 Model Evaluation

Now we would like to see the error percentage of the model by looking at its MAPE

accuracy(Energy_fore, Energy_test)
##                    ME      RMSE      MAE       MPE     MAPE      MASE
## Training set  722.616  8320.701 6372.442 0.1643256 1.866685 0.6321636
## Test set     5538.464 11323.765 9213.566 1.4626696 2.645851 0.9140108
##                     ACF1 Theil's U
## Training set -0.01689208        NA
## Test set      0.36362302 0.3363917

We can see that the our training set has an error of 1.87% and the test set has an error slightly bigger at 2.64%. This percentage of error is considered as low error. In other words, we have a good model

14 Check Assumption

14.1 No Autocorrelation

We will be checking the autocorrelation using L-jung box. we would want to see the p-value greater than 0.05 which indicates that there is no correlation in our forecasting

Box.test(Energy201111$residuals, type = "Ljung-Box")
## 
##  Box-Ljung test
## 
## data:  Energy201111$residuals
## X-squared = 0.052222, df = 1, p-value = 0.8192

Hypothesis:

\(H_0\): residual has no-autocorrelation

\(H_1\): residual has autocorrelation

Now since the p-value is greater than 0.05, then it fails to reject the \(H0\). Hence, the forecasting does not show any correlation in it.

14.2 Residuals Normality

We will now going to look at the distribution of the residuals whether its normal or not. To see that, we will be using the Shapiro Test method.

shapiro.test(Energy201111$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  Energy201111$residuals
## W = 0.9911, p-value = 0.33

Hypothesis:

\(H_0\): residuals spread normally

\(H_1\): residuals does not spread normally

Now since the p-value returning the value greater than 0.05, we can say that the distribution of the resids are normally distributed.

15 Conclusion and Suggestion

C > Out of our 5 models, we can see that the 4th model (Model Energy201111) has the best performance of all. this model also has already pass the test for it to be used.

S > Now, if we want to see the US of A energy consumption in the future, we could be simply using the Model Energy201111 to better prep the stock of the energy to be consumed