##Regresi Dengan Peubah Lag #Data Preparation #PACKAGE

library(dLagM)
## Loading required package: nardl
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Loading required package: dynlm
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(dynlm)
library(MLmetrics)
## 
## Attaching package: 'MLmetrics'
## The following object is masked from 'package:dLagM':
## 
##     MAPE
## The following object is masked from 'package:base':
## 
##     Recall
library(lmtest)
library(car)
## Loading required package: carData
library(readxl)
library(readr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:car':
## 
##     recode
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(knitr)
library(caTools)
library(ggplot2)
library(hrbrthemes)
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
##       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
##       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow

Data

Data yang digunakan adalah kumpulan data pemeriksaan suhu dari program data transportasi Departemen Transportasi Alaska yang berasal dari situs web kaggle https://www.kaggle.com/datasets/erikjamesmason/akdot-tdp-temperature-data-probes?select=TDP_2002_entire.csv. Variabel yang akan digunakan untuk analisis adalah OBSERVATION_TIME, BATTERY_VOLTAGE, dan REF_TEMP dengan jumlah amatan 91,026.

Input Data

data <- read_csv("C:/Users/ASUS/OneDrive/Documents/STK SMT 5/Tugas/Individu/MPDW/P4/TDP_2002_entire (1).csv")
## Rows: 5271 Columns: 24
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr  (1): OBSERVATION_TIME
## dbl (22): SITE_NUMBER, REF_TEMP, AMBIENT_AIR_TEMP, IN_PAVEMENT_TEMP, INTERNA...
## lgl  (1): TIMEZONE_FLAG
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
knitr::kable(head(data), align="l")
SITE_NUMBER OBSERVATION_TIME REF_TEMP AMBIENT_AIR_TEMP IN_PAVEMENT_TEMP INTERNAL_TEMP BATTERY_VOLTAGE TMR_PAV TMR_SUB_0 TMR_SUB_3 TMR_SUB_6 TMR_SUB_9 TMR_SUB_12 TMR_SUB_18 TMR_SUB_24 TMR_SUB_30 TMR_SUB_36 TMR_SUB_42 TMR_SUB_48 TMR_SUB_54 TMR_SUB_60 TMR_SUB_66 TMR_SUB_72 TIMEZONE_FLAG
110 2002-04-16-19-00-00 49.36 35.45 32 32 12.75 75.40 78.70 81.00 83.00 84.30 85.70 86.40 87.40 88.50 89.10 89.80 90.50 91.10 91.70 92.20 93.00 NA
110 2002-04-16-20-00-00 56.15 34.99 32 32 12.76 33.32 49.20 58.37 63.12 66.61 69.47 71.70 73.60 75.10 76.20 77.40 77.90 79.00 79.70 80.50 81.00 NA
110 2002-04-16-21-00-00 43.97 36.09 32 32 12.72 53.76 62.26 67.21 71.20 73.70 75.70 77.30 78.90 79.90 81.20 81.80 82.60 83.40 84.00 84.60 85.40 NA
110 2002-04-16-22-00-00 43.52 36.38 32 32 13.58 39.76 30.97 30.90 30.55 30.41 30.41 30.48 30.69 31.59 31.86 32.21 32.41 32.61 33.02 33.69 34.02 NA
110 2002-04-16-23-00-00 48.02 37.47 32 32 13.59 42.89 30.98 30.90 30.62 30.41 30.34 30.41 30.69 31.53 31.87 32.21 32.34 32.69 33.02 33.62 34.02 NA
110 2002-04-17-00-00-00 52.60 36.91 32 32 13.52 43.14 30.98 30.84 30.63 30.42 30.35 30.42 30.70 31.39 31.87 32.21 32.35 32.69 33.09 33.63 34.03 NA
str(data)
## spec_tbl_df [5,271 x 24] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ SITE_NUMBER     : num [1:5271] 110 110 110 110 110 110 110 110 110 110 ...
##  $ OBSERVATION_TIME: chr [1:5271] "2002-04-16-19-00-00" "2002-04-16-20-00-00" "2002-04-16-21-00-00" "2002-04-16-22-00-00" ...
##  $ REF_TEMP        : num [1:5271] 49.4 56.1 44 43.5 48 ...
##  $ AMBIENT_AIR_TEMP: num [1:5271] 35.5 35 36.1 36.4 37.5 ...
##  $ IN_PAVEMENT_TEMP: num [1:5271] 32 32 32 32 32 32 32 32 32 32 ...
##  $ INTERNAL_TEMP   : num [1:5271] 32 32 32 32 32 32 32 32 32 32 ...
##  $ BATTERY_VOLTAGE : num [1:5271] 12.8 12.8 12.7 13.6 13.6 ...
##  $ TMR_PAV         : num [1:5271] 75.4 33.3 53.8 39.8 42.9 ...
##  $ TMR_SUB_0       : num [1:5271] 78.7 49.2 62.3 31 31 ...
##  $ TMR_SUB_3       : num [1:5271] 81 58.4 67.2 30.9 30.9 ...
##  $ TMR_SUB_6       : num [1:5271] 83 63.1 71.2 30.6 30.6 ...
##  $ TMR_SUB_9       : num [1:5271] 84.3 66.6 73.7 30.4 30.4 ...
##  $ TMR_SUB_12      : num [1:5271] 85.7 69.5 75.7 30.4 30.3 ...
##  $ TMR_SUB_18      : num [1:5271] 86.4 71.7 77.3 30.5 30.4 ...
##  $ TMR_SUB_24      : num [1:5271] 87.4 73.6 78.9 30.7 30.7 ...
##  $ TMR_SUB_30      : num [1:5271] 88.5 75.1 79.9 31.6 31.5 ...
##  $ TMR_SUB_36      : num [1:5271] 89.1 76.2 81.2 31.9 31.9 ...
##  $ TMR_SUB_42      : num [1:5271] 89.8 77.4 81.8 32.2 32.2 ...
##  $ TMR_SUB_48      : num [1:5271] 90.5 77.9 82.6 32.4 32.3 ...
##  $ TMR_SUB_54      : num [1:5271] 91.1 79 83.4 32.6 32.7 ...
##  $ TMR_SUB_60      : num [1:5271] 91.7 79.7 84 33 33 ...
##  $ TMR_SUB_66      : num [1:5271] 92.2 80.5 84.6 33.7 33.6 ...
##  $ TMR_SUB_72      : num [1:5271] 93 81 85.4 34 34 ...
##  $ TIMEZONE_FLAG   : logi [1:5271] NA NA NA NA NA NA ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   SITE_NUMBER = col_double(),
##   ..   OBSERVATION_TIME = col_character(),
##   ..   REF_TEMP = col_double(),
##   ..   AMBIENT_AIR_TEMP = col_double(),
##   ..   IN_PAVEMENT_TEMP = col_double(),
##   ..   INTERNAL_TEMP = col_double(),
##   ..   BATTERY_VOLTAGE = col_double(),
##   ..   TMR_PAV = col_double(),
##   ..   TMR_SUB_0 = col_double(),
##   ..   TMR_SUB_3 = col_double(),
##   ..   TMR_SUB_6 = col_double(),
##   ..   TMR_SUB_9 = col_double(),
##   ..   TMR_SUB_12 = col_double(),
##   ..   TMR_SUB_18 = col_double(),
##   ..   TMR_SUB_24 = col_double(),
##   ..   TMR_SUB_30 = col_double(),
##   ..   TMR_SUB_36 = col_double(),
##   ..   TMR_SUB_42 = col_double(),
##   ..   TMR_SUB_48 = col_double(),
##   ..   TMR_SUB_54 = col_double(),
##   ..   TMR_SUB_60 = col_double(),
##   ..   TMR_SUB_66 = col_double(),
##   ..   TMR_SUB_72 = col_double(),
##   ..   TIMEZONE_FLAG = col_logical()
##   .. )
##  - attr(*, "problems")=<externalptr>
dim(data)
## [1] 5271   24
data$OBSERVATION_TIME <- as.Date(data$OBSERVATION_TIME,"%y/%m/%d")

t<-data$OBSERVATION_TIME
Xt<-data$BATTERY_VOLTAGE
Yt<-data$REF_TEMP

datareg1<-cbind(t, Xt, Yt)
datareg <- as.data.frame(datareg1)

Split Data dan Membuat data menjadi time series.

Dilakukan splitting data dengan data train dengan jumlah amatan 80% dari jumlah seluruh amatan yaitu 4.216 dan data test yaitu 20% dari jumlah seluruh amatan yaitu 1.055 amatan.

#Split data
train<-data[1:4216,]
test<-data[4217:5271,]

#data time series
train.ts<-ts(train)
test.ts<-ts(test)
data.ts<-ts(data)

Exploratory Data Analysis

Korelasi Peubah total_vaccinations (X) dan total_deaths (Y)

cor(Xt, Yt)
## [1] -0.9820873

Scatter Plot Peubah total_vaccinations (X) dan total_deaths (Y)

plot(Xt, Yt, pch = 20, col = "red", main = "Scatter Plot Ref Temp dan Battery Voltage")

Berdasarkan scatter plot terlihat bahwa hubungan antara Peubah BATTERY_VOLTAGE (X) dan REF_TEMP (Y) memiliki hubungan linier negatif dengan korelasi -0.9820873.

Model Regresi Linier Awal

model1 <- lm(data$REF_TEMP~data$BATTERY_VOLTAGE, data = data)
summary(model1)
## 
## Call:
## lm(formula = data$REF_TEMP ~ data$BATTERY_VOLTAGE, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -66.749  -1.060  -0.285   0.761  10.033 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          1062.6632     2.6543   400.4   <2e-16 ***
## data$BATTERY_VOLTAGE  -74.8384     0.1978  -378.3   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.419 on 5269 degrees of freedom
## Multiple R-squared:  0.9645, Adjusted R-squared:  0.9645 
## F-statistic: 1.431e+05 on 1 and 5269 DF,  p-value: < 2.2e-16

Berdasarkan output diatas, dapat diperoleh model regresi linier data deret waktu yaitu: Yt^ = 1062.6632 - 74.8384 (Xt)

Uji t = dilakukan untuk menguji signifikansi peubah penjelas terhdap variabel dependen. Berdasarkan output, dapat diperoleh pada peubah penjelas BATTERY_VOLTAGE memiliki P-Value<0.05. Maka dapat disimpulkan bahwa peubah penjelas BATTERY_VOLTAGE berpengaruh signifikan pada taraf nyata 5%.

Nilai R-Squared pada model regresi linier deret waktu yaitu 96,45%, artinya keragaman Y yang mampu dijelaskan oleh peubah penjelas X adalah sebesar 96.45%.

Interpretasi Model Regresi

Nilai intersep sebesar 1062.6632 yang artinya jika peubah penjelas bernilai nol, maka dugaan nilai IPM sebesar 1062.6632.

Pengaruh peubah BATTERY_VOLTAGE terhadap REF_ _TEMP bernilai negatif sebesar - 74.8384, hal ini menunjukkan bahwa jika jumlah BATTERY_VOLTAGE berkurang satu maka dugaan jumlah REF_TEMP berkurang sebesar - 74.8384.

Model KOYCK

Metode Koyck didasarkan asumsi bahwa semakin jauh jarak lag peubah independen dari periode sekarang maka semakin kecil pengaruh peubah lag terhadap peubah dependen

Koyck mengusulkan suatu metode untuk menduga model dinamis distributed lag dengan mengasumsikan bahwa semua koefisien β mempunyai tanda sama.

Model Koyck merupakan jenis paling umum dari model infinite distributed lag dan juga dikenal sebagai geometric lag.

model.koyck = dLagM::koyckDlm(x = train$BATTERY_VOLTAGE, y = train$REF_TEMP)
summary(model.koyck)
## 
## Call:
## "Y ~ (Intercept) + Y.1 + X.t"
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -67.6074  -1.8022  -0.4625   1.1787  60.4005 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -513.17083   72.67834  -7.061 1.93e-12 ***
## Y.1            1.40996    0.06453  21.850  < 2e-16 ***
## X.t           36.46061    5.13679   7.098 1.48e-12 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.53 on 4212 degrees of freedom
## Multiple R-Squared: 0.8213,  Adjusted R-squared: 0.8212 
## Wald test: 1.076e+04 on 2 and 4212 DF,  p-value: < 2.2e-16 
## 
## Diagnostic tests:
## NULL
## 
##                             alpha     beta      phi
## Geometric coefficients:  1251.748 36.46061 1.409963
AIC(model.koyck)
## [1] 26383.92
BIC(model.koyck)
## [1] 26409.31

Ramalan KOYCK

(fore.koyck <- forecast(model = model.koyck, x=test$BATTERY_VOLTAGE, h=1055))
## $forecasts
##    [1]   6.472232e+01   6.446980e+01   6.338456e+01   6.148979e+01
##    [5]   5.808904e+01   5.037724e+01   3.658705e+01   1.568495e+01
##    [9]  -1.488006e+01  -5.834022e+01  -1.199821e+02  -2.065302e+02
##   [13]  -3.143403e+02  -4.656193e+02  -6.785526e+02  -9.780516e+02
##   [17]  -1.399970e+03  -1.994129e+03  -2.831144e+03  -4.010574e+03
##   [21]  -5.673528e+03  -8.018597e+03  -1.132615e+04  -1.599078e+04
##   [25]  -2.256882e+04  -3.184399e+04  -4.492237e+04  -6.336240e+04
##   [29]  -8.936254e+04  -1.260287e+05  -1.777260e+05  -2.506161e+05
##   [33]  -3.533878e+05  -4.982917e+05  -7.026002e+05  -9.906678e+05
##   [37]  -1.396832e+06  -1.969511e+06  -2.776968e+06  -3.915456e+06
##   [41]  -5.520686e+06  -7.784002e+06  -1.097520e+07  -1.547466e+07
##   [45]  -2.181875e+07  -3.076367e+07  -4.337569e+07  -6.115818e+07
##   [49]  -8.623084e+07  -1.215824e+08  -1.714267e+08  -2.417054e+08
##   [53]  -3.407959e+08  -4.805098e+08  -6.775012e+08  -9.552520e+08
##   [57]  -1.346870e+09  -1.899038e+09  -2.677574e+09  -3.775282e+09
##   [61]  -5.323010e+09  -7.505249e+09  -1.058213e+10  -1.492041e+10
##   [65]  -2.103724e+10  -2.966174e+10  -4.182196e+10  -5.896744e+10
##   [69]  -8.314194e+10  -1.172271e+11  -1.652859e+11  -2.330471e+11
##   [73]  -3.285879e+11  -4.632969e+11  -6.532317e+11  -9.210329e+11
##   [77]  -1.298623e+12  -1.831011e+12  -2.581658e+12  -3.640043e+12
##   [81]  -5.132328e+12  -7.236395e+12  -1.020305e+13  -1.438593e+13
##   [85]  -2.028364e+13  -2.859919e+13  -4.032381e+13  -5.685510e+13
##   [89]  -8.016361e+13  -1.130278e+14  -1.593650e+14  -2.246989e+14
##   [93]  -3.168172e+14  -4.467006e+14  -6.298316e+14  -8.880395e+14
##   [97]  -1.252103e+15  -1.765420e+15  -2.489177e+15  -3.509649e+15
##  [101]  -4.948477e+15  -6.977172e+15  -9.837558e+15  -1.387060e+16
##  [105]  -1.955703e+16  -2.757470e+16  -3.887933e+16  -5.481843e+16
##  [109]  -7.729198e+16  -1.089789e+17  -1.536562e+17  -2.166497e+17
##  [113]  -3.054681e+17  -4.306989e+17  -6.072697e+17  -8.562280e+17
##  [117]  -1.207250e+18  -1.702179e+18  -2.400010e+18  -3.383926e+18
##  [121]  -4.771212e+18  -6.727235e+18  -9.485155e+18  -1.337372e+19
##  [125]  -1.885646e+19  -2.658692e+19  -3.748658e+19  -5.285471e+19
##  [129]  -7.452322e+19  -1.050750e+20  -1.481519e+20  -2.088888e+20
##  [133]  -2.945256e+20  -4.152703e+20  -5.855160e+20  -8.255561e+20
##  [137]  -1.164004e+21  -1.641203e+21  -2.314036e+21  -3.262707e+21
##  [141]  -4.600297e+21  -6.486251e+21  -9.145377e+21  -1.289465e+22
##  [145]  -1.818098e+22  -2.563452e+22  -3.614373e+22  -5.096135e+22
##  [149]  -7.185363e+22  -1.013110e+23  -1.428448e+23  -2.014060e+23
##  [153]  -2.839750e+23  -4.003944e+23  -5.645415e+23  -7.959829e+23
##  [157]  -1.122307e+24  -1.582412e+24  -2.231143e+24  -3.145829e+24
##  [161]  -4.435505e+24  -6.253899e+24  -8.817770e+24  -1.243273e+25
##  [165]  -1.752970e+25  -2.471624e+25  -3.484899e+25  -4.913580e+25
##  [169]  -6.927968e+25  -9.768182e+25  -1.377278e+26  -1.941912e+26
##  [173]  -2.738024e+26  -3.860514e+26  -5.443184e+26  -7.674691e+26
##  [177]  -1.082103e+27  -1.525726e+27  -2.151218e+27  -3.033139e+27
##  [181]  -4.276615e+27  -6.029871e+27  -8.501898e+27  -1.198737e+28
##  [185]  -1.690175e+28  -2.383085e+28  -3.360062e+28  -4.737565e+28
##  [189]  -6.679794e+28  -9.418265e+28  -1.327941e+29  -1.872348e+29
##  [193]  -2.639943e+29  -3.722223e+29  -5.248198e+29  -7.399767e+29
##  [197]  -1.043340e+30  -1.471071e+30  -2.074157e+30  -2.924486e+30
##  [201]  -4.123418e+30  -5.813868e+30  -8.197342e+30  -1.155795e+31
##  [205]  -1.629629e+31  -2.297717e+31  -3.239698e+31  -4.567855e+31
##  [209]  -6.440509e+31  -9.080882e+31  -1.280371e+32  -1.805277e+32
##  [213]  -2.545374e+32  -3.588885e+32  -5.060196e+32  -7.134691e+32
##  [217]  -1.005965e+33  -1.418374e+33  -1.999856e+33  -2.819724e+33
##  [221]  -3.975708e+33  -5.605603e+33  -7.903696e+33  -1.114392e+34
##  [225]  -1.571252e+34  -2.215408e+34  -3.123645e+34  -4.404225e+34
##  [229]  -6.209796e+34  -8.755586e+34  -1.234506e+35  -1.740608e+35
##  [233]  -2.454193e+35  -3.460323e+35  -4.878929e+35  -6.879112e+35
##  [237]  -9.699296e+35  -1.367565e+36  -1.928217e+36  -2.718716e+36
##  [241]  -3.833290e+36  -5.404798e+36  -7.620568e+36  -1.074472e+37
##  [245]  -1.514967e+37  -2.136048e+37  -3.011749e+37  -4.246456e+37
##  [249]  -5.987348e+37  -8.441942e+37  -1.190283e+38  -1.678255e+38
##  [253]  -2.366279e+38  -3.336367e+38  -4.704155e+38  -6.632687e+38
##  [257]  -9.351846e+38  -1.318576e+39  -1.859144e+39  -2.621325e+39
##  [261]  -3.695973e+39  -5.211187e+39  -7.347583e+39  -1.035982e+40
##  [265]  -1.460697e+40  -2.059530e+40  -2.903862e+40  -4.094339e+40
##  [269]  -5.772868e+40  -8.139533e+40  -1.147644e+41  -1.618137e+41
##  [273]  -2.281514e+41  -3.216851e+41  -4.535642e+41  -6.395090e+41
##  [277]  -9.016843e+41  -1.271342e+42  -1.792546e+42  -2.527424e+42
##  [281]  -3.563575e+42  -5.024511e+42  -7.084377e+42  -9.988713e+42
##  [285]  -1.408372e+43  -1.985753e+43  -2.799839e+43  -3.947671e+43
##  [289]  -5.566072e+43  -7.847958e+43  -1.106533e+44  -1.560172e+44
##  [293]  -2.199785e+44  -3.101616e+44  -4.373166e+44  -6.166004e+44
##  [297]  -8.693840e+44  -1.225800e+45  -1.728333e+45  -2.436886e+45
##  [301]  -3.435920e+45  -4.844522e+45  -6.830599e+45  -9.630895e+45
##  [305]  -1.357921e+46  -1.914619e+46  -2.699543e+46  -3.806257e+46
##  [309]  -5.366683e+46  -7.566827e+46  -1.066895e+47  -1.504283e+47
##  [313]  -2.120984e+47  -2.990510e+47  -4.216510e+47  -5.945125e+47
##  [317]  -8.382408e+47  -1.181889e+48  -1.666420e+48  -2.349592e+48
##  [321]  -3.312838e+48  -4.670981e+48  -6.585913e+48  -9.285896e+48
##  [325]  -1.309277e+49  -1.846033e+49  -2.602840e+49  -3.669909e+49
##  [329]  -5.174437e+49  -7.295767e+49  -1.028677e+50  -1.450396e+50
##  [333]  -2.045006e+50  -2.883383e+50  -4.065465e+50  -5.732157e+50
##  [337]  -8.082132e+50  -1.139551e+51  -1.606725e+51  -2.265424e+51
##  [341]  -3.194165e+51  -4.503656e+51  -6.349991e+51  -8.953255e+51
##  [345]  -1.262376e+52  -1.779904e+52  -2.509600e+52  -3.538445e+52
##  [349]  -4.989078e+52  -7.034417e+52  -9.918271e+52  -1.398440e+53
##  [353]  -1.971749e+53  -2.780094e+53  -3.919832e+53  -5.526819e+53
##  [357]  -7.792613e+53  -1.098730e+54  -1.549169e+54  -2.184272e+54
##  [361]  -3.079743e+54  -4.342326e+54  -6.122521e+54  -8.632530e+54
##  [365]  -1.217155e+55  -1.716144e+55  -2.419701e+55  -3.411690e+55
##  [369]  -4.810358e+55  -6.782429e+55  -9.562977e+55  -1.348345e+56
##  [373]  -1.901117e+56  -2.680505e+56  -3.779415e+56  -5.328837e+56
##  [377]  -7.513465e+56  -1.059371e+57  -1.493675e+57  -2.106027e+57
##  [381]  -2.969420e+57  -4.186774e+57  -5.903199e+57  -8.323295e+57
##  [385]  -1.173554e+58  -1.654668e+58  -2.333022e+58  -3.289476e+58
##  [389]  -4.638041e+58  -6.539468e+58  -9.220411e+58  -1.300044e+59
##  [393]  -1.833015e+59  -2.584484e+59  -3.644028e+59  -5.137946e+59
##  [397]  -7.244317e+59  -1.021422e+60  -1.440168e+60  -2.030584e+60
##  [401]  -2.863049e+60  -4.036795e+60  -5.691734e+60  -8.025136e+60
##  [405]  -1.131515e+61  -1.595395e+61  -2.249448e+61  -3.171640e+61
##  [409]  -4.471896e+61  -6.305210e+61  -8.890116e+61  -1.253474e+62
##  [413]  -1.767352e+62  -2.491902e+62  -3.513491e+62  -4.953894e+62
##  [417]  -6.984810e+62  -9.848326e+62  -1.388578e+63  -1.957844e+63
##  [421]  -2.760489e+63  -3.892188e+63  -5.487843e+63  -7.737659e+63
##  [425]  -1.090982e+64  -1.538244e+64  -2.168868e+64  -3.058025e+64
##  [429]  -4.311703e+64  -6.079344e+64  -8.571653e+64  -1.208572e+65
##  [433]  -1.704042e+65  -2.402637e+65  -3.387630e+65  -4.776435e+65
##  [437]  -6.734599e+65  -9.495538e+65  -1.338836e+66  -1.887710e+66
##  [441]  -2.661602e+66  -3.752762e+66  -5.291257e+66  -7.460479e+66
##  [445]  -1.051900e+67  -1.483141e+67  -2.091175e+67  -2.948480e+67
##  [449]  -4.157249e+67  -5.861569e+67  -8.264598e+67  -1.165278e+68
##  [453]  -1.643000e+68  -2.316569e+68  -3.266278e+68  -4.605333e+68
##  [457]  -6.493351e+68  -9.155388e+68  -1.290876e+69  -1.820088e+69
##  [461]  -2.566258e+69  -3.618330e+69  -5.101713e+69  -7.193229e+69
##  [465]  -1.014219e+70  -1.430012e+70  -2.016264e+70  -2.842859e+70
##  [469]  -4.008327e+70  -5.651595e+70  -7.968542e+70  -1.123535e+71
##  [473]  -1.584144e+71  -2.233585e+71  -3.149273e+71  -4.440360e+71
##  [477]  -6.260745e+71  -8.827422e+71  -1.244634e+72  -1.754889e+72
##  [481]  -2.474329e+72  -3.488714e+72  -4.918959e+72  -6.935552e+72
##  [485]  -9.778875e+72  -1.378786e+73  -1.944037e+73  -2.741022e+73
##  [489]  -3.864740e+73  -5.449143e+73  -7.683092e+73  -1.083288e+74
##  [493]  -1.527396e+74  -2.153573e+74  -3.036459e+74  -4.281297e+74
##  [497]  -6.036472e+74  -8.511205e+74  -1.200049e+75  -1.692025e+75
##  [501]  -2.385693e+75  -3.363740e+75  -4.742751e+75  -6.687106e+75
##  [505]  -9.428574e+75  -1.329395e+76  -1.874398e+76  -2.642832e+76
##  [509]  -3.726297e+76  -5.253943e+76  -7.407867e+76  -1.044482e+77
##  [513]  -1.472682e+77  -2.076427e+77  -2.927687e+77  -4.127931e+77
##  [517]  -5.820232e+77  -8.206315e+77  -1.157060e+78  -1.631413e+78
##  [521]  -2.300233e+78  -3.243244e+78  -4.572855e+78  -6.447559e+78
##  [525]  -9.090823e+78  -1.281773e+79  -1.807253e+79  -2.548160e+79
##  [529]  -3.592813e+79  -5.065735e+79  -7.142501e+79  -1.007067e+80
##  [533]  -1.419927e+80  -2.002045e+80  -2.822811e+80  -3.980060e+80
##  [537]  -5.611739e+80  -7.912347e+80  -1.115612e+81  -1.572972e+81
##  [541]  -2.217833e+81  -3.127064e+81  -4.409046e+81  -6.216594e+81
##  [545]  -8.765170e+81  -1.235857e+82  -1.742513e+82  -2.456880e+82
##  [549]  -3.464111e+82  -4.884270e+82  -6.886642e+82  -9.709913e+82
##  [553]  -1.369062e+83  -1.930328e+83  -2.721692e+83  -3.837486e+83
##  [557]  -5.410715e+83  -7.628910e+83  -1.075648e+84  -1.516625e+84
##  [561]  -2.138386e+84  -3.015046e+84  -4.251104e+84  -5.993902e+84
##  [565]  -8.451183e+84  -1.191586e+85  -1.680093e+85  -2.368869e+85
##  [569]  -3.340019e+85  -4.709305e+85  -6.639947e+85  -9.362083e+85
##  [573]  -1.320020e+86  -1.861179e+86  -2.624195e+86  -3.700019e+86
##  [577]  -5.216891e+86  -7.355626e+86  -1.037116e+87  -1.462296e+87
##  [581]  -2.061784e+87  -2.907040e+87  -4.098821e+87  -5.779188e+87
##  [585]  -8.148443e+87  -1.148901e+88  -1.619908e+88  -2.284011e+88
##  [589]  -3.220372e+88  -4.540607e+88  -6.402090e+88  -9.026713e+88
##  [593]  -1.272734e+89  -1.794508e+89  -2.530190e+89  -3.567476e+89
##  [597]  -5.030011e+89  -7.092132e+89  -9.999647e+89  -1.409914e+90
##  [601]  -1.987927e+90  -2.802904e+90  -3.951992e+90  -5.572165e+90
##  [605]  -7.856548e+90  -1.107745e+91  -1.561879e+91  -2.202193e+91
##  [609]  -3.105012e+91  -4.377953e+91  -6.172754e+91  -8.703357e+91
##  [613]  -1.227142e+92  -1.730225e+92  -2.439554e+92  -3.439681e+92
##  [617]  -4.849825e+92  -6.838076e+92  -9.641438e+92  -1.359407e+93
##  [621]  -1.916715e+93  -2.702498e+93  -3.810423e+93  -5.372558e+93
##  [625]  -7.575110e+93  -1.068063e+94  -1.505930e+94  -2.123306e+94
##  [629]  -2.993783e+94  -4.221125e+94  -5.951632e+94  -8.391584e+94
##  [633]  -1.183183e+95  -1.668244e+95  -2.352164e+95  -3.316465e+95
##  [637]  -4.676094e+95  -6.593122e+95  -9.296061e+95  -1.310711e+96
##  [641]  -1.848054e+96  -2.605689e+96  -3.673926e+96  -5.180101e+96
##  [645]  -7.303753e+96  -1.029803e+97  -1.451984e+97  -2.047244e+97
##  [649]  -2.886540e+97  -4.069915e+97  -5.738432e+97  -8.090979e+97
##  [653]  -1.140799e+98  -1.608484e+98  -2.267904e+98  -3.197662e+98
##  [657]  -4.508586e+98  -6.356942e+98  -8.963056e+98  -1.263758e+99
##  [661]  -1.781853e+99  -2.512347e+99  -3.542318e+99  -4.994539e+99
##  [665]  -7.042117e+99  -9.929128e+99 -1.399971e+100 -1.973908e+100
##  [669] -2.783138e+100 -3.924122e+100 -5.532869e+100 -7.801143e+100
##  [673] -1.099933e+101 -1.550865e+101 -2.186663e+101 -3.083115e+101
##  [677] -4.347079e+101 -6.129223e+101 -8.641980e+101 -1.218488e+102
##  [681] -1.718023e+102 -2.422350e+102 -3.415424e+102 -4.815624e+102
##  [685] -6.789853e+102 -9.573445e+102 -1.349821e+103 -1.903198e+103
##  [689] -2.683440e+103 -3.783552e+103 -5.334670e+103 -7.521690e+103
##  [693] -1.060531e+104 -1.495310e+104 -2.108332e+104 -2.972671e+104
##  [697] -4.191357e+104 -5.909661e+104 -8.332406e+104 -1.174839e+105
##  [701] -1.656480e+105 -2.335576e+105 -3.293077e+105 -4.643118e+105
##  [705] -6.546626e+105 -9.230504e+105 -1.301467e+106 -1.835021e+106
##  [709] -2.587313e+106 -3.648017e+106 -5.143571e+106 -7.252246e+106
##  [713] -1.022540e+107 -1.441744e+107 -2.032807e+107 -2.866183e+107
##  [717] -4.041214e+107 -5.697964e+107 -8.033921e+107 -1.132754e+108
##  [721] -1.597141e+108 -2.251911e+108 -3.175112e+108 -4.476791e+108
##  [725] -6.312112e+108 -8.899847e+108 -1.254846e+109 -1.769287e+109
##  [729] -2.494630e+109 -3.517337e+109 -4.959317e+109 -6.992455e+109
##  [733] -9.859107e+109 -1.390098e+110 -1.959987e+110 -2.763511e+110
##  [737] -3.896449e+110 -5.493851e+110 -7.746129e+110 -1.092176e+111
##  [741] -1.539928e+111 -2.171242e+111 -3.061372e+111 -4.316423e+111
##  [745] -6.085999e+111 -8.581036e+111 -1.209895e+112 -1.705907e+112
##  [749] -2.405267e+112 -3.391339e+112 -4.781663e+112 -6.741971e+112
##  [753] -9.505932e+112 -1.340302e+113 -1.889776e+113 -2.664516e+113
##  [757] -3.756870e+113 -5.297049e+113 -7.468646e+113 -1.053052e+114
##  [761] -1.484765e+114 -2.093464e+114 -2.951707e+114 -4.161799e+114
##  [765] -5.867985e+114 -8.273645e+114 -1.166554e+115 -1.644798e+115
##  [769] -2.319105e+115 -3.269853e+115 -4.610374e+115 -6.500459e+115
##  [773] -9.165409e+115 -1.292289e+116 -1.822081e+116 -2.569067e+116
##  [777] -3.622291e+116 -5.107297e+116 -7.201103e+116 -1.015329e+117
##  [781] -1.431577e+117 -2.018471e+117 -2.845971e+117 -4.012715e+117
##  [785] -5.657781e+117 -7.977265e+117 -1.124765e+118 -1.585878e+118
##  [789] -2.236030e+118 -3.152720e+118 -4.445220e+118 -6.267598e+118
##  [793] -8.837085e+118 -1.245997e+119 -1.756810e+119 -2.477038e+119
##  [797] -3.492532e+119 -4.924343e+119 -6.943144e+119 -9.789579e+119
##  [801] -1.380295e+120 -1.946165e+120 -2.744022e+120 -3.868971e+120
##  [805] -5.455107e+120 -7.691502e+120 -1.084474e+121 -1.529068e+121
##  [809] -2.155930e+121 -3.039783e+121 -4.285983e+121 -6.043080e+121
##  [813] -8.520521e+121 -1.201362e+122 -1.693877e+122 -2.388305e+122
##  [817] -3.367422e+122 -4.747943e+122 -6.694426e+122 -9.438895e+122
##  [821] -1.330850e+123 -1.876450e+123 -2.645725e+123 -3.730376e+123
##  [825] -5.259694e+123 -7.415976e+123 -1.045626e+124 -1.474294e+124
##  [829] -2.078700e+124 -2.930892e+124 -4.132450e+124 -5.826603e+124
##  [833] -8.215298e+124 -1.158327e+125 -1.633199e+125 -2.302751e+125
##  [837] -3.246794e+125 -4.577861e+125 -6.454617e+125 -9.100774e+125
##  [841] -1.283176e+126 -1.809231e+126 -2.550950e+126 -3.596746e+126
##  [845] -5.071280e+126 -7.150320e+126 -1.008169e+127 -1.421481e+127
##  [849] -2.004237e+127 -2.825901e+127 -3.984417e+127 -5.617882e+127
##  [853] -7.921008e+127 -1.116833e+128 -1.574694e+128 -2.220261e+128
##  [857] -3.130487e+128 -4.413872e+128 -6.223399e+128 -8.774765e+128
##  [861] -1.237210e+129 -1.744421e+129 -2.459569e+129 -3.467903e+129
##  [865] -4.889616e+129 -6.894180e+129 -9.720542e+129 -1.370561e+130
##  [869] -1.932441e+130 -2.724671e+130 -3.841686e+130 -5.416637e+130
##  [873] -7.637261e+130 -1.076826e+131 -1.518285e+131 -2.140727e+131
##  [877] -3.018346e+131 -4.255758e+131 -6.000463e+131 -8.460434e+131
##  [881] -1.192890e+132 -1.681932e+132 -2.371462e+132 -3.343675e+132
##  [885] -4.714460e+132 -6.647216e+132 -9.372331e+132 -1.321464e+133
##  [889] -1.863217e+133 -2.627067e+133 -3.704069e+133 -5.222602e+133
##  [893] -7.363678e+133 -1.038252e+134 -1.463897e+134 -2.064041e+134
##  [897] -2.910223e+134 -4.103307e+134 -5.785514e+134 -8.157363e+134
##  [901] -1.150158e+135 -1.621681e+135 -2.286511e+135 -3.223897e+135
##  [905] -4.545577e+135 -6.409098e+135 -9.036594e+135 -1.274127e+136
##  [909] -1.796472e+136 -2.532960e+136 -3.571381e+136 -5.035517e+136
##  [913] -7.099895e+136 -1.001059e+137 -1.411457e+137 -1.990103e+137
##  [917] -2.805972e+137 -3.956318e+137 -5.578264e+137 -7.865149e+137
##  [921] -1.108957e+138 -1.563589e+138 -2.204604e+138 -3.108410e+138
##  [925] -4.382745e+138 -6.179511e+138 -8.712884e+138 -1.228485e+139
##  [929] -1.732119e+139 -2.442224e+139 -3.443447e+139 -4.855134e+139
##  [933] -6.845562e+139 -9.651992e+139 -1.360896e+140 -1.918813e+140
##  [937] -2.705456e+140 -3.814594e+140 -5.378439e+140 -7.583402e+140
##  [941] -1.069232e+141 -1.507578e+141 -2.125630e+141 -2.997061e+141
##  [945] -4.225746e+141 -5.958147e+141 -8.400770e+141 -1.184478e+142
##  [949] -1.670070e+142 -2.354738e+142 -3.320095e+142 -4.681213e+142
##  [953] -6.600339e+142 -9.306237e+142 -1.312145e+143 -1.850077e+143
##  [957] -2.608541e+143 -3.677947e+143 -5.185771e+143 -7.311748e+143
##  [961] -1.030930e+144 -1.453573e+144 -2.049485e+144 -2.889699e+144
##  [965] -4.074371e+144 -5.744714e+144 -8.099836e+144 -1.142047e+145
##  [969] -1.610245e+145 -2.270387e+145 -3.201162e+145 -4.513522e+145
##  [973] -6.363901e+145 -8.972867e+145 -1.265141e+146 -1.783803e+146
##  [977] -2.515097e+146 -3.546195e+146 -5.000006e+146 -7.049826e+146
##  [981] -9.939997e+146 -1.401503e+147 -1.976068e+147 -2.786184e+147
##  [985] -3.928418e+147 -5.538926e+147 -7.809683e+147 -1.101137e+148
##  [989] -1.552563e+148 -2.189056e+148 -3.086490e+148 -4.351838e+148
##  [993] -6.135932e+148 -8.651440e+148 -1.219821e+149 -1.719904e+149
##  [997] -2.425001e+149 -3.419163e+149 -4.820895e+149 -6.797286e+149
## [1001] -9.583925e+149 -1.351298e+150 -1.905281e+150 -2.686377e+150
## [1005] -3.787693e+150 -5.340509e+150 -7.529923e+150 -1.061692e+151
## [1009] -1.496946e+151 -2.110640e+151 -2.975925e+151 -4.195945e+151
## [1013] -5.916130e+151 -8.341527e+151 -1.176125e+152 -1.658293e+152
## [1017] -2.338132e+152 -3.296681e+152 -4.648200e+152 -6.553792e+152
## [1021] -9.240608e+152 -1.302892e+153 -1.837030e+153 -2.590145e+153
## [1025] -3.652010e+153 -5.149201e+153 -7.260185e+153 -1.023660e+154
## [1029] -1.443323e+154 -2.035032e+154 -2.869321e+154 -4.045638e+154
## [1033] -5.704201e+154 -8.042715e+154 -1.133993e+155 -1.598889e+155
## [1037] -2.254376e+155 -3.178587e+155 -4.481692e+155 -6.319022e+155
## [1041] -8.909590e+155 -1.256220e+156 -1.771224e+156 -2.497361e+156
## [1045] -3.521187e+156 -4.964745e+156 -7.000110e+156 -9.869899e+156
## [1049] -1.391620e+157 -1.962133e+157 -2.766536e+157 -3.900714e+157
## [1053] -5.499864e+157 -7.754608e+157 -1.093371e+158
## 
## $call
## forecast.koyckDlm(model = model.koyck, x = test$BATTERY_VOLTAGE, 
##     h = 1055)
## 
## attr(,"class")
## [1] "forecast.koyckDlm" "dLagM"

MAPE testing dan akurasi Data Training

#mape data testing
mape.koyck <- MAPE(fore.koyck$forecasts, test$REF_TEMP)

#akurasi data training
mape_train <- dLagM::GoF(model.koyck)["MAPE"]

c("MAPE_testing" = mape.koyck, "MAPE_training" = mape_train)
## $MAPE_testing
## [1] 7.067076e+153
## 
## $MAPE_training.MAPE
## [1] 0.0487201

Regression with Distributed Lag

Regression with Distributed Lag (lag=2) -> estimasi parameter menggunakan least square

model.dlm = dLagM::dlm(x = train$BATTERY_VOLTAGE, y = train$REF_TEMP , q = 2)
summary(model.dlm)
## 
## Call:
## lm(formula = model.formula, data = design)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -66.858  -0.977  -0.269   0.735  10.976 
## 
## Coefficients:
##              Estimate Std. Error  t value Pr(>|t|)    
## (Intercept) 1058.7185     2.4999  423.508   <2e-16 ***
## x.t          -84.9375     0.6298 -134.859   <2e-16 ***
## x.1            0.4987     0.9359    0.533    0.594    
## x.2            9.8943     0.6287   15.737   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.017 on 4210 degrees of freedom
## Multiple R-squared:  0.9762, Adjusted R-squared:  0.9762 
## F-statistic: 5.768e+04 on 3 and 4210 DF,  p-value: < 2.2e-16
## 
## AIC and BIC values for the model:
##        AIC      BIC
## 1 17876.94 17908.67
AIC(model.dlm)
## [1] 17876.94
BIC(model.dlm)
## [1] 17908.67

ramalan

(fore.dlm <- forecast(model = model.dlm, x=test$BATTERY_VOLTAGE, h=1055))
## $forecasts
##    [1]  64.73170  63.99124  65.89286  66.83120  68.32708  75.01317  81.57040
##    [8]  84.13647  85.87311  86.31175  86.85931  85.90601  52.68641  51.28108
##   [15]  54.30043  52.80455  52.06409  50.56821  48.97838  47.48749  47.69534
##   [22]  48.74260  51.28574  53.71997  55.95631  56.49390  57.89083  57.78192
##   [29]  58.43341  74.56655  72.67412  68.25606  66.77015  66.22757  64.73170
##   [36]  64.84061  64.18912  67.59161  71.06811  79.14615  82.94739  86.17991
##   [43]  87.35901  88.55308  87.49584  84.75482  84.86872  83.46680  81.77802
##   [50]  80.28713  78.79623  75.60659  73.27630  71.13890  71.45069  58.15751
##   [57]  57.38792  55.57848  53.99862  50.15748  48.68155  46.63811  45.15220
##   [64]  42.91088  42.27435  42.57616  42.67510  42.67510  42.67510  41.82573
##   [71]  41.83072  43.62841  48.71469  55.28189  59.74459  61.47126  59.16389
##   [78]  58.02766  57.38116  58.33447  57.57905  54.93696  53.35211  50.26141
##   [85]  47.08174  44.94933  51.30569  51.56761  50.87501  50.02564  50.88000
##   [92]  50.97396  50.87501  52.57377  53.41317  53.21030  51.41260  51.42258
##   [99]  52.46984  53.31423  52.36092  54.81509  35.36344  36.03068  40.00012
##  [106]  44.13808  54.10777  60.34822  63.36790  66.79830  64.57990  64.09516
##  [113]  64.29305  64.29305  62.59430  60.90552  56.86650  53.69182  51.65835
##  [120]  48.67158  46.44023  45.15220  43.76025  43.96811  44.16600  44.16600
##  [127]  45.01537  45.85976  46.60521  44.80253  43.01481  40.67454  39.18863
##  [134]  37.79668  36.30579  35.66427  35.01777  33.42295  33.53186  32.03100
##  [141]  32.04097  32.23885  33.08823  34.78199  36.37183  40.41085  48.68179
##  [148]  53.23346  48.81661  43.99603  41.86860  39.83015  39.29256  38.74500
##  [155]  37.15018  35.56034  34.91883  33.42295  31.83311  32.04097  30.54010
##  [162]  29.70070  29.90357  29.15314  29.15813  30.10644  30.95083  58.87629
##  [169] 113.82220  57.57170  53.99772  64.36408  65.74107  69.48326  73.50732
##  [176]  72.13830  69.94982  68.35998  66.86909  65.37820  63.03793  62.40140
##  [183]  60.15509  59.41961  58.02268  57.28222  57.48509  56.73466  57.58902
##  [190]  56.83360  68.63090  68.66003  66.42546  66.43045  66.52939  65.68001
##  [197]  66.53438  65.77896  66.53438  69.17646  71.61068  76.39515  79.46590
##  [204]  79.70168  78.45154  78.35759  76.75778  75.06900  73.57811  72.93659
##  [211]  69.74196  68.16210  68.56784  67.91635  67.07196  68.87464  68.11424
##  [218]  66.22259  64.63275  62.29248  63.35470  64.49592  66.94012  68.52497
##  [225]  70.76629  72.25220  72.79477  71.74253  69.94982  67.51061  66.87408
##  [232]  64.62777  65.59104  65.03351  64.93955  64.18912  61.64598  61.75988
##  [239]  62.05671  62.90609  67.14798  69.57223  75.00818  78.07395  80.75891
##  [246]  82.89132  82.48059  82.18376  77.08751  74.56930  74.32854  73.78098
##  [253]  73.88491  71.43573  70.60131  69.20437  54.02453  54.31217  56.94251
##  [260]  57.78690  61.08048  64.35909  64.79275  64.39199  65.14243  66.83619
##  [267]  65.87790  40.20374  39.60290  42.57616  42.67510  41.82573  41.83072
##  [274]  41.92966  41.92966  42.77903  42.77405  42.67510  43.52448  43.51949
##  [281]  45.96868  53.59810  54.10577  54.05967  54.80512  56.39994  54.59227
##  [288]  52.70561  50.36534  48.87944  49.18624  50.23350  49.37914  49.28518
##  [295]  46.83600  46.85095  48.84653  50.53531  48.62870  46.74204  44.40177
##  [302]  42.06649  42.37828  49.47011  57.07459  60.48505  72.31027  71.74076
##  [309]  72.80475  74.48854  75.88049  75.67263  75.47475  74.62537  73.78098
##  [316]  73.03553  72.29009  69.84589  69.11042  68.56286  68.66679  67.91635
##  [323]  66.22259  66.33150  66.52939  68.22814  69.06754  71.41280  77.24452
##  [330]  60.77466  57.62868  56.12604  55.59344  53.44607  49.31310  47.93610
##  [337]  45.04329  41.86362  40.58058  39.28758  38.64606  38.84893  38.09850
##  [344]  38.10348  39.05180  38.19744  37.25411  37.35804  39.15573  39.14576
##  [351]  42.34537  46.57231  52.09723  71.95262  72.83910  70.45451  72.80475
##  [358]  75.33791  76.72488  78.11683  78.75835  76.85672  74.21963  73.58310
##  [365]  70.48741  69.75692  68.45893  67.71847  67.07196  67.17589  68.12421
##  [372]  67.26985  66.32652  66.43045  66.52939  68.22814  67.36879  68.02527
##  [379]  66.42047  68.03025  69.91692  84.14844  85.56454  84.72192  85.36842
##  [386]  81.86699  78.39049  75.40871  73.27630  71.13890  69.75194  68.35998
##  [393]  67.71847  67.07196  66.32652  66.43045  64.83064  66.53936  65.87790
##  [400]  64.83562  65.78893  65.03351  66.63830  66.72727  67.37876  65.67503
##  [407]  66.43543  64.08021  63.14685  62.59929  61.00446  60.26400  58.76812
##  [414]  57.17829  55.68740  55.89525  55.24376  54.39937  54.50330  55.45162
##  [421]  56.29601  59.58958  61.16945  65.85996  69.02965  71.81355  70.54846
##  [428]  68.45893  68.56784  67.91635  66.22259  61.23525  62.31243  62.90110
##  [435]  61.95278  63.65652  63.74549  64.39698  66.09074  66.83120  68.32708
##  [442]  69.06754  68.86467  67.91635  69.62009  68.85968  67.81741  67.92134
##  [449]  68.86966  68.01530  66.22259  65.48213  63.98625  64.09516  59.19680
##  [456]  56.67859  55.58845  54.19650  52.70561  53.76284  53.95574  53.85680
##  [463]  53.00742  53.01241  53.96073  53.95574  56.40493  57.23934  57.78690
##  [470]  57.68297  56.73466  55.89027  56.84357  57.78690  58.53235  58.42842
##  [477]  32.84821  32.99781  35.11671  35.12170  35.22064  35.22064  36.07002
##  [484]  35.21565  36.82045  37.75879  37.55592  38.30635  39.15074  40.74557
##  [491]  42.33540  42.12754  41.92966  41.92966  41.08028  41.93464  42.87798
##  [498]  44.47280  45.21326  47.55851  52.54086  49.66599  55.88230  59.53674
##  [505]  59.57462  61.72199  62.45747  63.00503  62.90110  62.80216  62.80216
##  [512]  62.80216  62.80216  61.95278  62.80714  63.75047  62.79717  63.55259
##  [519]  62.79717  62.70321  62.80216  61.95278  61.10839  58.66420  57.07935
##  [526]  56.53677  55.04089  47.50543  45.20007  46.95488  45.54797  45.45900
##  [533]  43.95814  45.66686  45.85477  46.50627  47.35065  48.09610  47.99217
##  [540]  48.74260  51.28574  55.41872  56.79571  56.29102  57.79189  56.08317
##  [547]  54.19650  52.70561  53.76284  54.80512  52.15306  50.37033  54.07463
##  [554]  53.40319  51.31366  49.72382  48.23293  45.04329  43.56237  41.41999
##  [561]  39.93408  38.54213  37.05124  72.08349  72.92630  68.86467  70.46448
##  [568]  73.00263  72.78979  74.19171  74.18174  71.43573  68.90256  65.81685
##  [575]  61.88674  62.30744  61.10341  61.96275  63.85440  62.04674  60.16007
##  [582]  59.51856  60.57080  63.21289  63.09898  64.50091  65.34031  63.43869
##  [589]  62.50034  65.25134  67.03407  65.87790  64.83562  64.93955  66.73725
##  [596]  67.57665  66.52440  66.43045  63.98126  62.29747  60.05615  57.72086
##  [603]  56.33390  55.79133  55.99420  56.09314  56.09314  56.09314  56.94251
##  [610]  59.48565  61.07050  59.91433  61.42018  69.15353  57.86888  57.04323
##  [617]  57.48010  57.48509  58.43341  58.42842  59.17885  57.47512  55.68740
##  [624]  55.89525  54.39439  53.55499  52.90848  53.86179  78.58763  76.64533
##  [631]  72.08722  71.44570  69.94982  69.20936  67.71348  66.12365  62.93400
##  [638]  62.30246  62.70321  61.10341  60.26400  60.46688  59.71644  58.02268
##  [645]  58.98097  61.72199  64.15622  68.94068  71.16206  75.64970  77.02171
##  [652]  64.52682  63.54937  62.39143  62.50533  62.80216  63.65153  65.34530
##  [659]  67.78451  65.02354  64.74167  65.03850  66.73725  65.02852  63.14186
##  [666]  60.80159  58.46631  58.77810  58.22555  57.38116  57.48509  56.73466
##  [673]  56.73964  55.98921  55.99420  56.09314  56.09314  56.09314  57.79189
##  [680]  57.78192  59.28278  60.12219  61.61806  59.81040  59.62249  58.97100
##  [687]  58.12661  59.07991  57.47512  57.38615  58.43341  57.57905  57.48509
##  [694]  56.73466  56.73964  55.13983  55.14981  55.34769  56.19707  66.38459
##  [701]  64.52706  60.80159  58.46631  55.38060  54.84799  52.70062  51.11578
##  [708]  49.72382  47.38356  46.74703  46.19946  46.30339  48.95046  54.88113
##  [715]  62.19378  67.40193  69.02467  72.56399  69.69410  66.66622  66.12863
##  [722]  65.58107  63.98625  62.39641  48.16489  47.59817  49.28518  49.38412
##  [729]  48.53475  48.53973  47.78930  48.64366  49.58699  51.18182  51.07290
##  [736]  52.57377  51.71442  50.67214  49.92670  49.18125  50.13455  49.37914
##  [743]  49.28518  47.68537  45.99659  46.20445  44.70359  53.20731  53.35533
##  [750]  52.36591  50.66716  49.82775  49.18125  48.43580  46.84098  46.94990
##  [757]  45.44903  43.76025  42.26936  40.77847  40.13695  38.64107  37.90061
##  [764]  38.10348  37.35305  37.35804  39.15573  40.84451  42.33540  42.97692
##  [771]  43.62342  43.51949  76.54619  78.89985  79.27300  80.64999  79.29593
##  [778]  79.10304  77.50323  75.81445  76.02231  73.67207  71.98827  69.74695
##  [785]  68.26104  68.56784  66.21760  65.38319  64.83562  63.24080  63.34972
##  [792]  63.54760  65.24635  66.93513  70.12478  71.60570  75.44683  76.07339
##  [799]  75.57369  75.47475  76.32412  76.31913  76.22019  75.37082  73.67705
##  [806]  72.93659  69.74196  69.86085  67.70849  65.17533  63.78836  62.39641
##  [813]  61.75490  59.40964  59.52354  59.82037  64.06725  66.59044  74.57452
##  [820]  80.17346  81.69726  83.53782  85.77416  56.58361  58.15508  59.81040
##  [827]  57.92374  57.28222  57.48509  57.58403  55.88528  56.74463  56.08815
##  [834]  55.14482  56.09813  61.28833  65.40635  66.48651  69.37933  70.01087
##  [841]  69.61012  68.66180  68.66679  67.06698  64.52882  63.04292  60.80159
##  [848]  59.31569  59.62249  59.82037  58.12162  57.28222  57.48509  56.73466
##  [855]  55.89027  55.14482  53.55000  54.50829  53.85181  54.60723  56.39994
##  [862]  60.53790  62.01383  62.35852  62.15565  63.75546  62.89611  61.85384
##  [869]  61.10839  58.66420  57.07935  56.53677  40.60151  41.64457  43.51949
##  [876]  43.42055  43.42055  43.42055  42.57118  44.27491  44.36388  44.16600
##  [883]  44.16600  43.31662  43.32161  44.26993  44.26494  44.16600  45.01537
##  [890]  44.16101  44.91643  45.85976  47.45458  50.74317  52.22409  51.81835
##  [897]  50.77109  49.92670  49.18125  47.58643  46.84597  47.04884  47.14778
##  [904]  47.14778  47.14778  47.14778  46.29841  46.30339  45.55296  44.70857
##  [911]  43.11375  42.37329  41.72679  41.83072  42.77903  44.47280  46.06263
##  [918]  47.55353  47.34567  47.99716  47.14280  47.89822  47.99217  47.04385
##  [925]  47.04884  47.14778  47.14778  47.14778  47.14778  45.44903  46.30838
##  [932]  45.65190  44.70857  49.90875  57.62216  56.98362  56.94251  60.33503
##  [939]  62.76427  64.90166  66.28863  65.13245  63.24080  62.50034  61.00446
##  [946]  59.41463  58.77311  58.12661  57.38116  56.63571  55.89027  55.99420
##  [953]  55.24376  53.55000  54.50829  53.85181  53.75786  53.85680  56.40493
##  [960]  57.23934  57.78690  59.38173  60.97156  62.46245  63.10397  62.05172
##  [967]  61.10839  60.36295  60.46688  40.18081  40.30048  40.97635  41.83570
##  [974]  41.17922  41.93464  42.02860  42.77903  44.47280  46.06263  48.40290
##  [981]  50.73818  51.27577  60.31709  58.46454  56.53677  55.89027  55.99420
##  [988]  56.09314  55.24376  55.24875  54.49832  53.65393  54.60723  55.55056
##  [995]  57.14539  60.43397  62.76427  69.14854  72.20932  72.24721  70.14771
## [1002]  69.20936  69.41223  67.81242  66.12365  64.63275  62.29248  42.12032
## [1009]  42.53682  45.76082  44.90646  45.66188  47.45458  47.34567  47.14778
## [1016]  51.39466  54.76723  55.10195  54.70119  52.05412  50.37033  49.82775
## [1023]  49.18125  48.43580  47.69036  46.94491  47.04884  47.14778  47.14778
## [1030]  46.29841  45.45402  45.55795  44.80751  45.66188  46.60521  46.50128
## [1037]  48.10109  54.03674  56.35208  57.34327  57.03647  56.83859  55.98921
## [1044]  54.29545  52.70561  52.91347  52.26198  50.56821  50.67713  50.87501
## [1051]  50.87501  50.87501  50.87501  50.87501  50.02564
## 
## $call
## forecast.dlm(model = model.dlm, x = test$BATTERY_VOLTAGE, h = 1055)
## 
## attr(,"class")
## [1] "forecast.dlm" "dLagM"

MAPE testing dan akurasi Data Training

#mape data testing
mape.dlm <- MAPE(fore.dlm$forecasts, test$REF_TEMP)

#akurasi data training
mape_train <- GoF(model.dlm)["MAPE"]

c("MAPE_testing" = mape.dlm, "MAPE_training" = mape_train)
## $MAPE_testing
## [1] 0.01844561
## 
## $MAPE_training.MAPE
## [1] 0.0218475

Lag Optimum

#penentuan lag optimum 
finiteDLMauto(formula = REF_TEMP ~ BATTERY_VOLTAGE,
              data = data.frame(train), q.min = 1, q.max = 4 ,
              model.type = "dlm", error.type = "AIC", trace = TRUE) ##q max lag maksimum
##   q - k    MASE      AIC      BIC   GMRAE    MBRAE R.Adj.Sq Ljung-Box
## 4     4 0.58721 16262.01 16306.43 0.79579 -0.70979  0.98377         0
## 3     3 0.59809 16394.75 16432.83 0.82436  0.34545  0.98327         0
## 2     2 0.61965 17876.94 17908.67 0.84677  0.56818  0.97623         0
## 1     1 0.65283 18694.23 18719.62 0.89583  1.72210  0.97116         0
#model dlm dengan lag optimum
model.dlm2 = dLagM::dlm(x = train$BATTERY_VOLTAGE,y = train$REF_TEMP , q = 4) #terdapat lag yang tidak signifikan sehingga dapat dikurangi jumlah lagnya 
summary(model.dlm2)
## 
## Call:
## lm(formula = model.formula, data = design)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -7.8121 -0.9438 -0.2332  0.6889  9.4896 
## 
## Coefficients:
##              Estimate Std. Error  t value Pr(>|t|)    
## (Intercept) 1053.8877     2.1431  491.767  < 2e-16 ***
## x.t          -84.8815     0.5423 -156.508  < 2e-16 ***
## x.1            2.1844     0.7920    2.758  0.00584 ** 
## x.2            1.4913     0.7744    1.926  0.05418 .  
## x.3            1.2520     0.7742    1.617  0.10591    
## x.4            5.7705     0.5227   11.039  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.666 on 4206 degrees of freedom
## Multiple R-squared:  0.9838, Adjusted R-squared:  0.9838 
## F-statistic: 5.106e+04 on 5 and 4206 DF,  p-value: < 2.2e-16
## 
## AIC and BIC values for the model:
##        AIC      BIC
## 1 16262.01 16306.43
AIC(model.dlm2)
## [1] 16262.01
BIC(model.dlm2)
## [1] 16306.43

ramalan

(fore.dlm2 <- forecast(model = model.dlm2, x=test$BATTERY_VOLTAGE, h=1055))
## $forecasts
##    [1]  64.46877  63.81900  65.69624  66.59902  68.37291  75.13750  81.59552
##    [8]  84.61398  86.73817  86.90000  87.17052  86.01656  52.73406  51.83302
##   [15]  51.56432  50.46435  51.94967  50.43164  48.87535  47.37917  47.53543
##   [22]  48.55452  51.21957  53.80098  56.22464  56.86792  58.28829  58.01901
##   [29]  58.65237  74.67527  72.43229  69.63366  67.73580  65.90405  64.41106
##   [36]  64.66782  63.97676  67.47661  70.91482  79.26847  83.24208  86.94691
##   [43]  88.10473  89.04446  87.77100  84.90301  84.84300  83.08722  81.52855
##   [50]  80.07754  78.47847  75.29717  73.00837  70.72756  71.00332  57.73540
##   [57]  57.44675  54.48506  53.09004  49.88510  48.43430  46.26197  44.83771
##   [64]  42.69325  42.09277  42.35750  42.52539  42.71102  42.76873  41.91991
##   [71]  41.94176  43.65430  48.71603  55.40337  60.20699  62.31254  60.01350
##   [78]  58.62688  57.44594  58.18344  57.45562  54.98633  53.41433  50.06231
##   [85]  46.87952  44.67825  50.91064  51.08337  51.24736  50.48401  50.95074
##   [92]  50.94381  50.94142  52.68423  53.43165  53.37998  51.64240  51.55816
##   [99]  52.37909  53.23111  52.46094  55.00180  35.35820  36.61950  38.65844
##  [106]  42.95876  54.32019  60.69128  64.40364  67.98043  65.30639  64.75127
##  [113]  64.42997  64.16649  62.58427  60.93032  56.75976  53.52858  51.28453
##  [120]  48.19246  46.11673  44.81267  43.42666  43.76855  43.99653  44.13698
##  [127]  45.10121  45.92818  46.74024  44.99333  43.25425  40.71109  39.07615
##  [134]  37.60740  36.13625  35.55911  34.90241  33.38199  33.56852  31.97094
##  [141]  32.09737  32.24261  33.11646  34.90766  36.54669  40.70474  48.97110
##  [148]  53.63054  49.77707  45.11716  42.08742  39.38492  38.93980  38.48365
##  [155]  37.03345  35.58006  34.87498  33.31176  31.81318  32.01463  30.42957
##  [162]  29.76489  29.93197  29.12311  29.27288  30.19432  31.03381  59.06567
##  [169] 113.49040  58.88164  61.34215  63.72726  62.29636  69.96233  73.83164
##  [176]  72.48548  70.55711  68.56696  66.66684  65.12546  62.79298  62.17997
##  [183]  59.84056  59.22516  57.77975  57.08480  57.32210  56.57095  57.56954
##  [190]  56.77149  68.67436  68.42865  67.32586  67.23013  66.43717  65.60088
##  [197]  66.52924  65.67350  66.54176  69.12646  71.54728  76.57509  79.69928
##  [204]  80.16057  78.98202  78.59264  76.66658  74.96745  73.40104  72.65078
##  [211]  69.44764  67.99275  68.22402  67.51281  66.94170  68.79150  67.92643
##  [218]  66.29104  64.68468  62.10885  63.13577  64.14793  66.81059  68.58837
##  [225]  70.97617  72.48318  73.04541  71.99195  70.10310  67.48732  66.68868
##  [232]  64.29156  65.37379  64.73351  64.83570  64.16240  61.59261  61.73076
##  [239]  61.78802  62.73210  67.12745  69.54976  75.33885  78.41616  81.29357
##  [246]  83.43223  82.85304  82.52740  77.16612  74.57762  73.88382  73.17671
##  [253]  73.59726  71.25136  70.53830  68.96495  53.78244  54.39108  55.59109
##  [260]  56.75883  61.15602  64.43648  65.06804  64.87876  65.43176  66.86421
##  [267]  65.89908  40.41412  40.15278  40.51913  40.96736  41.86221  41.94176
##  [274]  41.95667  41.96919  42.87571  42.85387  42.83895  43.67525  43.59570
##  [281]  46.12723  53.68852  54.23830  54.89349  55.41975  56.54876  54.72231
##  [288]  52.96831  50.41263  48.71999  48.94887  49.98048  49.30798  49.43032
##  [295]  46.88626  46.90661  48.70668  50.39819  48.80016  47.09135  44.47797
##  [302]  41.93651  42.18723  49.17546  56.85073  60.95202  73.34065  72.36411
##  [309]  74.10491  75.26069  76.00432  75.89324  75.66526  74.67599  73.73361
##  [316]  72.92155  72.12202  69.68255  68.98441  68.27240  68.40442  67.75615
##  [323]  66.15059  66.26690  66.30924  68.08962  69.01016  71.50493  77.34116
##  [330]  60.88809  58.55701  55.24988  54.36713  53.03613  49.09569  47.79536
##  [337]  44.61362  41.57127  40.33423  38.90543  38.41103  38.71856  38.02511
##  [344]  38.17488  39.09632  38.23818  37.45400  37.47823  39.14559  39.17213
##  [351]  42.59527  46.72693  52.38436  72.47838  73.25395  72.47618  74.28838
##  [358]  75.35934  76.83129  78.40293  78.96756  77.02010  74.36198  73.48059
##  [365]  70.11925  69.52569  68.09519  67.41276  66.85896  66.97846  67.97012
##  [372]  67.16968  66.38550  66.40974  66.37947  68.14732  67.31253  68.15336
##  [379]  66.42376  68.04727  69.77623  84.09991  85.48674  85.89790  86.36679
##  [386]  81.92875  78.47802  75.15956  72.75251  70.61215  69.30569  67.96487
##  [393]  67.40024  66.80125  66.12964  66.29433  64.68184  66.49338  65.68841
##  [400]  64.85665  65.83259  64.87396  66.64874  66.66516  67.43896  65.75215
##  [407]  66.51433  63.96335  63.13248  62.45314  60.77212  60.16754  58.59181
##  [414]  57.03552  55.53933  55.69559  55.01705  54.33053  54.48270  55.35895
##  [421]  56.25615  59.67236  61.25518  66.17451  69.30109  72.26364  71.07727
##  [428]  68.94552  68.72322  67.68593  66.09289  61.17400  62.19623  62.34661
##  [435]  61.67341  63.72660  63.64012  64.47163  66.18008  66.85488  68.48832
##  [442]  69.19579  69.01619  68.06972  69.66126  68.72597  67.88169  67.95111
##  [449]  68.71195  67.91152  66.27852  65.47579  63.78464  63.92599  58.99085
##  [456]  56.65821  55.23100  53.69692  52.45659  53.57708  53.72551  53.85104
##  [463]  53.10512  53.06926  53.93299  53.92366  56.51290  57.28367  58.00819
##  [470]  57.93387  56.88451  55.98731  56.81518  57.66959  58.55187  58.56030
##  [477]  33.01070  33.59578  33.13666  33.53411  35.28017  35.29269  36.19921
##  [484]  35.32855  37.03311  37.84063  37.74378  38.61034  39.30939  40.91255
##  [491]  42.53906  42.39533  42.28275  42.14230  41.17808  42.04874  42.89062
##  [498]  44.56402  45.39942  47.82397  52.75367  49.90349  56.57480  59.59182
##  [505]  59.92528  62.46319  62.71984  63.25873  63.12671  62.92616  62.85594
##  [512]  62.79823  62.79823  61.94942  62.82007  63.66196  62.78891  63.68984
##  [519]  62.76387  62.72561  62.78571  61.89171  61.12244  58.61275  57.00809
##  [526]  56.31792  54.76723  47.38465  45.19255  46.32386  44.87722  45.46290
##  [533]  43.95569  45.66434  45.76589  46.60992  47.52726  48.22391  48.17463
##  [540]  48.93831  51.39269  55.49861  57.02977  56.81625  58.24834  56.19345
##  [547]  54.39427  52.74512  53.57708  54.57432  52.13157  50.58745  54.00091
##  [554]  53.07440  51.53712  49.96342  48.12100  44.88200  43.44202  41.13936
##  [561]  39.70258  38.34923  36.87809  71.95119  72.07469  71.58185  72.86665
##  [568]  72.99099  72.83793  74.46578  74.26912  71.51974  69.01378  65.61338
##  [575]  61.53898  61.91852  60.51866  61.70458  63.69872  61.96753  60.38664
##  [582]  59.52860  60.33871  63.01868  63.06617  64.76424  65.47410  63.55169
##  [589]  62.70661  65.17679  66.79114  65.98183  65.14518  64.98378  66.59343
##  [596]  67.46879  66.62600  66.60789  63.94843  62.27115  59.87083  57.45730
##  [603]  56.06810  55.46068  55.72303  55.93610  56.06403  56.12173  56.97055
##  [610]  59.49515  61.11233  60.16257  61.75695  69.16936  57.80545  57.98787
##  [617]  57.10483  56.77010  58.38399  58.37466  59.26627  57.53428  55.80771
##  [624]  55.86871  54.16824  53.50356  52.82183  53.73244  78.46909  76.19330
##  [631]  74.15206  72.95597  69.66160  69.01184  67.49381  65.93752  62.74370
##  [638]  62.09484  62.31678  60.79956  60.23777  60.34714  59.53828  57.99042
##  [645]  58.95554  61.52249  64.07124  69.15675  71.43213  76.15934  77.43293
##  [652]  65.03256  64.21149  61.52441  61.66472  62.52985  63.47393  65.32283
##  [659]  67.81068  65.15636  65.09440  64.98617  66.54825  64.98004  63.29627
##  [666]  60.79830  58.25684  58.50756  57.85646  57.24016  57.45003  56.62865
##  [673]  56.72072  55.94452  55.97889  56.05151  56.06403  56.12173  57.81936
##  [680]  57.77567  59.44348  60.22357  61.75412  59.97284  59.85878  58.95704
##  [687]  58.03970  59.04068  57.34864  57.44764  58.37147  57.46814  57.59048
##  [694]  56.74406  56.72072  55.09571  55.15191  55.23945  56.11330  66.39265
##  [701]  64.41799  61.72375  59.06471  55.11230  54.54857  52.29430  50.90031
##  [708]  49.53444  47.15677  46.60147  45.95969  46.14942  48.89641  54.84281
##  [715]  62.34221  67.94537  69.94394  73.50148  70.19409  67.19711  66.22285
##  [722]  65.18965  63.73946  62.28606  47.99994  47.63503  48.05086  48.39402
##  [729]  48.53871  48.61826  47.78435  48.66753  49.56712  51.24052  51.22710
##  [736]  52.82468  51.84943  50.87723  50.04013  49.12518  50.08098  49.29546
##  [743]  49.37261  47.73508  46.03595  46.16717  44.52440  53.19670  53.12350
##  [750]  52.99940  51.29198  49.90980  49.11266  48.32564  46.79270  46.92152
##  [757]  45.32394  43.75274  42.24404  40.64496  40.01011  38.50460  37.85483
##  [764]  38.03443  37.28328  37.43305  39.20330  40.86976  42.55159  43.30185
##  [771]  43.95854  43.78133  76.74229  78.36661  81.90583  82.96122  79.70610
##  [778]  79.46240  77.46612  75.70929  75.84051  73.34893  71.85728  69.51467
##  [785]  67.94996  68.23654  65.87289  65.28776  64.62094  62.99762  63.24186
##  [792]  63.34191  65.12229  66.89164  70.21339  71.76878  75.76906  76.31334
##  [799]  75.96107  75.76815  76.31592  76.23637  76.22146  75.36012  73.62663
##  [806]  72.83642  69.50534  69.69038  67.33151  64.95838  63.60184  62.03020
##  [813]  61.46557  59.16895  59.38985  59.56252  63.90186  66.51220  74.86026
##  [820]  80.47619  82.39451  84.47272  86.24421  56.83271  59.01761  57.57267
##  [827]  56.14147  57.30310  57.26440  57.41976  55.85006  56.80027  55.95944
##  [834]  55.14259  56.13105  61.17183  65.34016  66.88428  70.02846  70.35124
##  [841]  69.95618  68.92696  68.70547  66.96504  64.47480  62.93024  60.49726
##  [848]  59.04795  59.33454  59.51733  58.01786  57.32814  57.37981  56.57095
##  [855]  55.87190  55.11755  53.46920  54.44684  53.67623  54.61472  56.40831
##  [862]  60.54860  62.15238  62.80019  62.57051  63.93966  62.91923  62.00473
##  [869]  61.16763  58.55505  57.00809  56.31792  40.33737  41.81428  42.20372
##  [876]  42.48439  43.56827  43.51056  42.66175  44.38122  44.35245  44.33514
##  [883]  44.36780  43.40358  43.42542  44.28915  44.27983  44.32262  45.15891
##  [890]  44.23055  45.08630  45.91566  47.53135  50.91320  52.42340  52.23732
##  [897]  51.19318  50.11035  49.18288  47.53453  46.81454  46.93644  47.03409
##  [904]  47.16202  47.21973  47.21973  46.37091  46.39276  45.55885  44.74440
##  [911]  43.14123  42.36354  41.63662  41.75612  42.74778  44.49379  46.19053
##  [918]  47.80212  47.64587  48.32440  47.31329  48.05363  48.03418  47.12527
##  [925]  47.19229  47.14950  47.16202  47.21973  47.21973  45.52210  46.41460
##  [932]  45.57377  44.75692  49.98946  57.46747  57.25162  57.94880  60.86331
##  [939]  62.78812  65.19686  66.67644  65.47082  63.55453  62.56616  60.81731
##  [946]  59.26102  58.61365  57.89925  57.22764  56.54351  55.80168  55.90866
##  [953]  55.14498  53.53942  54.50454  53.67623  53.76591  53.88371  56.38497
##  [960]  57.22596  58.00819  59.63151  61.08490  62.63879  63.33135  62.29041
##  [967]  61.30808  60.36809  60.35966  40.07323  40.66770  39.38570  40.57868
##  [974]  41.12277  42.00355  42.09951  42.88823  44.60920  46.19053  48.65094
##  [981]  51.01928  51.61738  60.73479  58.57129  57.41648  56.42391  55.85096
##  [988]  55.99380  55.21521  55.29476  54.46086  53.64640  54.58968  55.44409
##  [995]  57.17519  60.55703  62.91605  69.49865  72.50893  72.88268  70.83028
## [1002]  69.49852  69.30685  67.59147  66.06545  64.49904  62.05115  41.91539
## [1009]  42.62482  43.98453  43.58747  45.82813  47.50631  47.40253  47.41788
## [1016]  51.57922  54.74985  55.43672  55.29263  52.39266  50.51722  49.69913
## [1023]  48.93954  48.32564  47.64151  46.89968  47.00666  47.09180  47.16202
## [1030]  46.37091  45.54394  45.58070  44.75932  45.70020  46.59979  46.57555
## [1037]  48.30346  54.13125  56.43726  57.93993  57.64845  57.17713  56.13016
## [1044]  54.33896  52.69993  52.78596  52.04972  50.51438  50.68839  50.73074
## [1051]  50.81349  50.92890  50.92890  50.92890  50.08008
## 
## $call
## forecast.dlm(model = model.dlm2, x = test$BATTERY_VOLTAGE, h = 1055)
## 
## attr(,"class")
## [1] "forecast.dlm" "dLagM"
#akurasi testing
mape.dlm2 <- MAPE(fore.dlm2$forecasts, test$REF_TEMP)

#akurasi data training
mape_train <- GoF(model.dlm2)["MAPE"]

c("MAPE_testing" = mape.dlm2, "MAPE_training" = mape_train)
## $MAPE_testing
## [1] 0.01853903
## 
## $MAPE_training.MAPE
## [1] 0.02076887

Model Autoregressive / Dynamic Regression

Apabila peubah dependen dipengaruhi oleh peubah independen pada waktu sekarang, serta dipengaruhii juga oleh peubah dependen itu sendiri pada satu waktu yang lalu maka model tersebut disebut autoregressive (Gujarati, 2004)

#MODEL AUTOREGRESSIVE 
#library(dLagM)
model.ardl = ardlDlm(x = train$BATTERY_VOLTAGE, y = train$REF_TEMP, p = 1 , q = 1) #p:lag x, q:lag y
#model untuk p=1, q=1: yt=b0+b1yt-1+b2xt+b3xt-1
#model untuk p=2, q=3: yt=b0+b1yt-1+b2yt-2+b3xt+b4xt-1+b5xt-2

summary(model.ardl)
## 
## Time series regression with "ts" data:
## Start = 2, End = 4216
## 
## Call:
## dynlm(formula = as.formula(model.text), data = data, start = 1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -27.819  -0.577  -0.051   0.476  48.212 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 259.785996   9.549597   27.20   <2e-16 ***
## X.t         -75.674529   0.433500 -174.57   <2e-16 ***
## X.1          57.414829   0.677442   84.75   <2e-16 ***
## Y.1           0.747451   0.008771   85.22   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.346 on 4211 degrees of freedom
## Multiple R-squared:  0.9894, Adjusted R-squared:  0.9894 
## F-statistic: 1.313e+05 on 3 and 4211 DF,  p-value: < 2.2e-16
AIC(model.ardl)
## [1] 14471.32
BIC(model.ardl)
## [1] 14503.05

Ramalan Autoregressive

ramalan

(fore.ardl <- forecast(model = model.dlm2, x=test$BATTERY_VOLTAGE, h=1055))
## $forecasts
##    [1]  64.46877  63.81900  65.69624  66.59902  68.37291  75.13750  81.59552
##    [8]  84.61398  86.73817  86.90000  87.17052  86.01656  52.73406  51.83302
##   [15]  51.56432  50.46435  51.94967  50.43164  48.87535  47.37917  47.53543
##   [22]  48.55452  51.21957  53.80098  56.22464  56.86792  58.28829  58.01901
##   [29]  58.65237  74.67527  72.43229  69.63366  67.73580  65.90405  64.41106
##   [36]  64.66782  63.97676  67.47661  70.91482  79.26847  83.24208  86.94691
##   [43]  88.10473  89.04446  87.77100  84.90301  84.84300  83.08722  81.52855
##   [50]  80.07754  78.47847  75.29717  73.00837  70.72756  71.00332  57.73540
##   [57]  57.44675  54.48506  53.09004  49.88510  48.43430  46.26197  44.83771
##   [64]  42.69325  42.09277  42.35750  42.52539  42.71102  42.76873  41.91991
##   [71]  41.94176  43.65430  48.71603  55.40337  60.20699  62.31254  60.01350
##   [78]  58.62688  57.44594  58.18344  57.45562  54.98633  53.41433  50.06231
##   [85]  46.87952  44.67825  50.91064  51.08337  51.24736  50.48401  50.95074
##   [92]  50.94381  50.94142  52.68423  53.43165  53.37998  51.64240  51.55816
##   [99]  52.37909  53.23111  52.46094  55.00180  35.35820  36.61950  38.65844
##  [106]  42.95876  54.32019  60.69128  64.40364  67.98043  65.30639  64.75127
##  [113]  64.42997  64.16649  62.58427  60.93032  56.75976  53.52858  51.28453
##  [120]  48.19246  46.11673  44.81267  43.42666  43.76855  43.99653  44.13698
##  [127]  45.10121  45.92818  46.74024  44.99333  43.25425  40.71109  39.07615
##  [134]  37.60740  36.13625  35.55911  34.90241  33.38199  33.56852  31.97094
##  [141]  32.09737  32.24261  33.11646  34.90766  36.54669  40.70474  48.97110
##  [148]  53.63054  49.77707  45.11716  42.08742  39.38492  38.93980  38.48365
##  [155]  37.03345  35.58006  34.87498  33.31176  31.81318  32.01463  30.42957
##  [162]  29.76489  29.93197  29.12311  29.27288  30.19432  31.03381  59.06567
##  [169] 113.49040  58.88164  61.34215  63.72726  62.29636  69.96233  73.83164
##  [176]  72.48548  70.55711  68.56696  66.66684  65.12546  62.79298  62.17997
##  [183]  59.84056  59.22516  57.77975  57.08480  57.32210  56.57095  57.56954
##  [190]  56.77149  68.67436  68.42865  67.32586  67.23013  66.43717  65.60088
##  [197]  66.52924  65.67350  66.54176  69.12646  71.54728  76.57509  79.69928
##  [204]  80.16057  78.98202  78.59264  76.66658  74.96745  73.40104  72.65078
##  [211]  69.44764  67.99275  68.22402  67.51281  66.94170  68.79150  67.92643
##  [218]  66.29104  64.68468  62.10885  63.13577  64.14793  66.81059  68.58837
##  [225]  70.97617  72.48318  73.04541  71.99195  70.10310  67.48732  66.68868
##  [232]  64.29156  65.37379  64.73351  64.83570  64.16240  61.59261  61.73076
##  [239]  61.78802  62.73210  67.12745  69.54976  75.33885  78.41616  81.29357
##  [246]  83.43223  82.85304  82.52740  77.16612  74.57762  73.88382  73.17671
##  [253]  73.59726  71.25136  70.53830  68.96495  53.78244  54.39108  55.59109
##  [260]  56.75883  61.15602  64.43648  65.06804  64.87876  65.43176  66.86421
##  [267]  65.89908  40.41412  40.15278  40.51913  40.96736  41.86221  41.94176
##  [274]  41.95667  41.96919  42.87571  42.85387  42.83895  43.67525  43.59570
##  [281]  46.12723  53.68852  54.23830  54.89349  55.41975  56.54876  54.72231
##  [288]  52.96831  50.41263  48.71999  48.94887  49.98048  49.30798  49.43032
##  [295]  46.88626  46.90661  48.70668  50.39819  48.80016  47.09135  44.47797
##  [302]  41.93651  42.18723  49.17546  56.85073  60.95202  73.34065  72.36411
##  [309]  74.10491  75.26069  76.00432  75.89324  75.66526  74.67599  73.73361
##  [316]  72.92155  72.12202  69.68255  68.98441  68.27240  68.40442  67.75615
##  [323]  66.15059  66.26690  66.30924  68.08962  69.01016  71.50493  77.34116
##  [330]  60.88809  58.55701  55.24988  54.36713  53.03613  49.09569  47.79536
##  [337]  44.61362  41.57127  40.33423  38.90543  38.41103  38.71856  38.02511
##  [344]  38.17488  39.09632  38.23818  37.45400  37.47823  39.14559  39.17213
##  [351]  42.59527  46.72693  52.38436  72.47838  73.25395  72.47618  74.28838
##  [358]  75.35934  76.83129  78.40293  78.96756  77.02010  74.36198  73.48059
##  [365]  70.11925  69.52569  68.09519  67.41276  66.85896  66.97846  67.97012
##  [372]  67.16968  66.38550  66.40974  66.37947  68.14732  67.31253  68.15336
##  [379]  66.42376  68.04727  69.77623  84.09991  85.48674  85.89790  86.36679
##  [386]  81.92875  78.47802  75.15956  72.75251  70.61215  69.30569  67.96487
##  [393]  67.40024  66.80125  66.12964  66.29433  64.68184  66.49338  65.68841
##  [400]  64.85665  65.83259  64.87396  66.64874  66.66516  67.43896  65.75215
##  [407]  66.51433  63.96335  63.13248  62.45314  60.77212  60.16754  58.59181
##  [414]  57.03552  55.53933  55.69559  55.01705  54.33053  54.48270  55.35895
##  [421]  56.25615  59.67236  61.25518  66.17451  69.30109  72.26364  71.07727
##  [428]  68.94552  68.72322  67.68593  66.09289  61.17400  62.19623  62.34661
##  [435]  61.67341  63.72660  63.64012  64.47163  66.18008  66.85488  68.48832
##  [442]  69.19579  69.01619  68.06972  69.66126  68.72597  67.88169  67.95111
##  [449]  68.71195  67.91152  66.27852  65.47579  63.78464  63.92599  58.99085
##  [456]  56.65821  55.23100  53.69692  52.45659  53.57708  53.72551  53.85104
##  [463]  53.10512  53.06926  53.93299  53.92366  56.51290  57.28367  58.00819
##  [470]  57.93387  56.88451  55.98731  56.81518  57.66959  58.55187  58.56030
##  [477]  33.01070  33.59578  33.13666  33.53411  35.28017  35.29269  36.19921
##  [484]  35.32855  37.03311  37.84063  37.74378  38.61034  39.30939  40.91255
##  [491]  42.53906  42.39533  42.28275  42.14230  41.17808  42.04874  42.89062
##  [498]  44.56402  45.39942  47.82397  52.75367  49.90349  56.57480  59.59182
##  [505]  59.92528  62.46319  62.71984  63.25873  63.12671  62.92616  62.85594
##  [512]  62.79823  62.79823  61.94942  62.82007  63.66196  62.78891  63.68984
##  [519]  62.76387  62.72561  62.78571  61.89171  61.12244  58.61275  57.00809
##  [526]  56.31792  54.76723  47.38465  45.19255  46.32386  44.87722  45.46290
##  [533]  43.95569  45.66434  45.76589  46.60992  47.52726  48.22391  48.17463
##  [540]  48.93831  51.39269  55.49861  57.02977  56.81625  58.24834  56.19345
##  [547]  54.39427  52.74512  53.57708  54.57432  52.13157  50.58745  54.00091
##  [554]  53.07440  51.53712  49.96342  48.12100  44.88200  43.44202  41.13936
##  [561]  39.70258  38.34923  36.87809  71.95119  72.07469  71.58185  72.86665
##  [568]  72.99099  72.83793  74.46578  74.26912  71.51974  69.01378  65.61338
##  [575]  61.53898  61.91852  60.51866  61.70458  63.69872  61.96753  60.38664
##  [582]  59.52860  60.33871  63.01868  63.06617  64.76424  65.47410  63.55169
##  [589]  62.70661  65.17679  66.79114  65.98183  65.14518  64.98378  66.59343
##  [596]  67.46879  66.62600  66.60789  63.94843  62.27115  59.87083  57.45730
##  [603]  56.06810  55.46068  55.72303  55.93610  56.06403  56.12173  56.97055
##  [610]  59.49515  61.11233  60.16257  61.75695  69.16936  57.80545  57.98787
##  [617]  57.10483  56.77010  58.38399  58.37466  59.26627  57.53428  55.80771
##  [624]  55.86871  54.16824  53.50356  52.82183  53.73244  78.46909  76.19330
##  [631]  74.15206  72.95597  69.66160  69.01184  67.49381  65.93752  62.74370
##  [638]  62.09484  62.31678  60.79956  60.23777  60.34714  59.53828  57.99042
##  [645]  58.95554  61.52249  64.07124  69.15675  71.43213  76.15934  77.43293
##  [652]  65.03256  64.21149  61.52441  61.66472  62.52985  63.47393  65.32283
##  [659]  67.81068  65.15636  65.09440  64.98617  66.54825  64.98004  63.29627
##  [666]  60.79830  58.25684  58.50756  57.85646  57.24016  57.45003  56.62865
##  [673]  56.72072  55.94452  55.97889  56.05151  56.06403  56.12173  57.81936
##  [680]  57.77567  59.44348  60.22357  61.75412  59.97284  59.85878  58.95704
##  [687]  58.03970  59.04068  57.34864  57.44764  58.37147  57.46814  57.59048
##  [694]  56.74406  56.72072  55.09571  55.15191  55.23945  56.11330  66.39265
##  [701]  64.41799  61.72375  59.06471  55.11230  54.54857  52.29430  50.90031
##  [708]  49.53444  47.15677  46.60147  45.95969  46.14942  48.89641  54.84281
##  [715]  62.34221  67.94537  69.94394  73.50148  70.19409  67.19711  66.22285
##  [722]  65.18965  63.73946  62.28606  47.99994  47.63503  48.05086  48.39402
##  [729]  48.53871  48.61826  47.78435  48.66753  49.56712  51.24052  51.22710
##  [736]  52.82468  51.84943  50.87723  50.04013  49.12518  50.08098  49.29546
##  [743]  49.37261  47.73508  46.03595  46.16717  44.52440  53.19670  53.12350
##  [750]  52.99940  51.29198  49.90980  49.11266  48.32564  46.79270  46.92152
##  [757]  45.32394  43.75274  42.24404  40.64496  40.01011  38.50460  37.85483
##  [764]  38.03443  37.28328  37.43305  39.20330  40.86976  42.55159  43.30185
##  [771]  43.95854  43.78133  76.74229  78.36661  81.90583  82.96122  79.70610
##  [778]  79.46240  77.46612  75.70929  75.84051  73.34893  71.85728  69.51467
##  [785]  67.94996  68.23654  65.87289  65.28776  64.62094  62.99762  63.24186
##  [792]  63.34191  65.12229  66.89164  70.21339  71.76878  75.76906  76.31334
##  [799]  75.96107  75.76815  76.31592  76.23637  76.22146  75.36012  73.62663
##  [806]  72.83642  69.50534  69.69038  67.33151  64.95838  63.60184  62.03020
##  [813]  61.46557  59.16895  59.38985  59.56252  63.90186  66.51220  74.86026
##  [820]  80.47619  82.39451  84.47272  86.24421  56.83271  59.01761  57.57267
##  [827]  56.14147  57.30310  57.26440  57.41976  55.85006  56.80027  55.95944
##  [834]  55.14259  56.13105  61.17183  65.34016  66.88428  70.02846  70.35124
##  [841]  69.95618  68.92696  68.70547  66.96504  64.47480  62.93024  60.49726
##  [848]  59.04795  59.33454  59.51733  58.01786  57.32814  57.37981  56.57095
##  [855]  55.87190  55.11755  53.46920  54.44684  53.67623  54.61472  56.40831
##  [862]  60.54860  62.15238  62.80019  62.57051  63.93966  62.91923  62.00473
##  [869]  61.16763  58.55505  57.00809  56.31792  40.33737  41.81428  42.20372
##  [876]  42.48439  43.56827  43.51056  42.66175  44.38122  44.35245  44.33514
##  [883]  44.36780  43.40358  43.42542  44.28915  44.27983  44.32262  45.15891
##  [890]  44.23055  45.08630  45.91566  47.53135  50.91320  52.42340  52.23732
##  [897]  51.19318  50.11035  49.18288  47.53453  46.81454  46.93644  47.03409
##  [904]  47.16202  47.21973  47.21973  46.37091  46.39276  45.55885  44.74440
##  [911]  43.14123  42.36354  41.63662  41.75612  42.74778  44.49379  46.19053
##  [918]  47.80212  47.64587  48.32440  47.31329  48.05363  48.03418  47.12527
##  [925]  47.19229  47.14950  47.16202  47.21973  47.21973  45.52210  46.41460
##  [932]  45.57377  44.75692  49.98946  57.46747  57.25162  57.94880  60.86331
##  [939]  62.78812  65.19686  66.67644  65.47082  63.55453  62.56616  60.81731
##  [946]  59.26102  58.61365  57.89925  57.22764  56.54351  55.80168  55.90866
##  [953]  55.14498  53.53942  54.50454  53.67623  53.76591  53.88371  56.38497
##  [960]  57.22596  58.00819  59.63151  61.08490  62.63879  63.33135  62.29041
##  [967]  61.30808  60.36809  60.35966  40.07323  40.66770  39.38570  40.57868
##  [974]  41.12277  42.00355  42.09951  42.88823  44.60920  46.19053  48.65094
##  [981]  51.01928  51.61738  60.73479  58.57129  57.41648  56.42391  55.85096
##  [988]  55.99380  55.21521  55.29476  54.46086  53.64640  54.58968  55.44409
##  [995]  57.17519  60.55703  62.91605  69.49865  72.50893  72.88268  70.83028
## [1002]  69.49852  69.30685  67.59147  66.06545  64.49904  62.05115  41.91539
## [1009]  42.62482  43.98453  43.58747  45.82813  47.50631  47.40253  47.41788
## [1016]  51.57922  54.74985  55.43672  55.29263  52.39266  50.51722  49.69913
## [1023]  48.93954  48.32564  47.64151  46.89968  47.00666  47.09180  47.16202
## [1030]  46.37091  45.54394  45.58070  44.75932  45.70020  46.59979  46.57555
## [1037]  48.30346  54.13125  56.43726  57.93993  57.64845  57.17713  56.13016
## [1044]  54.33896  52.69993  52.78596  52.04972  50.51438  50.68839  50.73074
## [1051]  50.81349  50.92890  50.92890  50.92890  50.08008
## 
## $call
## forecast.dlm(model = model.dlm2, x = test$BATTERY_VOLTAGE, h = 1055)
## 
## attr(,"class")
## [1] "forecast.dlm" "dLagM"

MAPE testing dan akurasi Data Training

#akurasi testing
mape.ardl <- MAPE(fore.ardl$forecasts, test$REF_TEMP) #data testing

#akurasi data training
mape_train <- GoF(model.ardl)["MAPE"]

c("MAPE_testing" = mape.ardl, "MAPE_training" = mape_train)
## $MAPE_testing
## [1] 0.01853903
## 
## $MAPE_training.MAPE
## [1] 0.01269811

Penentuan lag optimum

ardlBoundOrders(data = data.frame(train), ic="AIC", formula = REF_TEMP ~ BATTERY_VOLTAGE ) 
## $p
##   BATTERY_VOLTAGE
## 1              15
## 
## $q
## [1] 15
## 
## $Stat.table
##           q = 1    q = 2    q = 3    q = 4    q = 5    q = 6    q = 7    q = 8
## p = 1  14388.70 13674.87 11953.76 11934.56 11928.94 11923.08 11912.05 11902.66
## p = 2  13713.53 13653.23 11955.28 11936.08 11929.41 11924.10 11913.66 11904.51
## p = 3  11957.68 11957.68 11947.68 11932.06 11926.50 11909.16 11901.70 11894.76
## p = 4  11927.24 11928.32 11928.32 11927.57 11922.67 11906.66 11891.16 11885.79
## p = 5  11916.71 11918.63 11919.99 11919.99 11920.26 11903.41 11889.24 11871.27
## p = 6  11904.99 11906.98 11899.34 11901.33 11901.33 11900.90 11886.52 11869.65
## p = 7  11886.54 11888.51 11882.63 11881.00 11882.99 11882.99 11882.29 11864.13
## p = 8  11868.91 11870.72 11866.55 11865.77 11861.82 11863.81 11863.81 11865.77
## p = 9  11869.95 11871.85 11866.83 11865.42 11860.39 11860.06 11860.40 11860.40
## p = 10 11869.03 11870.95 11865.80 11864.26 11859.12 11858.61 11853.15 11855.07
## p = 11 11855.08 11857.03 11852.54 11851.74 11847.88 11848.33 11844.89 11846.73
## p = 12 11859.21 11861.19 11855.61 11854.41 11850.06 11850.16 11846.02 11847.60
## p = 13 11865.64 11867.64 11861.25 11859.20 11853.67 11852.93 11846.99 11847.87
## p = 14 11864.69 11866.67 11859.54 11856.75 11849.86 11848.16 11840.73 11840.84
## p = 15 11863.80 11865.79 11858.87 11856.29 11849.79 11848.63 11842.17 11842.89
##           q = 9   q = 10   q = 11   q = 12   q = 13   q = 14   q = 15
## p = 1  11893.50 11892.27 11884.93 11880.92 11875.90 11874.26 11868.14
## p = 2  11895.48 11894.26 11886.93 11882.92 11877.89 11876.26 11870.14
## p = 3  11887.15 11886.43 11879.91 11876.32 11871.38 11869.96 11863.97
## p = 4  11879.85 11879.48 11873.99 11870.88 11866.35 11864.92 11859.19
## p = 5  11867.80 11867.80 11863.51 11861.23 11857.10 11855.84 11850.16
## p = 6  11864.11 11864.28 11860.91 11859.06 11855.31 11854.23 11848.84
## p = 7  11859.56 11852.82 11850.56 11849.54 11846.22 11845.52 11840.60
## p = 8  11861.22 11854.55 11850.18 11849.58 11846.47 11845.90 11841.29
## p = 9  11862.23 11854.73 11850.73 11849.17 11846.71 11846.31 11841.96
## p = 10 11855.07 11852.07 11847.75 11846.56 11846.24 11845.85 11841.94
## p = 11 11847.62 11847.62 11849.61 11848.39 11848.12 11846.22 11842.95
## p = 12 11849.31 11848.42 11848.42 11850.39 11850.12 11848.21 11842.80
## p = 13 11848.95 11847.60 11849.53 11849.53 11835.43 11834.12 11827.98
## p = 14 11840.99 11837.31 11834.77 11831.19 11831.19 11826.27 11822.51
## p = 15 11843.80 11842.02 11842.37 11843.33 11824.47 11824.47 11821.02
## 
## $min.Stat
## [1] 11821.02
#PEMODELAN DLM dan ARDL dengan library dynlm
#library(dynlm)

#sama dengan model dlm p=1
cons_lm1 <- dynlm(REF_TEMP ~ BATTERY_VOLTAGE+L(BATTERY_VOLTAGE),data = train.ts)

#sama dengan model ardl p=0 q=1
cons_lm2 <- dynlm(REF_TEMP ~ BATTERY_VOLTAGE+L(REF_TEMP),data = train.ts)

#sama dengan ardl p=1 q=1
cons_lm3 <- dynlm(REF_TEMP ~ BATTERY_VOLTAGE+L(BATTERY_VOLTAGE)+L(REF_TEMP),data = train.ts)

#sama dengan dlm p=2
cons_lm4 <- dynlm(REF_TEMP ~ BATTERY_VOLTAGE+L(BATTERY_VOLTAGE)+L(BATTERY_VOLTAGE,2),data = train.ts)
summary(cons_lm1)
## 
## Time series regression with "ts" data:
## Start = 2, End = 4216
## 
## Call:
## dynlm(formula = REF_TEMP ~ BATTERY_VOLTAGE + L(BATTERY_VOLTAGE), 
##     data = train.ts)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -67.140  -1.045  -0.289   0.783   9.733 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        1061.4948     2.7098  391.72   <2e-16 ***
## BATTERY_VOLTAGE     -86.4626     0.6843 -126.35   <2e-16 ***
## L(BATTERY_VOLTAGE)   11.7100     0.6831   17.14   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.221 on 4212 degrees of freedom
## Multiple R-squared:  0.9712, Adjusted R-squared:  0.9712 
## F-statistic: 7.096e+04 on 2 and 4212 DF,  p-value: < 2.2e-16
summary(cons_lm2)
## 
## Time series regression with "ts" data:
## Start = 2, End = 4216
## 
## Call:
## dynlm(formula = REF_TEMP ~ BATTERY_VOLTAGE + L(REF_TEMP), data = train.ts)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -58.542  -1.114  -0.270   0.838  10.981 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     903.047069   9.532103   94.74   <2e-16 ***
## BATTERY_VOLTAGE -63.636912   0.673633  -94.47   <2e-16 ***
## L(REF_TEMP)       0.158972   0.008813   18.04   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.213 on 4212 degrees of freedom
## Multiple R-squared:  0.9714, Adjusted R-squared:  0.9714 
## F-statistic: 7.147e+04 on 2 and 4212 DF,  p-value: < 2.2e-16
summary(cons_lm3)
## 
## Time series regression with "ts" data:
## Start = 2, End = 4216
## 
## Call:
## dynlm(formula = REF_TEMP ~ BATTERY_VOLTAGE + L(BATTERY_VOLTAGE) + 
##     L(REF_TEMP), data = train.ts)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -27.819  -0.577  -0.051   0.476  48.212 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        259.785996   9.549597   27.20   <2e-16 ***
## BATTERY_VOLTAGE    -75.674529   0.433500 -174.57   <2e-16 ***
## L(BATTERY_VOLTAGE)  57.414829   0.677442   84.75   <2e-16 ***
## L(REF_TEMP)          0.747451   0.008771   85.22   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.346 on 4211 degrees of freedom
## Multiple R-squared:  0.9894, Adjusted R-squared:  0.9894 
## F-statistic: 1.313e+05 on 3 and 4211 DF,  p-value: < 2.2e-16
summary(cons_lm4)
## 
## Time series regression with "ts" data:
## Start = 3, End = 4216
## 
## Call:
## dynlm(formula = REF_TEMP ~ BATTERY_VOLTAGE + L(BATTERY_VOLTAGE) + 
##     L(BATTERY_VOLTAGE, 2), data = train.ts)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -66.858  -0.977  -0.269   0.735  10.976 
## 
## Coefficients:
##                        Estimate Std. Error  t value Pr(>|t|)    
## (Intercept)           1058.7185     2.4999  423.508   <2e-16 ***
## BATTERY_VOLTAGE        -84.9375     0.6298 -134.859   <2e-16 ***
## L(BATTERY_VOLTAGE)       0.4987     0.9359    0.533    0.594    
## L(BATTERY_VOLTAGE, 2)    9.8943     0.6287   15.737   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.017 on 4210 degrees of freedom
## Multiple R-squared:  0.9762, Adjusted R-squared:  0.9762 
## F-statistic: 5.768e+04 on 3 and 4210 DF,  p-value: < 2.2e-16

SSE

deviance(cons_lm1)
## [1] 20781.08
deviance(cons_lm2)
## [1] 20636.79
deviance(cons_lm3)
## [1] 7626.971
deviance(cons_lm4)
## [1] 17123.24

Diagnostik Model

Uji Non Autokorelasi

if(require("lmtest")) encomptest(cons_lm1, cons_lm2)
## Encompassing test
## 
## Model 1: REF_TEMP ~ BATTERY_VOLTAGE + L(BATTERY_VOLTAGE)
## Model 2: REF_TEMP ~ BATTERY_VOLTAGE + L(REF_TEMP)
## Model E: REF_TEMP ~ BATTERY_VOLTAGE + L(BATTERY_VOLTAGE) + L(REF_TEMP)
##           Res.Df Df      F    Pr(>F)    
## M1 vs. ME   4211 -1 7262.6 < 2.2e-16 ***
## M2 vs. ME   4211 -1 7183.0 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Diagnostik

Durbin Watson

dwtest(cons_lm1)
## 
##  Durbin-Watson test
## 
## data:  cons_lm1
## DW = 0.58765, p-value < 2.2e-16
## alternative hypothesis: true autocorrelation is greater than 0
dwtest(cons_lm2)
## 
##  Durbin-Watson test
## 
## data:  cons_lm2
## DW = 0.55408, p-value < 2.2e-16
## alternative hypothesis: true autocorrelation is greater than 0
dwtest(cons_lm3)
## 
##  Durbin-Watson test
## 
## data:  cons_lm3
## DW = 2.0825, p-value = 0.996
## alternative hypothesis: true autocorrelation is greater than 0
dwtest(cons_lm4)
## 
##  Durbin-Watson test
## 
## data:  cons_lm4
## DW = 0.64804, p-value < 2.2e-16
## alternative hypothesis: true autocorrelation is greater than 0

Uji Heterogenitas

bptest(cons_lm1)
## 
##  studentized Breusch-Pagan test
## 
## data:  cons_lm1
## BP = 51.049, df = 2, p-value = 8.222e-12
bptest(cons_lm2)
## 
##  studentized Breusch-Pagan test
## 
## data:  cons_lm2
## BP = 417.76, df = 2, p-value < 2.2e-16
bptest(cons_lm3)
## 
##  studentized Breusch-Pagan test
## 
## data:  cons_lm3
## BP = 1072.9, df = 3, p-value < 2.2e-16

Normalitas

shapiro.test(residuals(cons_lm1))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(cons_lm1)
## W = 0.67637, p-value < 2.2e-16
shapiro.test(residuals(cons_lm2))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(cons_lm2)
## W = 0.76397, p-value < 2.2e-16
shapiro.test(residuals(cons_lm3))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(cons_lm3)
## W = 0.63256, p-value < 2.2e-16
shapiro.test(residuals(cons_lm4))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(cons_lm4)
## W = 0.73161, p-value < 2.2e-16

Perbandingan Tiga Metode Penanganan Autokorelasi

Plot Perbandingan Data Aktual dengan Tiga Metode Penanganan Autokorelasi

par(mfrow=c(1,1))
plot(test$BATTERY_VOLTAGE, test$REF_TEMP, type="b", col="black")
points(test$BATTERY_VOLTAGE, fore.koyck$forecasts,col="red")
points(test$BATTERY_VOLTAGE, fore.dlm2$forecasts,col="blue")
points(test$BATTERY_VOLTAGE, fore.ardl$forecasts,col="green")
legend("topleft",c("aktual", "koyck","DLM", "autoregressive"), lty=1, col=c("black","red","blue","green"), cex=0.8)

Secara eksploratif, terlihat bahwa metode Distributel Lag Model merupakan metode yang sesuai untuk peramalan karena memiliki tren data yang paling mendekati pola data aktual dibandingkan dengan metode Koyck.

Perbandingan Keakuratan Ramalan

#TABEL
akurasi <- matrix(c(mape.koyck, mape.dlm, mape.dlm2, mape.ardl))
row.names(akurasi)<- c("Koyck","DLM 1","DLM 2","Autoregressive")
colnames(akurasi) <- c("MAPE")
akurasi
##                         MAPE
## Koyck          7.067076e+153
## DLM 1           1.844561e-02
## DLM 2           1.853903e-02
## Autoregressive  1.853903e-02

Diagnostik Model

Uji Non Autokorelasi

bgtest(model.dlm2$model)
## 
##  Breusch-Godfrey test for serial correlation of order up to 1
## 
## data:  model.dlm2$model
## LM test = 2616.4, df = 1, p-value < 2.2e-16

Uji Heterogenitas

bptest(model.dlm2$model)
## 
##  studentized Breusch-Pagan test
## 
## data:  model.dlm2$model
## BP = 323.34, df = 5, p-value < 2.2e-16

Diperoleh p-value =< 2.2e-16 < 0.05 Tolak H0, artinya cukup bukti untuk menyatakan bahwa terdapat autokorelasi pada model awal dengan taraf nyata 5%. Autokorelasi pada model masih belum berhasil ditangani, sehingga perlu dilakukan penanganan dengan metode lain.

Kesimpulan

Metode yang paling cocok untuk metode peramalan terbaik yaitu metode Distributed lag Model

Hasil uji diagnostik menunjukkan bahwa dengan metode Distributed lag Model autokorelasi pada model regresi deret waktu belum berhasil ditangani, sehingga perlu dilakukan uji lanjut atau penanganan dengan metode lain.