Simple Moving Average

Task 2 Time Series Analysis Practicum

Khusnia Nurul Khikmah (G1501211049)

1/31/2022

Question

The data used in this second practicum is the time series data selected in the first practicum assignment. Smooth the simple moving average with N=2,3,4,5, and 6 on the data. Then comparing the results of the smoothing accuracy of each method. Give the conclusion!

Upload the practicum 2 assignment. The compressed folder naming rule is NIM_Name_Prakt2 (7Z or ZIP). The folder consists of data files, R scripts, and the results.

Answer

This R program is also attached in: Smoothing Moving Average

Data

The data used is Daily Delhi climate data taken from Kaggle. This data has several variables: mean temperature, humidity, wind speed, and mean pressure. However, in this assignment, the variable used is wind speed only.

Read data

DailyDelhiClimateTest <- read.csv("D:/S2/IPB/STA542 Analisis Deret Waktu/1/Res/DailyDelhiClimateTest.csv", header=TRUE)
head(DailyDelhiClimateTest)
##         date meantemp humidity wind_speed meanpressure
## 1 2017-01-01 15.91304 85.86957   2.743478       59.000
## 2 2017-01-02 18.50000 77.22222   2.894444     1018.278
## 3 2017-01-03 17.11111 81.88889   4.016667     1018.333
## 4 2017-01-04 18.70000 70.05000   4.545000     1015.700
## 5 2017-01-05 18.38889 74.94444   3.300000     1014.333
## 6 2017-01-06 19.31818 79.31818   8.681818     1011.773

Data visualization

Before the visualization is carried out, the selected wind speed data will be formed into a time-series object with the ts function first.

DailyDelhiClimateTest.ts <- ts(DailyDelhiClimateTest$wind_speed, start=1) #form a time-series object
DailyDelhiClimateTest.ts
## Time Series:
## Start = 1 
## End = 114 
## Frequency = 1 
##   [1]  2.743478  2.894444  4.016667  4.545000  3.300000  8.681818 10.041667
##   [8]  1.950000  6.542857  9.361111  9.772222  6.626316  6.435294  5.276000
##  [15]  3.630435 10.380000  8.038889  6.029167 10.338095 11.226316 13.695652
##  [22]  5.868000  6.752941  3.391304  8.756000  8.467857 14.358333  9.690909
##  [29] 10.294444  4.322222  4.625000  5.100000  3.027273  1.854545  9.820000
##  [36]  8.100000  9.044444  7.637500  4.080000  7.875000  9.066667  3.950000
##  [43]  1.625000  6.377778  6.962500  5.557143 10.437500  9.280000  6.250000
##  [50]  6.054545  6.937500 12.341667  7.412500 14.350000 16.662500 11.928571
##  [57] 11.112500  5.100000  3.911111  6.415385  5.930000  7.412500  8.350000
##  [64]  9.962500  9.666667  6.025000 10.263636  8.342857 11.462500  5.566667
##  [71]  7.637500  9.055556  4.522222  7.175000  5.560000 11.490000  7.123077
##  [78]  9.161111 10.077778  9.262500 10.187500  3.487500 10.033333 10.425000
##  [85] 17.590000 13.650000  8.844444 13.200000 10.585714  6.950000  9.037500
##  [92]  9.262500  6.937500 14.320000 14.384615 13.577778  4.650000  8.337500
##  [99] 14.125000 19.314286 15.512500  9.487500  4.944444  1.387500  5.966667
## [106]  2.100000  5.366667  7.811111  9.025000  5.562500  6.962500  8.890000
## [113]  9.962500 12.157143
ts.plot(DailyDelhiClimateTest.ts)

Split data

The data used will be divided into train data and test data. Train data will be used for smoothing with a simple moving average of 80% and train data of 20%. Splitting this data using the subset function. The data splitting ratio of 80:20 was chosen because the wind speed data from the Daily Delhi Climate has a reasonably narrow range, which is between 0 to 20 and when viewed from the average value of 8.1439241. In addition, because the material is stationary data has not been discussed in this task, it still focuses on Smoothing Moving Average, and the 80:20 ratio is the best splitting ratio previously discussed in [Rácz, A. et al.].

options(digits = 8)

# Training set
train.DailyDelhiClimateTest.ts = subset(DailyDelhiClimateTest.ts, start=1,end=94)

# Testing set
test.DailyDelhiClimateTest.ts = subset(DailyDelhiClimateTest.ts, start=94,end=114)

Smoothing with a simple moving average

Smoothing with a simple moving average will be done in two ways, manually with the SMA function and automatically or by using the sma function available in the smooth packages.

Simple Moving Average, N=2

Manually

Smoothing with a simple moving average with the SMA function
DailyDelhiClimateTestSMA2<- SMA(train.DailyDelhiClimateTest.ts, n=2)
DailyDelhiClimateTestSMA2
## Time Series:
## Start = 1 
## End = 94 
## Frequency = 1 
##  [1]         NA  2.8189614  3.4555556  4.2808333  3.9225000  5.9909091
##  [7]  9.3617424  5.9958333  4.2464286  7.9519841  9.5666667  8.1992690
## [13]  6.5308050  5.8556471  4.4532174  7.0052174  9.2094444  7.0340278
## [19]  8.1836310 10.7822055 12.4609840  9.7818261  6.3104706  5.0721228
## [25]  6.0736522  8.6119286 11.4130952 12.0246212  9.9926768  7.3083333
## [31]  4.4736111  4.8625000  4.0636364  2.4409091  5.8372727  8.9600000
## [37]  8.5722222  8.3409722  5.8587500  5.9775000  8.4708333  6.5083333
## [43]  2.7875000  4.0013889  6.6701389  6.2598214  7.9973214  9.8587500
## [49]  7.7650000  6.1522727  6.4960227  9.6395833  9.8770833 10.8812500
## [55] 15.5062500 14.2955357 11.5205357  8.1062500  4.5055556  5.1632479
## [61]  6.1726923  6.6712500  7.8812500  9.1562500  9.8145833  7.8458333
## [67]  8.1443182  9.3032468  9.9026786  8.5145833  6.6020833  8.3465278
## [73]  6.7888889  5.8486111  6.3675000  8.5250000  9.3065385  8.1420940
## [79]  9.6194444  9.6701389  9.7250000  6.8375000  6.7604167 10.2291667
## [85] 14.0075000 15.6200000 11.2472222 11.0222222 11.8928571  8.7678571
## [91]  7.9937500  9.1500000  8.1000000 10.6287500
Visualization of Train set with Smoothing set
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate dan The smoothing data", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="red")
lines(DailyDelhiClimateTestSMA2)

Forecasting Simple Moving Average, N=2
DailyDelhiClimateTest.fc2<-c(NA,DailyDelhiClimateTestSMA2)
DailyDelhiClimateTest.fc2
##  [1]         NA         NA  2.8189614  3.4555556  4.2808333  3.9225000
##  [7]  5.9909091  9.3617424  5.9958333  4.2464286  7.9519841  9.5666667
## [13]  8.1992690  6.5308050  5.8556471  4.4532174  7.0052174  9.2094444
## [19]  7.0340278  8.1836310 10.7822055 12.4609840  9.7818261  6.3104706
## [25]  5.0721228  6.0736522  8.6119286 11.4130952 12.0246212  9.9926768
## [31]  7.3083333  4.4736111  4.8625000  4.0636364  2.4409091  5.8372727
## [37]  8.9600000  8.5722222  8.3409722  5.8587500  5.9775000  8.4708333
## [43]  6.5083333  2.7875000  4.0013889  6.6701389  6.2598214  7.9973214
## [49]  9.8587500  7.7650000  6.1522727  6.4960227  9.6395833  9.8770833
## [55] 10.8812500 15.5062500 14.2955357 11.5205357  8.1062500  4.5055556
## [61]  5.1632479  6.1726923  6.6712500  7.8812500  9.1562500  9.8145833
## [67]  7.8458333  8.1443182  9.3032468  9.9026786  8.5145833  6.6020833
## [73]  8.3465278  6.7888889  5.8486111  6.3675000  8.5250000  9.3065385
## [79]  8.1420940  9.6194444  9.6701389  9.7250000  6.8375000  6.7604167
## [85] 10.2291667 14.0075000 15.6200000 11.2472222 11.0222222 11.8928571
## [91]  8.7678571  7.9937500  9.1500000  8.1000000 10.6287500
Visualization of Train set with Forecasting set
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate dan The forecasting data", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="blue")
lines(DailyDelhiClimateTest.fc2)

All time series plots in one
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="red")
lines(DailyDelhiClimateTestSMA2)
par(col="blue")
lines(DailyDelhiClimateTest.fc2)
legend("topleft",c("Actual data","Smoothing Data N=2","Forecasting data"), lty=8, col=c("black","red","blue"), cex=0.8)

data2<-
cbind(Actual=c(train.DailyDelhiClimateTest.ts, rep(NA,20)),
      Smoothing=c(DailyDelhiClimateTestSMA2, rep(NA,20)),
      Forecasting=c(DailyDelhiClimateTest.fc2, rep(DailyDelhiClimateTest.fc2[length(DailyDelhiClimateTest.fc2)],19)))
data2.ts<-ts(data2, start=c(1))
data2.ts
## Time Series:
## Start = 1 
## End = 114 
## Frequency = 1 
##         Actual  Smoothing Forecasting
##   1  2.7434783         NA          NA
##   2  2.8944444  2.8189614          NA
##   3  4.0166667  3.4555556   2.8189614
##   4  4.5450000  4.2808333   3.4555556
##   5  3.3000000  3.9225000   4.2808333
##   6  8.6818182  5.9909091   3.9225000
##   7 10.0416667  9.3617424   5.9909091
##   8  1.9500000  5.9958333   9.3617424
##   9  6.5428571  4.2464286   5.9958333
##  10  9.3611111  7.9519841   4.2464286
##  11  9.7722222  9.5666667   7.9519841
##  12  6.6263158  8.1992690   9.5666667
##  13  6.4352941  6.5308050   8.1992690
##  14  5.2760000  5.8556471   6.5308050
##  15  3.6304348  4.4532174   5.8556471
##  16 10.3800000  7.0052174   4.4532174
##  17  8.0388889  9.2094444   7.0052174
##  18  6.0291667  7.0340278   9.2094444
##  19 10.3380952  8.1836310   7.0340278
##  20 11.2263158 10.7822055   8.1836310
##  21 13.6956522 12.4609840  10.7822055
##  22  5.8680000  9.7818261  12.4609840
##  23  6.7529412  6.3104706   9.7818261
##  24  3.3913043  5.0721228   6.3104706
##  25  8.7560000  6.0736522   5.0721228
##  26  8.4678571  8.6119286   6.0736522
##  27 14.3583333 11.4130952   8.6119286
##  28  9.6909091 12.0246212  11.4130952
##  29 10.2944444  9.9926768  12.0246212
##  30  4.3222222  7.3083333   9.9926768
##  31  4.6250000  4.4736111   7.3083333
##  32  5.1000000  4.8625000   4.4736111
##  33  3.0272727  4.0636364   4.8625000
##  34  1.8545455  2.4409091   4.0636364
##  35  9.8200000  5.8372727   2.4409091
##  36  8.1000000  8.9600000   5.8372727
##  37  9.0444444  8.5722222   8.9600000
##  38  7.6375000  8.3409722   8.5722222
##  39  4.0800000  5.8587500   8.3409722
##  40  7.8750000  5.9775000   5.8587500
##  41  9.0666667  8.4708333   5.9775000
##  42  3.9500000  6.5083333   8.4708333
##  43  1.6250000  2.7875000   6.5083333
##  44  6.3777778  4.0013889   2.7875000
##  45  6.9625000  6.6701389   4.0013889
##  46  5.5571429  6.2598214   6.6701389
##  47 10.4375000  7.9973214   6.2598214
##  48  9.2800000  9.8587500   7.9973214
##  49  6.2500000  7.7650000   9.8587500
##  50  6.0545455  6.1522727   7.7650000
##  51  6.9375000  6.4960227   6.1522727
##  52 12.3416667  9.6395833   6.4960227
##  53  7.4125000  9.8770833   9.6395833
##  54 14.3500000 10.8812500   9.8770833
##  55 16.6625000 15.5062500  10.8812500
##  56 11.9285714 14.2955357  15.5062500
##  57 11.1125000 11.5205357  14.2955357
##  58  5.1000000  8.1062500  11.5205357
##  59  3.9111111  4.5055556   8.1062500
##  60  6.4153846  5.1632479   4.5055556
##  61  5.9300000  6.1726923   5.1632479
##  62  7.4125000  6.6712500   6.1726923
##  63  8.3500000  7.8812500   6.6712500
##  64  9.9625000  9.1562500   7.8812500
##  65  9.6666667  9.8145833   9.1562500
##  66  6.0250000  7.8458333   9.8145833
##  67 10.2636364  8.1443182   7.8458333
##  68  8.3428571  9.3032468   8.1443182
##  69 11.4625000  9.9026786   9.3032468
##  70  5.5666667  8.5145833   9.9026786
##  71  7.6375000  6.6020833   8.5145833
##  72  9.0555556  8.3465278   6.6020833
##  73  4.5222222  6.7888889   8.3465278
##  74  7.1750000  5.8486111   6.7888889
##  75  5.5600000  6.3675000   5.8486111
##  76 11.4900000  8.5250000   6.3675000
##  77  7.1230769  9.3065385   8.5250000
##  78  9.1611111  8.1420940   9.3065385
##  79 10.0777778  9.6194444   8.1420940
##  80  9.2625000  9.6701389   9.6194444
##  81 10.1875000  9.7250000   9.6701389
##  82  3.4875000  6.8375000   9.7250000
##  83 10.0333333  6.7604167   6.8375000
##  84 10.4250000 10.2291667   6.7604167
##  85 17.5900000 14.0075000  10.2291667
##  86 13.6500000 15.6200000  14.0075000
##  87  8.8444444 11.2472222  15.6200000
##  88 13.2000000 11.0222222  11.2472222
##  89 10.5857143 11.8928571  11.0222222
##  90  6.9500000  8.7678571  11.8928571
##  91  9.0375000  7.9937500   8.7678571
##  92  9.2625000  9.1500000   7.9937500
##  93  6.9375000  8.1000000   9.1500000
##  94 14.3200000 10.6287500   8.1000000
##  95         NA         NA  10.6287500
##  96         NA         NA  10.6287500
##  97         NA         NA  10.6287500
##  98         NA         NA  10.6287500
##  99         NA         NA  10.6287500
## 100         NA         NA  10.6287500
## 101         NA         NA  10.6287500
## 102         NA         NA  10.6287500
## 103         NA         NA  10.6287500
## 104         NA         NA  10.6287500
## 105         NA         NA  10.6287500
## 106         NA         NA  10.6287500
## 107         NA         NA  10.6287500
## 108         NA         NA  10.6287500
## 109         NA         NA  10.6287500
## 110         NA         NA  10.6287500
## 111         NA         NA  10.6287500
## 112         NA         NA  10.6287500
## 113         NA         NA  10.6287500
## 114         NA         NA  10.6287500
Forecast Accuracy Measure Manually
error2=train.DailyDelhiClimateTest.ts - DailyDelhiClimateTest.fc2 [1:length(train.DailyDelhiClimateTest.ts)]
error2
## Time Series:
## Start = 1 
## End = 94 
## Frequency = 1 
##  [1]           NA           NA  1.197705314  1.089444444 -0.980833333
##  [6]  4.759318182  4.050757576 -7.411742424  0.547023810  5.114682540
## [11]  1.820238095 -2.940350877 -1.763974888 -1.254804954 -2.225212276
## [16]  5.926782609  1.033671498 -3.180277778  3.304067460  3.042684837
## [21]  2.913446660 -6.592983982 -3.028884910 -2.919166240  3.683877238
## [26]  2.394204969  5.746404762 -1.722186147 -1.730176768 -5.670454545
## [31] -2.683333333  0.626388889 -1.835227273 -2.209090909  7.379090909
## [36]  2.262727273  0.084444444 -0.934722222 -4.260972222  2.016250000
## [41]  3.089166667 -4.520833333 -4.883333333  3.590277778  2.961111111
## [46] -1.112996032  4.177678571  1.282678571 -3.608750000 -1.710454545
## [51]  0.785227273  5.845643939 -2.227083333  4.472916667  5.781250000
## [56] -3.577678571 -3.183035714 -6.420535714 -4.195138889  1.909829060
## [61]  0.766752137  1.239807692  1.678750000  2.081250000  0.510416667
## [66] -3.789583333  2.417803030  0.198538961  2.159253247 -4.336011905
## [71] -0.877083333  2.453472222 -3.824305556  0.386111111 -0.288611111
## [76]  5.122500000 -1.401923077 -0.145427350  1.935683761 -0.356944444
## [81]  0.517361111 -6.237500000  3.195833333  3.664583333  7.360833333
## [86] -0.357500000 -6.775555556  1.952777778 -0.436507937 -4.942857143
## [91]  0.269642857  1.268750000 -2.212500000  6.220000000
ME2=mean(error2[7:length(train.DailyDelhiClimateTest.ts)])
ME2
## [1] 0.084737862
MAD2=mean(abs(error2[7:length(train.DailyDelhiClimateTest.ts)]))
MAD2
## [1] 2.8980495
MSE2=mean(error2[7:length(train.DailyDelhiClimateTest.ts)]^2)
MSE2
## [1] 12.256419
MSE2.sqrt=sqrt(MSE2)
MSE2.sqrt1=1.25*MAD2
r.error2=((data2[,1]-data2[,3])/data2[,1])*100
MPE2=mean(r.error2[7:length(train.DailyDelhiClimateTest.ts)])
MPE2
## [1] -17.692994
MAPE2=mean(abs((error2[7:length(train.DailyDelhiClimateTest.ts)]/train.DailyDelhiClimateTest.ts[7:length(train.DailyDelhiClimateTest.ts)])*100))
MAPE2
## [1] 46.588328
AccuracyMeasur2 <- c(ME2, MAD2, MSE2, MPE2, MAPE2)
mod2 <- c("ME2", "MAD2","MSE2","MPE2", "MAPE2")
kompmodel2 <- cbind(mod2, AccuracyMeasur2)

Automatically

Smoothing by using the sma function available in the smooth packages.
DailyDelhiClimateTestSMA2 <- sma(train.DailyDelhiClimateTest.ts, order=2, ic=c("AIC","BIC"),h=3, holdout=FALSE)
summary(DailyDelhiClimateTestSMA2)
## Time elapsed: 0.15 seconds
## Model estimated: SMA(2)
## Initial values were produced using backcasting.
## 
## Loss function type: MSE; Loss function value: 11.7533
## Error standard deviation: 3.4654
## Sample size: 94
## Number of estimated parameters: 2
## Number of degrees of freedom: 92
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 502.3893 502.5212 507.4759 507.7755
forecast(DailyDelhiClimateTestSMA2)
## Time Series:
## Start = 95 
## End = 104 
## Frequency = 1 
##     Point forecast Lower bound (2.5%) Upper bound (97.5%)
##  95      10.628750         3.74621043           17.511290
##  96      12.474375         4.77946183           20.169288
##  97      11.551562         2.28566003           20.817465
##  98      12.012969         1.79726509           22.228672
##  99      11.782266         0.52393444           23.040597
## 100      11.897617        -0.23293508           24.028169
## 101      11.839941        -1.14210704           24.821990
## 102      11.868779        -1.89430434           25.631863
## 103      11.854360        -2.65625076           26.364971
## 104      11.861570        -3.35584719           27.078987
plot(forecast(DailyDelhiClimateTestSMA2))

AccuracyMeasurAuto2 <- c(502.3893, 502.5212, 507.4759, 507.7755)
modAuto2 <- c("AIC", "AICc","BIC","BICc")
kompmodelAuto2 <- cbind(modAuto2, AccuracyMeasurAuto2)

All of N=2 Forecast Accuracy Measure

colnames(kompmodel2) <- c("Accuracy Measure N=2", "Value")
kompmodelAll2 <- as.data.frame(rbind(kompmodel2, kompmodelAuto2))
kompmodelAll2
##   Accuracy Measure N=2              Value
## 1                  ME2 0.0847378615702394
## 2                 MAD2   2.89804949703823
## 3                 MSE2   12.2564187883676
## 4                 MPE2  -17.6929941041466
## 5                MAPE2   46.5883279125533
## 6                  AIC           502.3893
## 7                 AICc           502.5212
## 8                  BIC           507.4759
## 9                 BICc           507.7755

Simple Moving Average, N=3

Manually

Smoothing with a simple moving average with the SMA function
DailyDelhiClimateTestSMA3<- SMA(train.DailyDelhiClimateTest.ts, n=3)
DailyDelhiClimateTestSMA3
## Time Series:
## Start = 1 
## End = 94 
## Frequency = 1 
##  [1]         NA         NA  3.2181965  3.8187037  3.9538889  5.5089394
##  [7]  7.3411616  6.8911616  6.1781746  5.9513228  8.5587302  8.5865497
## [13]  7.6112774  6.1125366  5.1139096  6.4288116  7.3497746  8.1493519
## [19]  8.1353836  9.1978592 11.7533544 10.2633227  8.7721978  5.3374152
## [25]  6.3000818  6.8717205 10.5273968 10.8390332 11.4478956  8.1025253
## [31]  6.4138889  4.6824074  4.2507576  3.3272727  4.9006061  6.5915152
## [37]  8.9881481  8.2606481  6.9206481  6.5308333  7.0072222  6.9638889
## [43]  4.8805556  3.9842593  4.9884259  6.2991402  7.6523810  8.4248810
## [49]  8.6558333  7.1948485  6.4140152  8.4445707  8.8972222 11.3680556
## [55] 12.8083333 14.3136905 13.2345238  9.3803571  6.7078704  5.1421652
## [61]  5.4188319  6.5859615  7.2308333  8.5750000  9.3263889  8.5513889
## [67]  8.6517677  8.2104978 10.0229978  8.4573413  8.2222222  7.4199074
## [73]  7.0717593  6.9175926  5.7524074  8.0750000  8.0576923  9.2580627
## [79]  8.7873219  9.5004630  9.8425926  7.6458333  7.9027778  7.9819444
## [85] 12.6827778 13.8883333 13.3614815 11.8981481 10.8767196 10.2452381
## [91]  8.8577381  8.4166667  8.4125000 10.1733333
Visualization of Train set with Smoothing set
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate dan The smoothing data", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="red")
lines(DailyDelhiClimateTestSMA3)

Forecasting Simple Moving Average, N=3
DailyDelhiClimateTest.fc3<-c(NA,DailyDelhiClimateTestSMA3)
DailyDelhiClimateTest.fc3
##  [1]         NA         NA         NA  3.2181965  3.8187037  3.9538889
##  [7]  5.5089394  7.3411616  6.8911616  6.1781746  5.9513228  8.5587302
## [13]  8.5865497  7.6112774  6.1125366  5.1139096  6.4288116  7.3497746
## [19]  8.1493519  8.1353836  9.1978592 11.7533544 10.2633227  8.7721978
## [25]  5.3374152  6.3000818  6.8717205 10.5273968 10.8390332 11.4478956
## [31]  8.1025253  6.4138889  4.6824074  4.2507576  3.3272727  4.9006061
## [37]  6.5915152  8.9881481  8.2606481  6.9206481  6.5308333  7.0072222
## [43]  6.9638889  4.8805556  3.9842593  4.9884259  6.2991402  7.6523810
## [49]  8.4248810  8.6558333  7.1948485  6.4140152  8.4445707  8.8972222
## [55] 11.3680556 12.8083333 14.3136905 13.2345238  9.3803571  6.7078704
## [61]  5.1421652  5.4188319  6.5859615  7.2308333  8.5750000  9.3263889
## [67]  8.5513889  8.6517677  8.2104978 10.0229978  8.4573413  8.2222222
## [73]  7.4199074  7.0717593  6.9175926  5.7524074  8.0750000  8.0576923
## [79]  9.2580627  8.7873219  9.5004630  9.8425926  7.6458333  7.9027778
## [85]  7.9819444 12.6827778 13.8883333 13.3614815 11.8981481 10.8767196
## [91] 10.2452381  8.8577381  8.4166667  8.4125000 10.1733333
Visualization of Train set with Forecasting set
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate dan The forecasting data", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="blue")
lines(DailyDelhiClimateTest.fc3)

All time series plots in one
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="red")
lines(DailyDelhiClimateTestSMA3)
par(col="blue")
lines(DailyDelhiClimateTest.fc3)
legend("topleft",c("Actual data","Smoothing Data N=4","Forecasting data"), lty=8, col=c("black","red","blue"), cex=0.8)

data3<-
cbind(Actual=c(train.DailyDelhiClimateTest.ts, rep(NA,20)),
      Smoothing=c(DailyDelhiClimateTestSMA3, rep(NA,20)),
      Forecasting=c(DailyDelhiClimateTest.fc3, rep(DailyDelhiClimateTest.fc3[length(DailyDelhiClimateTest.fc3)],19)))
data3.ts<-ts(data3, start=c(1))
data3.ts
## Time Series:
## Start = 1 
## End = 114 
## Frequency = 1 
##         Actual  Smoothing Forecasting
##   1  2.7434783         NA          NA
##   2  2.8944444         NA          NA
##   3  4.0166667  3.2181965          NA
##   4  4.5450000  3.8187037   3.2181965
##   5  3.3000000  3.9538889   3.8187037
##   6  8.6818182  5.5089394   3.9538889
##   7 10.0416667  7.3411616   5.5089394
##   8  1.9500000  6.8911616   7.3411616
##   9  6.5428571  6.1781746   6.8911616
##  10  9.3611111  5.9513228   6.1781746
##  11  9.7722222  8.5587302   5.9513228
##  12  6.6263158  8.5865497   8.5587302
##  13  6.4352941  7.6112774   8.5865497
##  14  5.2760000  6.1125366   7.6112774
##  15  3.6304348  5.1139096   6.1125366
##  16 10.3800000  6.4288116   5.1139096
##  17  8.0388889  7.3497746   6.4288116
##  18  6.0291667  8.1493519   7.3497746
##  19 10.3380952  8.1353836   8.1493519
##  20 11.2263158  9.1978592   8.1353836
##  21 13.6956522 11.7533544   9.1978592
##  22  5.8680000 10.2633227  11.7533544
##  23  6.7529412  8.7721978  10.2633227
##  24  3.3913043  5.3374152   8.7721978
##  25  8.7560000  6.3000818   5.3374152
##  26  8.4678571  6.8717205   6.3000818
##  27 14.3583333 10.5273968   6.8717205
##  28  9.6909091 10.8390332  10.5273968
##  29 10.2944444 11.4478956  10.8390332
##  30  4.3222222  8.1025253  11.4478956
##  31  4.6250000  6.4138889   8.1025253
##  32  5.1000000  4.6824074   6.4138889
##  33  3.0272727  4.2507576   4.6824074
##  34  1.8545455  3.3272727   4.2507576
##  35  9.8200000  4.9006061   3.3272727
##  36  8.1000000  6.5915152   4.9006061
##  37  9.0444444  8.9881481   6.5915152
##  38  7.6375000  8.2606481   8.9881481
##  39  4.0800000  6.9206481   8.2606481
##  40  7.8750000  6.5308333   6.9206481
##  41  9.0666667  7.0072222   6.5308333
##  42  3.9500000  6.9638889   7.0072222
##  43  1.6250000  4.8805556   6.9638889
##  44  6.3777778  3.9842593   4.8805556
##  45  6.9625000  4.9884259   3.9842593
##  46  5.5571429  6.2991402   4.9884259
##  47 10.4375000  7.6523810   6.2991402
##  48  9.2800000  8.4248810   7.6523810
##  49  6.2500000  8.6558333   8.4248810
##  50  6.0545455  7.1948485   8.6558333
##  51  6.9375000  6.4140152   7.1948485
##  52 12.3416667  8.4445707   6.4140152
##  53  7.4125000  8.8972222   8.4445707
##  54 14.3500000 11.3680556   8.8972222
##  55 16.6625000 12.8083333  11.3680556
##  56 11.9285714 14.3136905  12.8083333
##  57 11.1125000 13.2345238  14.3136905
##  58  5.1000000  9.3803571  13.2345238
##  59  3.9111111  6.7078704   9.3803571
##  60  6.4153846  5.1421652   6.7078704
##  61  5.9300000  5.4188319   5.1421652
##  62  7.4125000  6.5859615   5.4188319
##  63  8.3500000  7.2308333   6.5859615
##  64  9.9625000  8.5750000   7.2308333
##  65  9.6666667  9.3263889   8.5750000
##  66  6.0250000  8.5513889   9.3263889
##  67 10.2636364  8.6517677   8.5513889
##  68  8.3428571  8.2104978   8.6517677
##  69 11.4625000 10.0229978   8.2104978
##  70  5.5666667  8.4573413  10.0229978
##  71  7.6375000  8.2222222   8.4573413
##  72  9.0555556  7.4199074   8.2222222
##  73  4.5222222  7.0717593   7.4199074
##  74  7.1750000  6.9175926   7.0717593
##  75  5.5600000  5.7524074   6.9175926
##  76 11.4900000  8.0750000   5.7524074
##  77  7.1230769  8.0576923   8.0750000
##  78  9.1611111  9.2580627   8.0576923
##  79 10.0777778  8.7873219   9.2580627
##  80  9.2625000  9.5004630   8.7873219
##  81 10.1875000  9.8425926   9.5004630
##  82  3.4875000  7.6458333   9.8425926
##  83 10.0333333  7.9027778   7.6458333
##  84 10.4250000  7.9819444   7.9027778
##  85 17.5900000 12.6827778   7.9819444
##  86 13.6500000 13.8883333  12.6827778
##  87  8.8444444 13.3614815  13.8883333
##  88 13.2000000 11.8981481  13.3614815
##  89 10.5857143 10.8767196  11.8981481
##  90  6.9500000 10.2452381  10.8767196
##  91  9.0375000  8.8577381  10.2452381
##  92  9.2625000  8.4166667   8.8577381
##  93  6.9375000  8.4125000   8.4166667
##  94 14.3200000 10.1733333   8.4125000
##  95         NA         NA  10.1733333
##  96         NA         NA  10.1733333
##  97         NA         NA  10.1733333
##  98         NA         NA  10.1733333
##  99         NA         NA  10.1733333
## 100         NA         NA  10.1733333
## 101         NA         NA  10.1733333
## 102         NA         NA  10.1733333
## 103         NA         NA  10.1733333
## 104         NA         NA  10.1733333
## 105         NA         NA  10.1733333
## 106         NA         NA  10.1733333
## 107         NA         NA  10.1733333
## 108         NA         NA  10.1733333
## 109         NA         NA  10.1733333
## 110         NA         NA  10.1733333
## 111         NA         NA  10.1733333
## 112         NA         NA  10.1733333
## 113         NA         NA  10.1733333
## 114         NA         NA  10.1733333
Forecast Accuracy Measure Manually
error3=train.DailyDelhiClimateTest.ts - DailyDelhiClimateTest.fc3 [1:length(train.DailyDelhiClimateTest.ts)]
error3
## Time Series:
## Start = 1 
## End = 94 
## Frequency = 1 
##  [1]          NA          NA          NA  1.32680354 -0.51870370  4.72792929
##  [7]  4.53272727 -5.39116162 -0.34830447  3.18293651  3.82089947 -1.93241437
## [13] -2.15125559 -2.33527738 -2.48210185  5.26609037  1.61007729 -1.32060789
## [19]  2.18874339  3.09093219  4.49779294 -5.88535440 -3.51038148 -5.38089344
## [25]  3.41858483  2.16777530  7.48661284 -0.83648773 -0.54458874 -7.12567340
## [31] -3.47752525 -1.31388889 -1.65513468 -2.39621212  6.49272727  3.19939394
## [37]  2.45292929 -1.35064815 -4.18064815  0.95435185  2.53583333 -3.05722222
## [43] -5.33888889  1.49722222  2.97824074  0.56871693  4.13835979  1.62761905
## [49] -2.17488095 -2.60128788 -0.25734848  5.92765152 -1.03207071  5.45277778
## [55]  5.29444444 -0.87976190 -3.20119048 -8.13452381 -5.46924603 -0.29248575
## [61]  0.78783476  1.99366809  1.76403846  2.73166667  1.09166667 -3.30138889
## [67]  1.71224747 -0.30891053  3.25200216 -4.45633117 -0.81984127  0.83333333
## [73] -2.89768519  0.10324074 -1.35759259  5.73759259 -0.95192308  1.10341880
## [79]  0.81971510  0.47517806  0.68703704 -6.35509259  2.38750000  2.52222222
## [85]  9.60805556  0.96722222 -5.04388889 -0.16148148 -1.31243386 -3.92671958
## [91] -1.20773810  0.40476190 -1.47916667  5.90750000
ME3=mean(error3[7:length(train.DailyDelhiClimateTest.ts)])
ME3
## [1] 0.10949638
MAD3=mean(abs(error3[7:length(train.DailyDelhiClimateTest.ts)]))
MAD3
## [1] 2.8285341
MSE3=mean(error3[7:length(train.DailyDelhiClimateTest.ts)]^2)
MSE3
## [1] 12.342084
MSE3.sqrt=sqrt(MSE3)
MSE3.sqrt1=1.25*MAD3
r.error3=((data3[,1]-data3[,3])/data3[,1])*100
MPE3=mean(r.error3[7:length(train.DailyDelhiClimateTest.ts)])
MPE3
## [1] -18.245483
MAPE3=mean(abs((error3[7:length(train.DailyDelhiClimateTest.ts)]/train.DailyDelhiClimateTest.ts[7:length(train.DailyDelhiClimateTest.ts)])*100))
MAPE3
## [1] 45.624035
AccuracyMeasur3 <- c(ME3, MAD3, MSE3, MPE3, MAPE3)
mod3 <- c("ME3", "MAD3","MSE3","MPE3", "MAPE3")
kompmodel3 <- cbind(mod3, AccuracyMeasur3)

Automatically

Smoothing by using the sma function available in the smooth packages.
DailyDelhiClimateTestAutoSMA3 <- sma(train.DailyDelhiClimateTest.ts, order=3, ic=c("AIC","BIC"),h=3, holdout=FALSE)
summary(DailyDelhiClimateTestAutoSMA3)
## Time elapsed: 0.01 seconds
## Model estimated: SMA(3)
## Initial values were produced using backcasting.
## 
## Loss function type: MSE; Loss function value: 11.8262
## Error standard deviation: 3.4761
## Sample size: 94
## Number of estimated parameters: 2
## Number of degrees of freedom: 92
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 502.9703 503.1022 508.0569 508.3565
forecast(DailyDelhiClimateTestAutoSMA3)
## Time Series:
## Start = 95 
## End = 104 
## Frequency = 1 
##     Point forecast Lower bound (2.5%) Upper bound (97.5%)
##  95      10.173333         3.26949185           17.077175
##  96      10.476944         3.19965654           17.754232
##  97      11.656759         3.75904831           19.554470
##  98      10.769012         1.87454935           19.663475
##  99      10.967572         1.53058592           20.404558
## 100      11.131115         1.08748008           21.174749
## 101      10.955900         0.29972317           21.612076
## 102      11.018195        -0.16240805           22.198799
## 103      11.035070        -0.66892431           22.739064
## 104      11.003055        -1.20409608           23.210206
plot(forecast(DailyDelhiClimateTestAutoSMA3))

All of N=3 Forecast Accuracy Measure

AccuracyMeasurAuto3 <- c(502.9703, 503.1022, 508.0569, 508.3565)
modAuto3 <- c("AIC", "AICc","BIC","BICc")
kompmodelAuto3 <- cbind(modAuto3, AccuracyMeasurAuto3)
colnames(kompmodel3) <- c("Accuracy Measure N=3", "Value")
kompmodelAll3 <- as.data.frame(rbind(kompmodel3, kompmodelAuto3))
kompmodelAll3
##   Accuracy Measure N=3             Value
## 1                  ME3  0.10949638429752
## 2                 MAD3  2.82853412505324
## 3                 MSE3  12.3420840534905
## 4                 MPE3 -18.2454827685466
## 5                MAPE3  45.6240348532701
## 6                  AIC          502.9703
## 7                 AICc          503.1022
## 8                  BIC          508.0569
## 9                 BICc          508.3565

Simple Moving Average, N=4

Manually

Smoothing with a simple moving average with the SMA function
DailyDelhiClimateTestSMA4<- SMA(train.DailyDelhiClimateTest.ts, n=4)
DailyDelhiClimateTestSMA4
## Time Series:
## Start = 1 
## End = 94 
## Frequency = 1 
##  [1]         NA         NA         NA  3.5498973  3.6890278  5.1358712
##  [7]  6.6421212  5.9933712  6.8040855  6.9739087  6.9065476  8.0756266
## [13]  8.0487358  7.0274580  5.4920112  6.4304322  6.8313309  7.0196226
## [19]  8.6965377  8.9081166 10.3223075 10.2820158  9.3857273  7.4269744
## [25]  6.1920614  6.8420257  8.7433737 10.3182749 10.7028860  9.6664773
## [31]  7.2331439  6.0854167  4.2686237  3.6517045  4.9504545  5.7004545
## [37]  7.2047475  8.6504861  7.2154861  7.1592361  7.1647917  6.2429167
## [43]  5.6291667  5.2548611  4.7288194  5.1306052  7.3337302  8.0592857
## [49]  7.8811607  8.0055114  7.1305114  7.8959280  8.1865530 10.2604167
## [55] 12.6916667 12.5883929 13.5133929 11.2008929  8.0130456  6.6347489
## [61]  5.3391239  5.9172489  7.0269712  7.9137500  8.8479167  8.5010417
## [67]  8.9794508  8.5745400  9.0234984  8.9089150  8.2523810  8.4305556
## [73]  6.6954861  7.0975694  6.5781944  7.1868056  7.8370192  8.3335470
## [79]  9.4629915  8.9061165  9.6722222  8.2538194  8.2427083  8.5333333
## [85] 10.3839583 12.9245833 12.6273611 13.3211111 11.5700397  9.8950397
## [91]  9.9433036  8.9589286  8.0468750  9.8893750
Visualization of Train set with Smoothing set
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate dan The smoothing data", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="red")
lines(DailyDelhiClimateTestSMA4)

Forecasting Simple Moving Average, N=4
DailyDelhiClimateTest.fc4<-c(NA,DailyDelhiClimateTestSMA4)
DailyDelhiClimateTest.fc4
##  [1]         NA         NA         NA         NA  3.5498973  3.6890278
##  [7]  5.1358712  6.6421212  5.9933712  6.8040855  6.9739087  6.9065476
## [13]  8.0756266  8.0487358  7.0274580  5.4920112  6.4304322  6.8313309
## [19]  7.0196226  8.6965377  8.9081166 10.3223075 10.2820158  9.3857273
## [25]  7.4269744  6.1920614  6.8420257  8.7433737 10.3182749 10.7028860
## [31]  9.6664773  7.2331439  6.0854167  4.2686237  3.6517045  4.9504545
## [37]  5.7004545  7.2047475  8.6504861  7.2154861  7.1592361  7.1647917
## [43]  6.2429167  5.6291667  5.2548611  4.7288194  5.1306052  7.3337302
## [49]  8.0592857  7.8811607  8.0055114  7.1305114  7.8959280  8.1865530
## [55] 10.2604167 12.6916667 12.5883929 13.5133929 11.2008929  8.0130456
## [61]  6.6347489  5.3391239  5.9172489  7.0269712  7.9137500  8.8479167
## [67]  8.5010417  8.9794508  8.5745400  9.0234984  8.9089150  8.2523810
## [73]  8.4305556  6.6954861  7.0975694  6.5781944  7.1868056  7.8370192
## [79]  8.3335470  9.4629915  8.9061165  9.6722222  8.2538194  8.2427083
## [85]  8.5333333 10.3839583 12.9245833 12.6273611 13.3211111 11.5700397
## [91]  9.8950397  9.9433036  8.9589286  8.0468750  9.8893750
Visualization of Train set with Forecasting set
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate dan The forecasting data", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="blue")
lines(DailyDelhiClimateTest.fc4)

All time series plots in one
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="red")
lines(DailyDelhiClimateTestSMA4)
par(col="blue")
lines(DailyDelhiClimateTest.fc4)
legend("topleft",c("Actual data","Smoothing Data N=4","Forecasting data"), lty=8, col=c("black","red","blue"), cex=0.8)

data4<-
cbind(Actual=c(train.DailyDelhiClimateTest.ts, rep(NA,20)),
      Smoothing=c(DailyDelhiClimateTestSMA4, rep(NA,20)),
      Forecasting=c(DailyDelhiClimateTest.fc4, rep(DailyDelhiClimateTest.fc4[length(DailyDelhiClimateTest.fc4)],19)))
data4.ts<-ts(data4, start=c(1))
data4.ts
## Time Series:
## Start = 1 
## End = 114 
## Frequency = 1 
##         Actual  Smoothing Forecasting
##   1  2.7434783         NA          NA
##   2  2.8944444         NA          NA
##   3  4.0166667         NA          NA
##   4  4.5450000  3.5498973          NA
##   5  3.3000000  3.6890278   3.5498973
##   6  8.6818182  5.1358712   3.6890278
##   7 10.0416667  6.6421212   5.1358712
##   8  1.9500000  5.9933712   6.6421212
##   9  6.5428571  6.8040855   5.9933712
##  10  9.3611111  6.9739087   6.8040855
##  11  9.7722222  6.9065476   6.9739087
##  12  6.6263158  8.0756266   6.9065476
##  13  6.4352941  8.0487358   8.0756266
##  14  5.2760000  7.0274580   8.0487358
##  15  3.6304348  5.4920112   7.0274580
##  16 10.3800000  6.4304322   5.4920112
##  17  8.0388889  6.8313309   6.4304322
##  18  6.0291667  7.0196226   6.8313309
##  19 10.3380952  8.6965377   7.0196226
##  20 11.2263158  8.9081166   8.6965377
##  21 13.6956522 10.3223075   8.9081166
##  22  5.8680000 10.2820158  10.3223075
##  23  6.7529412  9.3857273  10.2820158
##  24  3.3913043  7.4269744   9.3857273
##  25  8.7560000  6.1920614   7.4269744
##  26  8.4678571  6.8420257   6.1920614
##  27 14.3583333  8.7433737   6.8420257
##  28  9.6909091 10.3182749   8.7433737
##  29 10.2944444 10.7028860  10.3182749
##  30  4.3222222  9.6664773  10.7028860
##  31  4.6250000  7.2331439   9.6664773
##  32  5.1000000  6.0854167   7.2331439
##  33  3.0272727  4.2686237   6.0854167
##  34  1.8545455  3.6517045   4.2686237
##  35  9.8200000  4.9504545   3.6517045
##  36  8.1000000  5.7004545   4.9504545
##  37  9.0444444  7.2047475   5.7004545
##  38  7.6375000  8.6504861   7.2047475
##  39  4.0800000  7.2154861   8.6504861
##  40  7.8750000  7.1592361   7.2154861
##  41  9.0666667  7.1647917   7.1592361
##  42  3.9500000  6.2429167   7.1647917
##  43  1.6250000  5.6291667   6.2429167
##  44  6.3777778  5.2548611   5.6291667
##  45  6.9625000  4.7288194   5.2548611
##  46  5.5571429  5.1306052   4.7288194
##  47 10.4375000  7.3337302   5.1306052
##  48  9.2800000  8.0592857   7.3337302
##  49  6.2500000  7.8811607   8.0592857
##  50  6.0545455  8.0055114   7.8811607
##  51  6.9375000  7.1305114   8.0055114
##  52 12.3416667  7.8959280   7.1305114
##  53  7.4125000  8.1865530   7.8959280
##  54 14.3500000 10.2604167   8.1865530
##  55 16.6625000 12.6916667  10.2604167
##  56 11.9285714 12.5883929  12.6916667
##  57 11.1125000 13.5133929  12.5883929
##  58  5.1000000 11.2008929  13.5133929
##  59  3.9111111  8.0130456  11.2008929
##  60  6.4153846  6.6347489   8.0130456
##  61  5.9300000  5.3391239   6.6347489
##  62  7.4125000  5.9172489   5.3391239
##  63  8.3500000  7.0269712   5.9172489
##  64  9.9625000  7.9137500   7.0269712
##  65  9.6666667  8.8479167   7.9137500
##  66  6.0250000  8.5010417   8.8479167
##  67 10.2636364  8.9794508   8.5010417
##  68  8.3428571  8.5745400   8.9794508
##  69 11.4625000  9.0234984   8.5745400
##  70  5.5666667  8.9089150   9.0234984
##  71  7.6375000  8.2523810   8.9089150
##  72  9.0555556  8.4305556   8.2523810
##  73  4.5222222  6.6954861   8.4305556
##  74  7.1750000  7.0975694   6.6954861
##  75  5.5600000  6.5781944   7.0975694
##  76 11.4900000  7.1868056   6.5781944
##  77  7.1230769  7.8370192   7.1868056
##  78  9.1611111  8.3335470   7.8370192
##  79 10.0777778  9.4629915   8.3335470
##  80  9.2625000  8.9061165   9.4629915
##  81 10.1875000  9.6722222   8.9061165
##  82  3.4875000  8.2538194   9.6722222
##  83 10.0333333  8.2427083   8.2538194
##  84 10.4250000  8.5333333   8.2427083
##  85 17.5900000 10.3839583   8.5333333
##  86 13.6500000 12.9245833  10.3839583
##  87  8.8444444 12.6273611  12.9245833
##  88 13.2000000 13.3211111  12.6273611
##  89 10.5857143 11.5700397  13.3211111
##  90  6.9500000  9.8950397  11.5700397
##  91  9.0375000  9.9433036   9.8950397
##  92  9.2625000  8.9589286   9.9433036
##  93  6.9375000  8.0468750   8.9589286
##  94 14.3200000  9.8893750   8.0468750
##  95         NA         NA   9.8893750
##  96         NA         NA   9.8893750
##  97         NA         NA   9.8893750
##  98         NA         NA   9.8893750
##  99         NA         NA   9.8893750
## 100         NA         NA   9.8893750
## 101         NA         NA   9.8893750
## 102         NA         NA   9.8893750
## 103         NA         NA   9.8893750
## 104         NA         NA   9.8893750
## 105         NA         NA   9.8893750
## 106         NA         NA   9.8893750
## 107         NA         NA   9.8893750
## 108         NA         NA   9.8893750
## 109         NA         NA   9.8893750
## 110         NA         NA   9.8893750
## 111         NA         NA   9.8893750
## 112         NA         NA   9.8893750
## 113         NA         NA   9.8893750
## 114         NA         NA   9.8893750
Forecast Accuracy Measure Manually
error4=train.DailyDelhiClimateTest.ts - DailyDelhiClimateTest.fc4 [1:length(train.DailyDelhiClimateTest.ts)]
error4
## Time Series:
## Start = 1 
## End = 94 
## Frequency = 1 
##  [1]           NA           NA           NA           NA -0.249897343
##  [6]  4.992790404  4.905795455 -4.692121212  0.549485931  2.557025613
## [11]  2.798313492 -0.280231830 -1.640332449 -2.772735810 -3.397023250
## [16]  4.887988828  1.608456664 -0.802164251  3.318472654  2.529778091
## [21]  4.787535528 -4.454307467 -3.529074624 -5.994422937  1.329025575
## [26]  2.275795762  7.516307667  0.947535385 -0.023830447 -6.380663781
## [31] -5.041477273 -2.133143939 -3.058143939 -2.414078283  6.168295455
## [36]  3.149545455  3.343989899  0.432752525 -4.570486111  0.659513889
## [41]  1.907430556 -3.214791667 -4.617916667  0.748611111  1.707638889
## [46]  0.828323413  5.306894841  1.946269841 -1.809285714 -1.826615260
## [51] -1.068011364  5.211155303 -0.483428030  6.163446970  6.402083333
## [56] -0.763095238 -1.475892857 -8.413392857 -7.289781746 -1.597661020
## [61] -0.704748932  2.073376068  2.432751068  2.935528846  1.752916667
## [66] -2.822916667  1.762594697 -0.636593615  2.887959957 -3.456831710
## [71] -1.271415043  0.803174603 -3.908333333  0.479513889 -1.537569444
## [76]  4.911805556 -0.063728632  1.324091880  1.744230769 -0.200491453
## [81]  1.281383547 -6.184722222  1.779513889  2.182291667  9.056666667
## [86]  3.266041667 -4.080138889  0.572638889 -2.735396825 -4.620039683
## [91] -0.857539683 -0.680803571 -2.021428571  6.273125000
ME4=mean(error4[7:length(train.DailyDelhiClimateTest.ts)])
ME4
## [1] 0.13613938
MAD4=mean(abs(error4[7:length(train.DailyDelhiClimateTest.ts)]))
MAD4
## [1] 2.8526577
MSE4=mean(error4[7:length(train.DailyDelhiClimateTest.ts)]^2)
MSE4
## [1] 12.480498
MSE4.sqrt=sqrt(MSE4)
MSE4.sqrt1=1.25*MAD4
r.error4=((data4[,1]-data4[,3])/data4[,1])*100
MPE4=mean(r.error4[7:length(train.DailyDelhiClimateTest.ts)])
MPE4
## [1] -18.600041
MAPE4=mean(abs((error4[7:length(train.DailyDelhiClimateTest.ts)]/train.DailyDelhiClimateTest.ts[7:length(train.DailyDelhiClimateTest.ts)])*100))
MAPE4
## [1] 46.017028
AccuracyMeasur4 <- c(ME4, MAD4, MSE4, MPE4, MAPE4)
mod4 <- c("ME4", "MAD4","MSE4","MPE4", "MAPE4")
kompmodel4 <- cbind(mod4, AccuracyMeasur4)

Automatically

smoothing by using the sma function available in the smooth packages.
DailyDelhiClimateTestAutoSMA4 <- sma(train.DailyDelhiClimateTest.ts, order=4, ic=c("AIC","BIC"),h=3, holdout=FALSE)
summary(DailyDelhiClimateTestAutoSMA4)
## Time elapsed: 0.01 seconds
## Model estimated: SMA(4)
## Initial values were produced using backcasting.
## 
## Loss function type: MSE; Loss function value: 11.9827
## Error standard deviation: 3.499
## Sample size: 94
## Number of estimated parameters: 2
## Number of degrees of freedom: 92
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 504.2058 504.3376 509.2924 509.5919
forecast(DailyDelhiClimateTestAutoSMA4)
## Time Series:
## Start = 95 
## End = 104 
## Frequency = 1 
##     Point forecast Lower bound (2.5%) Upper bound (97.5%)
##  95       9.889375        2.940014798           16.838735
##  96      10.102344        2.939107215           17.265580
##  97      10.312305        2.827110619           17.797499
##  98      11.156006        3.193773139           19.118239
##  99      10.365007        1.709879185           19.020135
## 100      10.483915        1.473791938           19.494039
## 101      10.579308        1.174502695           19.984114
## 102      10.646059        0.825556723           20.466562
## 103      10.518573        0.291459661           20.745685
## 104      10.556964       -0.025818223           21.139746
plot(forecast(DailyDelhiClimateTestAutoSMA4))

All of N=4 Forecast Accuracy Measure

AccuracyMeasurAuto4 <- c(504.2058, 504.3376, 509.2924, 509.5919)
modAuto4 <- c("AIC", "AICc","BIC","BICc")
kompmodelAuto4 <- cbind(modAuto4, AccuracyMeasurAuto4)
colnames(kompmodel4) <- c("Accuracy Measure N=4", "Value")
kompmodelAll4 <- as.data.frame(rbind(kompmodel4, kompmodelAuto4))
kompmodelAll4
##   Accuracy Measure N=4             Value
## 1                  ME4 0.136139376721768
## 2                 MAD4  2.85265774709068
## 3                 MSE4  12.4804984807303
## 4                 MPE4 -18.6000407778462
## 5                MAPE4  46.0170278740535
## 6                  AIC          504.2058
## 7                 AICc          504.3376
## 8                  BIC          509.2924
## 9                 BICc          509.5919

Simple Moving Average, N=5

Manually

Smoothing with a simple moving average with the SMA function
DailyDelhiClimateTestSMA5<- SMA(train.DailyDelhiClimateTest.ts, n=5)
DailyDelhiClimateTestSMA5
## Time Series:
## Start = 1 
## End = 94 
## Frequency = 1 
##  [1]         NA         NA         NA         NA  3.4999179  4.6875859
##  [7]  6.1170303  5.7036970  6.1032684  7.3154906  7.5335714  6.8505013
## [13]  7.7475601  7.4941886  6.3480534  6.4696089  6.7521236  6.6708981
## [19]  7.6833171  9.2024933  9.8656238  9.4314460  9.5762009  8.1868427
## [25]  7.6927795  6.6472205  8.3452872  8.9328808 10.3135088  9.4267532
## [31]  8.6581818  6.8065152  5.4737879  3.7858081  4.8853636  5.5803636
## [37]  6.3692525  7.2912980  7.7363889  7.3473889  7.5407222  6.5218333
## [43]  5.3193333  5.7788889  5.5963889  4.8944841  6.1919841  7.7229841
## [49]  7.6974286  7.5158377  7.7919091  8.1727424  7.7992424  9.4192424
## [55] 11.5408333 12.5390476 12.2932143 11.8307143  9.7429365  7.6935134
## [61]  6.4937991  5.7537991  6.4037991  7.6140769  8.2643333  8.2833333
## [67]  8.8535606  8.8521320  9.1521320  8.3321320  8.6546320  8.4130159
## [73]  7.6488889  6.7913889  6.7900556  7.5605556  7.1740598  8.1018376
## [79]  8.6823932  9.4228932  9.1623932  8.4352778  8.6097222  8.6791667
## [85] 10.3446667 11.0371667 12.1085556 12.7418889 12.7740317 10.6460317
## [91]  9.7235317  9.8071429  8.5546429  9.3015000
Visualization of Train set with Smoothing set
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate dan The smoothing data", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="red")
lines(DailyDelhiClimateTestSMA5)

Forecasting Simple Moving Average, N=5
DailyDelhiClimateTest.fc5<-c(NA,DailyDelhiClimateTestSMA5)
DailyDelhiClimateTest.fc5
##  [1]         NA         NA         NA         NA         NA  3.4999179
##  [7]  4.6875859  6.1170303  5.7036970  6.1032684  7.3154906  7.5335714
## [13]  6.8505013  7.7475601  7.4941886  6.3480534  6.4696089  6.7521236
## [19]  6.6708981  7.6833171  9.2024933  9.8656238  9.4314460  9.5762009
## [25]  8.1868427  7.6927795  6.6472205  8.3452872  8.9328808 10.3135088
## [31]  9.4267532  8.6581818  6.8065152  5.4737879  3.7858081  4.8853636
## [37]  5.5803636  6.3692525  7.2912980  7.7363889  7.3473889  7.5407222
## [43]  6.5218333  5.3193333  5.7788889  5.5963889  4.8944841  6.1919841
## [49]  7.7229841  7.6974286  7.5158377  7.7919091  8.1727424  7.7992424
## [55]  9.4192424 11.5408333 12.5390476 12.2932143 11.8307143  9.7429365
## [61]  7.6935134  6.4937991  5.7537991  6.4037991  7.6140769  8.2643333
## [67]  8.2833333  8.8535606  8.8521320  9.1521320  8.3321320  8.6546320
## [73]  8.4130159  7.6488889  6.7913889  6.7900556  7.5605556  7.1740598
## [79]  8.1018376  8.6823932  9.4228932  9.1623932  8.4352778  8.6097222
## [85]  8.6791667 10.3446667 11.0371667 12.1085556 12.7418889 12.7740317
## [91] 10.6460317  9.7235317  9.8071429  8.5546429  9.3015000
Visualization of Train set with Forecasting set
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate dan The forecasting data", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="blue")
lines(DailyDelhiClimateTest.fc5)

All time series plots in one
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="red")
lines(DailyDelhiClimateTestSMA5)
par(col="blue")
lines(DailyDelhiClimateTest.fc5)
legend("topleft",c("Actual data","Smoothing Data N=5","Forecasting data"), lty=8, col=c("black","red","blue"), cex=0.8)

data5 <-
cbind(Actual=c(train.DailyDelhiClimateTest.ts, rep(NA,20)),
      Smoothing=c(DailyDelhiClimateTestSMA5, rep(NA,20)),
      Forecasting=c(DailyDelhiClimateTest.fc5, rep(DailyDelhiClimateTest.fc5[length(DailyDelhiClimateTest.fc5)],19)))
data5.ts<-ts(data5, start=c(1))
data5.ts
## Time Series:
## Start = 1 
## End = 114 
## Frequency = 1 
##         Actual  Smoothing Forecasting
##   1  2.7434783         NA          NA
##   2  2.8944444         NA          NA
##   3  4.0166667         NA          NA
##   4  4.5450000         NA          NA
##   5  3.3000000  3.4999179          NA
##   6  8.6818182  4.6875859   3.4999179
##   7 10.0416667  6.1170303   4.6875859
##   8  1.9500000  5.7036970   6.1170303
##   9  6.5428571  6.1032684   5.7036970
##  10  9.3611111  7.3154906   6.1032684
##  11  9.7722222  7.5335714   7.3154906
##  12  6.6263158  6.8505013   7.5335714
##  13  6.4352941  7.7475601   6.8505013
##  14  5.2760000  7.4941886   7.7475601
##  15  3.6304348  6.3480534   7.4941886
##  16 10.3800000  6.4696089   6.3480534
##  17  8.0388889  6.7521236   6.4696089
##  18  6.0291667  6.6708981   6.7521236
##  19 10.3380952  7.6833171   6.6708981
##  20 11.2263158  9.2024933   7.6833171
##  21 13.6956522  9.8656238   9.2024933
##  22  5.8680000  9.4314460   9.8656238
##  23  6.7529412  9.5762009   9.4314460
##  24  3.3913043  8.1868427   9.5762009
##  25  8.7560000  7.6927795   8.1868427
##  26  8.4678571  6.6472205   7.6927795
##  27 14.3583333  8.3452872   6.6472205
##  28  9.6909091  8.9328808   8.3452872
##  29 10.2944444 10.3135088   8.9328808
##  30  4.3222222  9.4267532  10.3135088
##  31  4.6250000  8.6581818   9.4267532
##  32  5.1000000  6.8065152   8.6581818
##  33  3.0272727  5.4737879   6.8065152
##  34  1.8545455  3.7858081   5.4737879
##  35  9.8200000  4.8853636   3.7858081
##  36  8.1000000  5.5803636   4.8853636
##  37  9.0444444  6.3692525   5.5803636
##  38  7.6375000  7.2912980   6.3692525
##  39  4.0800000  7.7363889   7.2912980
##  40  7.8750000  7.3473889   7.7363889
##  41  9.0666667  7.5407222   7.3473889
##  42  3.9500000  6.5218333   7.5407222
##  43  1.6250000  5.3193333   6.5218333
##  44  6.3777778  5.7788889   5.3193333
##  45  6.9625000  5.5963889   5.7788889
##  46  5.5571429  4.8944841   5.5963889
##  47 10.4375000  6.1919841   4.8944841
##  48  9.2800000  7.7229841   6.1919841
##  49  6.2500000  7.6974286   7.7229841
##  50  6.0545455  7.5158377   7.6974286
##  51  6.9375000  7.7919091   7.5158377
##  52 12.3416667  8.1727424   7.7919091
##  53  7.4125000  7.7992424   8.1727424
##  54 14.3500000  9.4192424   7.7992424
##  55 16.6625000 11.5408333   9.4192424
##  56 11.9285714 12.5390476  11.5408333
##  57 11.1125000 12.2932143  12.5390476
##  58  5.1000000 11.8307143  12.2932143
##  59  3.9111111  9.7429365  11.8307143
##  60  6.4153846  7.6935134   9.7429365
##  61  5.9300000  6.4937991   7.6935134
##  62  7.4125000  5.7537991   6.4937991
##  63  8.3500000  6.4037991   5.7537991
##  64  9.9625000  7.6140769   6.4037991
##  65  9.6666667  8.2643333   7.6140769
##  66  6.0250000  8.2833333   8.2643333
##  67 10.2636364  8.8535606   8.2833333
##  68  8.3428571  8.8521320   8.8535606
##  69 11.4625000  9.1521320   8.8521320
##  70  5.5666667  8.3321320   9.1521320
##  71  7.6375000  8.6546320   8.3321320
##  72  9.0555556  8.4130159   8.6546320
##  73  4.5222222  7.6488889   8.4130159
##  74  7.1750000  6.7913889   7.6488889
##  75  5.5600000  6.7900556   6.7913889
##  76 11.4900000  7.5605556   6.7900556
##  77  7.1230769  7.1740598   7.5605556
##  78  9.1611111  8.1018376   7.1740598
##  79 10.0777778  8.6823932   8.1018376
##  80  9.2625000  9.4228932   8.6823932
##  81 10.1875000  9.1623932   9.4228932
##  82  3.4875000  8.4352778   9.1623932
##  83 10.0333333  8.6097222   8.4352778
##  84 10.4250000  8.6791667   8.6097222
##  85 17.5900000 10.3446667   8.6791667
##  86 13.6500000 11.0371667  10.3446667
##  87  8.8444444 12.1085556  11.0371667
##  88 13.2000000 12.7418889  12.1085556
##  89 10.5857143 12.7740317  12.7418889
##  90  6.9500000 10.6460317  12.7740317
##  91  9.0375000  9.7235317  10.6460317
##  92  9.2625000  9.8071429   9.7235317
##  93  6.9375000  8.5546429   9.8071429
##  94 14.3200000  9.3015000   8.5546429
##  95         NA         NA   9.3015000
##  96         NA         NA   9.3015000
##  97         NA         NA   9.3015000
##  98         NA         NA   9.3015000
##  99         NA         NA   9.3015000
## 100         NA         NA   9.3015000
## 101         NA         NA   9.3015000
## 102         NA         NA   9.3015000
## 103         NA         NA   9.3015000
## 104         NA         NA   9.3015000
## 105         NA         NA   9.3015000
## 106         NA         NA   9.3015000
## 107         NA         NA   9.3015000
## 108         NA         NA   9.3015000
## 109         NA         NA   9.3015000
## 110         NA         NA   9.3015000
## 111         NA         NA   9.3015000
## 112         NA         NA   9.3015000
## 113         NA         NA   9.3015000
## 114         NA         NA   9.3015000
Forecast Accuracy Measure Manually
error5=train.DailyDelhiClimateTest.ts - DailyDelhiClimateTest.fc5 [1:length(train.DailyDelhiClimateTest.ts)]
error5
## Time Series:
## Start = 1 
## End = 94 
## Frequency = 1 
##  [1]           NA           NA           NA           NA           NA
##  [6]  5.181900307  5.354080808 -4.167030303  0.839160173  3.257842713
## [11]  2.456731602 -0.907255639 -0.415207135 -2.471560077 -3.863753865
## [16]  4.031946618  1.569279951 -0.722956891  3.667197170  3.542998674
## [21]  4.493158857 -3.997623751 -2.678504797 -6.184896528  0.569157302
## [26]  0.775077603  7.711112800  1.345621891  1.361563661 -5.991286580
## [31] -4.801753247 -3.558181818 -3.779242424 -3.619242424  6.034191919
## [36]  3.214636364  3.464080808  1.268247475 -3.211297980  0.138611111
## [41]  1.719277778 -3.590722222 -4.896833333  1.058444444  1.183611111
## [46] -0.039246032  5.543015873  3.088015873 -1.472984127 -1.642883117
## [51] -0.578337662  4.549757576 -0.760242424  6.550757576  7.243257576
## [56]  0.387738095 -1.426547619 -7.193214286 -7.919603175 -3.327551893
## [61] -1.763513431  0.918700855  2.596200855  3.558700855  2.052589744
## [66] -2.239333333  1.980303030 -0.510703463  2.610367965 -3.585465368
## [71] -0.694632035  0.400923521 -3.890793651 -0.473888889 -1.231388889
## [76]  4.699944444 -0.437478632  1.987051282  1.975940171  0.580106838
## [81]  0.764606838 -5.674893162  1.598055556  1.815277778  8.910833333
## [86]  3.305333333 -2.192722222  1.091444444 -2.156174603 -5.824031746
## [91] -1.608531746 -0.461031746 -2.869642857  5.765357143
ME5=mean(error5[7:length(train.DailyDelhiClimateTest.ts)])
ME5
## [1] 0.16134234
MAD5=mean(abs(error5[7:length(train.DailyDelhiClimateTest.ts)]))
MAD5
## [1] 2.8620738
MSE5=mean(error5[7:length(train.DailyDelhiClimateTest.ts)]^2)
MSE5
## [1] 12.504732
MSE5.sqrt=sqrt(MSE5)
MSE5.sqrt1=1.25*MAD5
r.error5=((data5[,1]-data5[,3])/data5[,1])*100
MPE5=mean(r.error5[7:length(train.DailyDelhiClimateTest.ts)])
MPE5
## [1] -19.176826
MAPE5=mean(abs((error5[7:length(train.DailyDelhiClimateTest.ts)]/train.DailyDelhiClimateTest.ts[7:length(train.DailyDelhiClimateTest.ts)])*100))
MAPE5
## [1] 46.594702
AccuracyMeasur5 <- c(ME5, MAD5, MSE5, MPE5, MAPE5)
mod5 <- c("ME5", "MAD5","MSE5","MPE5", "MAPE5")
kompmodel5 <- cbind(mod5, AccuracyMeasur5)

Automatically

Smoothing by using the sma function available in the smooth packages.
DailyDelhiClimateTestAutoSMA5 <- sma(train.DailyDelhiClimateTest.ts, order=5, ic=c("AIC","BIC"),h=3, holdout=FALSE)
summary(DailyDelhiClimateTestAutoSMA5)
## Time elapsed: 0 seconds
## Model estimated: SMA(5)
## Initial values were produced using backcasting.
## 
## Loss function type: MSE; Loss function value: 12.0234
## Error standard deviation: 3.505
## Sample size: 94
## Number of estimated parameters: 2
## Number of degrees of freedom: 92
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 504.5249 504.6568 509.6115 509.9111
forecast(DailyDelhiClimateTestAutoSMA5)
## Time Series:
## Start = 95 
## End = 104 
## Frequency = 1 
##     Point forecast Lower bound (2.5%) Upper bound (97.5%)
##  95      9.3015000         2.34033187           16.262668
##  96      9.7718000         2.67277358           16.870826
##  97      9.9186600         2.62569428           17.211626
##  98     10.0498920         2.48638502           17.613399
##  99     10.6723704         2.73546837           18.609272
## 100      9.9428445         1.49720588           18.388483
## 101     10.0711134         1.37500133           18.767225
## 102     10.1309761         1.15891415           19.103038
## 103     10.1734393         0.90739356           19.439485
## 104     10.1981487         0.63190776           19.764390
plot(forecast(DailyDelhiClimateTestAutoSMA5))

All of N=5 Forecast Accuracy Measure

AccuracyMeasurAuto5 <- c(504.5249, 504.6568, 509.6115, 509.9111)
modAuto5 <- c("AIC", "AICc","BIC","BICc")
kompmodelAuto5 <- cbind(modAuto5, AccuracyMeasurAuto5)
colnames(kompmodel5) <- c("Accuracy Measure N=5", "Value")
kompmodelAll5 <- as.data.frame(rbind(kompmodel5, kompmodelAuto5))
kompmodelAll5
##   Accuracy Measure N=5             Value
## 1                  ME5  0.16134234389348
## 2                 MAD5  2.86207382399456
## 3                 MSE5  12.5047324017883
## 4                 MPE5 -19.1768260307426
## 5                MAPE5  46.5947024010929
## 6                  AIC          504.5249
## 7                 AICc          504.6568
## 8                  BIC          509.6115
## 9                 BICc          509.9111

Simple Moving Average, N=6

Manually

Smoothing with a simple moving average with the SMA function
DailyDelhiClimateTestSMA6<- SMA(train.DailyDelhiClimateTest.ts, n=6)
DailyDelhiClimateTestSMA6
## Time Series:
## Start = 1 
## End = 94 
## Frequency = 1 
##  [1]         NA         NA         NA         NA         NA  4.3635679
##  [7]  5.5799327  5.4225253  5.8435570  6.6462422  7.7249459  7.3823622
## [13]  6.7813001  7.3356334  6.8502297  7.0200445  6.7311556  6.6316307
## [19]  7.2820976  8.2738169  9.9513531  9.1993531  8.9850285  8.5453848
## [25]  8.2817022  7.8219591  7.9324060  8.5695575  9.1598081  9.3149610
## [31]  8.6264610  8.0651515  6.1766414  4.8705808  4.7915067  5.4211364
## [37]  6.1577104  6.5806271  6.7560816  7.7594907  7.6339352  6.9422685
## [43]  5.7056944  5.4957407  5.9761574  5.5898479  5.8183201  6.7066534
## [49]  7.4774868  7.4236147  7.4194481  8.5502020  8.0460354  8.8910354
## [55] 10.6264520 11.6054563 12.3012897 11.0943452 10.5107804  9.1883445
## [61]  7.3995945  6.6469160  6.1864993  6.9969160  7.9561752  7.8911111
## [67]  8.6133838  8.7684434  9.2871934  8.5545545  8.2163600  8.7214526
## [73]  7.7645503  7.5699074  6.5861574  7.5733796  7.4876425  7.5052350
## [79]  8.4311610  8.7790776  9.5503276  8.2165776  8.7016204  8.9122685
## [85] 10.1643056 10.8955556 10.6717130 12.2904630 12.3825265 11.8033598
## [91] 10.3779431  9.6466931  9.3288690  9.5155357
Visualization of Train set with Smoothing set
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate dan The smoothing data", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="red")
lines(DailyDelhiClimateTestSMA6)

Forecasting Simple Moving Average, N=6
DailyDelhiClimateTest.fc6<-c(NA,DailyDelhiClimateTestSMA6)
DailyDelhiClimateTest.fc6
##  [1]         NA         NA         NA         NA         NA         NA
##  [7]  4.3635679  5.5799327  5.4225253  5.8435570  6.6462422  7.7249459
## [13]  7.3823622  6.7813001  7.3356334  6.8502297  7.0200445  6.7311556
## [19]  6.6316307  7.2820976  8.2738169  9.9513531  9.1993531  8.9850285
## [25]  8.5453848  8.2817022  7.8219591  7.9324060  8.5695575  9.1598081
## [31]  9.3149610  8.6264610  8.0651515  6.1766414  4.8705808  4.7915067
## [37]  5.4211364  6.1577104  6.5806271  6.7560816  7.7594907  7.6339352
## [43]  6.9422685  5.7056944  5.4957407  5.9761574  5.5898479  5.8183201
## [49]  6.7066534  7.4774868  7.4236147  7.4194481  8.5502020  8.0460354
## [55]  8.8910354 10.6264520 11.6054563 12.3012897 11.0943452 10.5107804
## [61]  9.1883445  7.3995945  6.6469160  6.1864993  6.9969160  7.9561752
## [67]  7.8911111  8.6133838  8.7684434  9.2871934  8.5545545  8.2163600
## [73]  8.7214526  7.7645503  7.5699074  6.5861574  7.5733796  7.4876425
## [79]  7.5052350  8.4311610  8.7790776  9.5503276  8.2165776  8.7016204
## [85]  8.9122685 10.1643056 10.8955556 10.6717130 12.2904630 12.3825265
## [91] 11.8033598 10.3779431  9.6466931  9.3288690  9.5155357
Visualization of Train set with Forecasting set
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate dan The forecasting data", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="blue")
lines(DailyDelhiClimateTest.fc6)

All time series plots in one
par(col="black")
ts.plot(train.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate", lty=1)
points(train.DailyDelhiClimateTest.ts)
par(col="red")
lines(DailyDelhiClimateTestSMA6)
par(col="blue")
lines(DailyDelhiClimateTest.fc6)
legend("topleft",c("Actual data","Smoothing Data N=5","Forecasting data"), lty=8, col=c("black","red","blue"), cex=0.8)

data6 <-
cbind(Actual=c(train.DailyDelhiClimateTest.ts, rep(NA,20)),
      Smoothing=c(DailyDelhiClimateTestSMA6, rep(NA,20)),
      Forecasting=c(DailyDelhiClimateTest.fc6, rep(DailyDelhiClimateTest.fc6[length(DailyDelhiClimateTest.fc6)],19)))
data6.ts<-ts(data6, start=c(1))
data6.ts
## Time Series:
## Start = 1 
## End = 114 
## Frequency = 1 
##         Actual  Smoothing Forecasting
##   1  2.7434783         NA          NA
##   2  2.8944444         NA          NA
##   3  4.0166667         NA          NA
##   4  4.5450000         NA          NA
##   5  3.3000000         NA          NA
##   6  8.6818182  4.3635679          NA
##   7 10.0416667  5.5799327   4.3635679
##   8  1.9500000  5.4225253   5.5799327
##   9  6.5428571  5.8435570   5.4225253
##  10  9.3611111  6.6462422   5.8435570
##  11  9.7722222  7.7249459   6.6462422
##  12  6.6263158  7.3823622   7.7249459
##  13  6.4352941  6.7813001   7.3823622
##  14  5.2760000  7.3356334   6.7813001
##  15  3.6304348  6.8502297   7.3356334
##  16 10.3800000  7.0200445   6.8502297
##  17  8.0388889  6.7311556   7.0200445
##  18  6.0291667  6.6316307   6.7311556
##  19 10.3380952  7.2820976   6.6316307
##  20 11.2263158  8.2738169   7.2820976
##  21 13.6956522  9.9513531   8.2738169
##  22  5.8680000  9.1993531   9.9513531
##  23  6.7529412  8.9850285   9.1993531
##  24  3.3913043  8.5453848   8.9850285
##  25  8.7560000  8.2817022   8.5453848
##  26  8.4678571  7.8219591   8.2817022
##  27 14.3583333  7.9324060   7.8219591
##  28  9.6909091  8.5695575   7.9324060
##  29 10.2944444  9.1598081   8.5695575
##  30  4.3222222  9.3149610   9.1598081
##  31  4.6250000  8.6264610   9.3149610
##  32  5.1000000  8.0651515   8.6264610
##  33  3.0272727  6.1766414   8.0651515
##  34  1.8545455  4.8705808   6.1766414
##  35  9.8200000  4.7915067   4.8705808
##  36  8.1000000  5.4211364   4.7915067
##  37  9.0444444  6.1577104   5.4211364
##  38  7.6375000  6.5806271   6.1577104
##  39  4.0800000  6.7560816   6.5806271
##  40  7.8750000  7.7594907   6.7560816
##  41  9.0666667  7.6339352   7.7594907
##  42  3.9500000  6.9422685   7.6339352
##  43  1.6250000  5.7056944   6.9422685
##  44  6.3777778  5.4957407   5.7056944
##  45  6.9625000  5.9761574   5.4957407
##  46  5.5571429  5.5898479   5.9761574
##  47 10.4375000  5.8183201   5.5898479
##  48  9.2800000  6.7066534   5.8183201
##  49  6.2500000  7.4774868   6.7066534
##  50  6.0545455  7.4236147   7.4774868
##  51  6.9375000  7.4194481   7.4236147
##  52 12.3416667  8.5502020   7.4194481
##  53  7.4125000  8.0460354   8.5502020
##  54 14.3500000  8.8910354   8.0460354
##  55 16.6625000 10.6264520   8.8910354
##  56 11.9285714 11.6054563  10.6264520
##  57 11.1125000 12.3012897  11.6054563
##  58  5.1000000 11.0943452  12.3012897
##  59  3.9111111 10.5107804  11.0943452
##  60  6.4153846  9.1883445  10.5107804
##  61  5.9300000  7.3995945   9.1883445
##  62  7.4125000  6.6469160   7.3995945
##  63  8.3500000  6.1864993   6.6469160
##  64  9.9625000  6.9969160   6.1864993
##  65  9.6666667  7.9561752   6.9969160
##  66  6.0250000  7.8911111   7.9561752
##  67 10.2636364  8.6133838   7.8911111
##  68  8.3428571  8.7684434   8.6133838
##  69 11.4625000  9.2871934   8.7684434
##  70  5.5666667  8.5545545   9.2871934
##  71  7.6375000  8.2163600   8.5545545
##  72  9.0555556  8.7214526   8.2163600
##  73  4.5222222  7.7645503   8.7214526
##  74  7.1750000  7.5699074   7.7645503
##  75  5.5600000  6.5861574   7.5699074
##  76 11.4900000  7.5733796   6.5861574
##  77  7.1230769  7.4876425   7.5733796
##  78  9.1611111  7.5052350   7.4876425
##  79 10.0777778  8.4311610   7.5052350
##  80  9.2625000  8.7790776   8.4311610
##  81 10.1875000  9.5503276   8.7790776
##  82  3.4875000  8.2165776   9.5503276
##  83 10.0333333  8.7016204   8.2165776
##  84 10.4250000  8.9122685   8.7016204
##  85 17.5900000 10.1643056   8.9122685
##  86 13.6500000 10.8955556  10.1643056
##  87  8.8444444 10.6717130  10.8955556
##  88 13.2000000 12.2904630  10.6717130
##  89 10.5857143 12.3825265  12.2904630
##  90  6.9500000 11.8033598  12.3825265
##  91  9.0375000 10.3779431  11.8033598
##  92  9.2625000  9.6466931  10.3779431
##  93  6.9375000  9.3288690   9.6466931
##  94 14.3200000  9.5155357   9.3288690
##  95         NA         NA   9.5155357
##  96         NA         NA   9.5155357
##  97         NA         NA   9.5155357
##  98         NA         NA   9.5155357
##  99         NA         NA   9.5155357
## 100         NA         NA   9.5155357
## 101         NA         NA   9.5155357
## 102         NA         NA   9.5155357
## 103         NA         NA   9.5155357
## 104         NA         NA   9.5155357
## 105         NA         NA   9.5155357
## 106         NA         NA   9.5155357
## 107         NA         NA   9.5155357
## 108         NA         NA   9.5155357
## 109         NA         NA   9.5155357
## 110         NA         NA   9.5155357
## 111         NA         NA   9.5155357
## 112         NA         NA   9.5155357
## 113         NA         NA   9.5155357
## 114         NA         NA   9.5155357
Forecast Accuracy Measure Manually
error6=train.DailyDelhiClimateTest.ts - DailyDelhiClimateTest.fc6 [1:length(train.DailyDelhiClimateTest.ts)]
error6
## Time Series:
## Start = 1 
## End = 94 
## Frequency = 1 
##  [1]           NA           NA           NA           NA           NA
##  [6]           NA  5.678098741 -3.629932660  1.120331890  3.517554113
## [11]  3.125980038 -1.098630098 -0.947068038 -1.505300064 -3.705198615
## [16]  3.529770329  1.018844404 -0.701988930  3.706464495  3.944218193
## [21]  5.421835280 -4.083353126 -2.446411950 -5.593724160  0.210615212
## [26]  0.186154895  6.536374193  1.758503091  1.724886929 -4.837585838
## [31] -4.689961039 -3.526461039 -5.037878788 -4.322095960  4.949419192
## [36]  3.308493266  3.623308081  1.479789562 -2.500627104  1.118918350
## [41]  1.307175926 -3.683935185 -5.317268519  0.672083333  1.466759259
## [46] -0.419014550  4.847652116  3.461679894 -0.456653439 -1.422941318
## [51] -0.486114719  4.922218615 -1.137702020  6.303964646  7.771464646
## [56]  1.302119408 -0.492956349 -7.201289683 -7.183234127 -4.095395808
## [61] -3.258344526  0.012905474  1.703084046  3.776000712  2.669750712
## [66] -1.931175214  2.372525253 -0.270526696  2.694056638 -3.720526696
## [71] -0.917054473  0.839195527 -4.199230399 -0.589550265 -2.009907407
## [76]  4.903842593 -0.450302707  1.673468661  2.572542735  0.831339031
## [81]  1.408422365 -6.062827635  1.816755698  1.723379630  8.677731481
## [86]  3.485694444 -2.051111111  2.528287037 -1.704748677 -5.432526455
## [91] -2.765859788 -1.115443122 -2.709193122  4.991130952
ME6=mean(error6[7:length(train.DailyDelhiClimateTest.ts)])
ME6
## [1] 0.19299704
MAD6=mean(abs(error6[7:length(train.DailyDelhiClimateTest.ts)]))
MAD6
## [1] 2.9137028
MSE6=mean(error6[7:length(train.DailyDelhiClimateTest.ts)]^2)
MSE6
## [1] 12.439515
MSE6.sqrt=sqrt(MSE6)
MSE6.sqrt1=1.25*MAD6
r.error6=((data6[,1]-data6[,3])/data6[,1])*100
MPE6=mean(r.error6[7:length(train.DailyDelhiClimateTest.ts)])
MPE6
## [1] -19.287701
MAPE6=mean(abs((error6[7:length(train.DailyDelhiClimateTest.ts)]/train.DailyDelhiClimateTest.ts[7:length(train.DailyDelhiClimateTest.ts)])*100))
MAPE6
## [1] 47.385693
AccuracyMeasur6 <- c(ME6, MAD6, MSE6, MPE6, MAPE6)
mod6 <- c("ME6", "MAD6","MSE6","MPE6", "MAPE6")
kompmodel6 <- cbind(mod6, AccuracyMeasur6)

Automatically

Smoothing by using the sma function available in the smooth packages.
DailyDelhiClimateTestAutoSMA6 <- sma(train.DailyDelhiClimateTest.ts, order=6, ic=c("AIC","BIC"),h=3, holdout=FALSE)
summary(DailyDelhiClimateTestAutoSMA6)
## Time elapsed: 0.01 seconds
## Model estimated: SMA(6)
## Initial values were produced using backcasting.
## 
## Loss function type: MSE; Loss function value: 11.968
## Error standard deviation: 3.4969
## Sample size: 94
## Number of estimated parameters: 2
## Number of degrees of freedom: 92
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 504.0905 504.2223 509.1770 509.4766
forecast(DailyDelhiClimateTestAutoSMA6)
## Time Series:
## Start = 95 
## End = 104 
## Frequency = 1 
##     Point forecast Lower bound (2.5%) Upper bound (97.5%)
##  95      9.5155357          2.5704370           16.460634
##  96      9.3371726          2.2962750           16.378070
##  97      9.7350347          2.5658007           16.904269
##  98      9.8512905          2.5109810           17.191600
##  99      9.9494223          2.3824724           17.516372
## 100     10.4514093          2.5864641           18.316354
## 101      9.8066442          1.5533653           18.059923
## 102      9.8551623          1.4160381           18.294286
## 103      9.9414939          1.2994088           18.583579
## 104      9.9759037          1.1171689           18.834639
plot(forecast(DailyDelhiClimateTestAutoSMA6))

All of N=6 Forecast Accuracy Measure

AccuracyMeasurAuto6 <- c(504.0905, 504.2223, 509.1770, 509.4766)
modAuto6 <- c("AIC", "AICc","BIC","BICc")
kompmodelAuto6 <- cbind(modAuto6, AccuracyMeasurAuto6)
colnames(kompmodel6) <- c("Accuracy Measure N=6", "Value")
kompmodelAll6 <- as.data.frame(rbind(kompmodel6, kompmodelAuto6))
kompmodelAll6
##   Accuracy Measure N=6             Value
## 1                  ME6 0.192997041751982
## 2                 MAD6  2.91370275573897
## 3                 MSE6  12.4395152514096
## 4                 MPE6 -19.2877011957409
## 5                MAPE6  47.3856933590145
## 6                  AIC          504.0905
## 7                 AICc          504.2223
## 8                  BIC           509.177
## 9                 BICc          509.4766

Best smoothing range

Based on the smoothing results with a simple moving average, the best range will be sought based on the accuracy of the forecast with the slightest error.

AccuracyMeasur <- cbind(kompmodelAll2$Value, kompmodelAll3$Value, kompmodelAll4$Value, kompmodelAll5$Value, kompmodelAll6$Value)
mod <- c("ME", "MAD", "MSE", "MPE", "MAPE", "AIC", "AICc","BIC","BICc")
kompmodelALL <- cbind(mod, AccuracyMeasur)
colnames(kompmodelALL) <- c("Accuracy Measure", "N=2", "N=3", "N=4", "N=5", "N=6")
kompmodelAll <- as.data.frame(cbind(kompmodelALL))
kompmodelAll$`N=2` <- as.numeric(kompmodelAll$`N=2`)
kompmodelAll$`N=3` <- as.numeric(kompmodelAll$`N=3`)
kompmodelAll$`N=4` <- as.numeric(kompmodelAll$`N=4`)
kompmodelAll$`N=5` <- as.numeric(kompmodelAll$`N=5`)
kompmodelAll$`N=6` <- as.numeric(kompmodelAll$`N=6`)
kompmodelAll
##   Accuracy Measure           N=2          N=3          N=4          N=5
## 1               ME   0.084737862   0.10949638   0.13613938   0.16134234
## 2              MAD   2.898049497   2.82853413   2.85265775   2.86207382
## 3              MSE  12.256418788  12.34208405  12.48049848  12.50473240
## 4              MPE -17.692994104 -18.24548277 -18.60004078 -19.17682603
## 5             MAPE  46.588327913  45.62403485  46.01702787  46.59470240
## 6              AIC 502.389300000 502.97030000 504.20580000 504.52490000
## 7             AICc 502.521200000 503.10220000 504.33760000 504.65680000
## 8              BIC 507.475900000 508.05690000 509.29240000 509.61150000
## 9             BICc 507.775500000 508.35650000 509.59190000 509.91110000
##            N=6
## 1   0.19299704
## 2   2.91370276
## 3  12.43951525
## 4 -19.28770120
## 5  47.38569336
## 6 504.09050000
## 7 504.22230000
## 8 509.17700000
## 9 509.47660000
options(digits = 8)
minim <- transform(kompmodelAll, min=pmin(kompmodelAll$`N=2`, kompmodelAll$`N=3`, kompmodelAll$`N=4`, kompmodelAll$`N=5`, kompmodelAll$`N=6`))
minim
##   Accuracy.Measure           N.2          N.3          N.4          N.5
## 1               ME   0.084737862   0.10949638   0.13613938   0.16134234
## 2              MAD   2.898049497   2.82853413   2.85265775   2.86207382
## 3              MSE  12.256418788  12.34208405  12.48049848  12.50473240
## 4              MPE -17.692994104 -18.24548277 -18.60004078 -19.17682603
## 5             MAPE  46.588327913  45.62403485  46.01702787  46.59470240
## 6              AIC 502.389300000 502.97030000 504.20580000 504.52490000
## 7             AICc 502.521200000 503.10220000 504.33760000 504.65680000
## 8              BIC 507.475900000 508.05690000 509.29240000 509.61150000
## 9             BICc 507.775500000 508.35650000 509.59190000 509.91110000
##            N.6           min
## 1   0.19299704   0.084737862
## 2   2.91370276   2.828534125
## 3  12.43951525  12.256418788
## 4 -19.28770120 -19.287701196
## 5  47.38569336  45.624034853
## 6 504.09050000 502.389300000
## 7 504.22230000 502.521200000
## 8 509.17700000 507.475900000
## 9 509.47660000 507.775500000
Accuracy Measure N=2 N=3 N=4 N=5 N=6 Min
ME 0.084737862 0.10949638 0.13613938 0.16134234 0.19299704 0.084737862
MAD 2.898049497 2.82853413 2.85265775 2.86207382 2.91370276 2.828534125
MSE 12.256418788 12.34208405 12.48049848 12.50473240 12.43951525 12.256418788
MPE -17.692994104 -18.24548277 -18.60004078 -19.17682603 -19.28770120 -19.28770120
MAPE 46.588327913 45.62403485 46.01702787 46.59470240 47.38569336 45.62403485
AIC 502.38930000 502.97030000 504.20580000 504.52490000 504.09050000 502.38930000
AICc 502.52120000 503.10220000 504.33760000 504.65680000 504.22230000 502.52120000
BIC 507.47590000 508.05690000 509.29240000 509.61150000 509.17700000 507.47590000
BICc 507.77550000 508.35650000 509.59190000 509.91110000 509.47660000 507.77550000

The table above is a smoothing comparison table using 5 ranges, namely N=2, N=3, N=4, N=5, and N=6. The comparison table shows the accuracy measure value for each range, with the best accuracy measure criteria being the range with a small accuracy measure value.

The table above shows that the range N=2 has a high forecasting accuracy, so the best smoothing is the simple moving average with N=2. The results from this best range will then be used in smoothing the simple moving average on the test data.

Testing best smoothing for testing set

Simple Moving Average, N=2

Manually

Smoothing with a simple moving average with the SMA function
DailyDelhiClimateTestSMATest2<- SMA(test.DailyDelhiClimateTest.ts, n=2)
DailyDelhiClimateTestSMATest2
## Time Series:
## Start = 94 
## End = 114 
## Frequency = 1 
##  [1]         NA 14.3523077 13.9811966  9.1138889  6.4937500 11.2312500
##  [7] 16.7196429 17.4133929 12.5000000  7.2159722  3.1659722  3.6770833
## [13]  4.0333333  3.7333333  6.5888889  8.4180556  7.2937500  6.2625000
## [19]  7.9262500  9.4262500 11.0598214
Visualization of Test set with Smoothing set
par(col="black")
ts.plot(test.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate dan The smoothing data", lty=1)
points(test.DailyDelhiClimateTest.ts)
par(col="red")
lines(DailyDelhiClimateTestSMATest2)

Forecasting Simple Moving Average, N=2
DailyDelhiClimateTest.fcTest2<-c(NA, DailyDelhiClimateTestSMATest2)
DailyDelhiClimateTest.fcTest2<-ts(DailyDelhiClimateTest.fcTest2, start=94)
DailyDelhiClimateTest.fcTest2
## Time Series:
## Start = 94 
## End = 115 
## Frequency = 1 
##  [1]         NA         NA 14.3523077 13.9811966  9.1138889  6.4937500
##  [7] 11.2312500 16.7196429 17.4133929 12.5000000  7.2159722  3.1659722
## [13]  3.6770833  4.0333333  3.7333333  6.5888889  8.4180556  7.2937500
## [19]  6.2625000  7.9262500  9.4262500 11.0598214

DailyDelhiClimateTest.fcTest2 results from forecasting on test data using the best range obtained from smoothing moving average using test data.

Visualization of Test set with Forecasting set
par(col="black")
ts.plot(test.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate dan The forecasting data", lty=1)
points(test.DailyDelhiClimateTest.ts)
par(col="blue")
lines(DailyDelhiClimateTest.fcTest2)

All time series plots in one
par(col="black")
ts.plot(test.DailyDelhiClimateTest.ts, xlab="Day", ylab="Daily Delhi Climate", lty=1)
points(test.DailyDelhiClimateTest.ts)
par(col="red")
lines(DailyDelhiClimateTestSMATest2)
par(col="blue")
lines(DailyDelhiClimateTest.fcTest2)
legend("topleft",c("Actual data","Smoothing Test Data N=2","Forecasting data"), lty=8, col=c("black","red","blue"), cex=0.8)

The plot above visualization compares the actual value (test data), smoothing value, and forecast value based on the best range of train data.

dataTest2<-
cbind(Actual=c(test.DailyDelhiClimateTest.ts, rep(NA, 1)),
      Smoothing=c(DailyDelhiClimateTestSMATest2, rep(NA,1)),
      Forecasting=c(DailyDelhiClimateTest.fcTest2, rep(DailyDelhiClimateTest.fcTest2[length(DailyDelhiClimateTest.fc2)],0)))
dataTest2.ts<-ts(dataTest2, start=94)
dataTest2.ts
## Time Series:
## Start = 94 
## End = 115 
## Frequency = 1 
##         Actual  Smoothing Forecasting
##  94 14.3200000         NA          NA
##  95 14.3846154 14.3523077          NA
##  96 13.5777778 13.9811966  14.3523077
##  97  4.6500000  9.1138889  13.9811966
##  98  8.3375000  6.4937500   9.1138889
##  99 14.1250000 11.2312500   6.4937500
## 100 19.3142857 16.7196429  11.2312500
## 101 15.5125000 17.4133929  16.7196429
## 102  9.4875000 12.5000000  17.4133929
## 103  4.9444444  7.2159722  12.5000000
## 104  1.3875000  3.1659722   7.2159722
## 105  5.9666667  3.6770833   3.1659722
## 106  2.1000000  4.0333333   3.6770833
## 107  5.3666667  3.7333333   4.0333333
## 108  7.8111111  6.5888889   3.7333333
## 109  9.0250000  8.4180556   6.5888889
## 110  5.5625000  7.2937500   8.4180556
## 111  6.9625000  6.2625000   7.2937500
## 112  8.8900000  7.9262500   6.2625000
## 113  9.9625000  9.4262500   7.9262500
## 114 12.1571429 11.0598214   9.4262500
## 115         NA         NA  11.0598214
Forecast Accuracy Measure Manually
errorTest2=test.DailyDelhiClimateTest.ts - DailyDelhiClimateTest.fcTest2 [1:length(test.DailyDelhiClimateTest.ts)]
errorTest2
## Time Series:
## Start = 94 
## End = 114 
## Frequency = 1 
##  [1]          NA          NA -0.77452991 -9.33119658 -0.77638889  7.63125000
##  [7]  8.08303571 -1.20714286 -7.92589286 -7.55555556 -5.82847222  2.80069444
## [13] -1.57708333  1.33333333  4.07777778  2.43611111 -2.85555556 -0.33125000
## [19]  2.62750000  2.03625000  2.73089286
ME2=mean(error2[7:length(test.DailyDelhiClimateTest.ts)])
ME2
## [1] 0.59846613
MAD2=mean(abs(error2[7:length(test.DailyDelhiClimateTest.ts)]))
MAD2
## [1] 3.1019812
MSE2=mean(error2[7:length(test.DailyDelhiClimateTest.ts)]^2)
MSE2
## [1] 12.958052
MSE2.sqrt=sqrt(MSE2)
MSE2.sqrt1=1.25*MAD2
r.errorTest2=((dataTest2[,1]-dataTest2[,3])/dataTest2[,1])*100
MPE2=mean(r.errorTest2[7:length(test.DailyDelhiClimateTest.ts)])
MPE2
## [1] -35.34028
MAPE2=mean(abs((errorTest2[7:length(test.DailyDelhiClimateTest.ts)]/test.DailyDelhiClimateTest.ts[7:length(test.DailyDelhiClimateTest.ts)])*100))
MAPE2
## [1] 70.712232
AccuracyMeasur2 <- c(ME2, MAD2, MSE2, MPE2, MAPE2)
mod2 <- c("ME", "MAD","MSE","MPE", "MAPE")
kompmodelTest2 <- cbind(mod2, AccuracyMeasur2)

Automatically

Smoothing by using the sma function available in the smooth packages.
DailyDelhiClimateTestSMATest2 <- sma(test.DailyDelhiClimateTest.ts, order=2, ic=c("AIC","BIC"),h=3, holdout=FALSE)
summary(DailyDelhiClimateTestSMATest2)
## Time elapsed: 0 seconds
## Model estimated: SMA(2)
## Initial values were produced using backcasting.
## 
## Loss function type: MSE; Loss function value: 20.4108
## Error standard deviation: 4.7497
## Sample size: 21
## Number of estimated parameters: 2
## Number of degrees of freedom: 19
## Information criteria:
##      AIC     AICc      BIC     BICc 
## 126.9327 127.5994 129.0218 130.0366
forecast(DailyDelhiClimateTestSMATest2)
## Time Series:
## Start = 115 
## End = 124 
## Frequency = 1 
##     Point forecast Lower bound (2.5%) Upper bound (97.5%)
## 115      11.059821         1.11867061           21.000972
## 116      11.608482         0.49393764           22.723027
## 117      11.334152        -2.04953210           24.717836
## 118      11.471317        -3.28426123           26.226895
## 119      11.402734        -4.85881663           27.664285
## 120      11.437026        -6.08436281           28.958414
## 121      11.419880        -7.33141087           30.171171
## 122      11.428453        -8.45096648           31.307872
## 123      11.424166        -9.53498273           32.383316
## 124      11.426310       -10.55375107           33.406370
plot(forecast(DailyDelhiClimateTestSMATest2))

##   Accuracy Measure N=2             Value
## 1                   ME 0.598466125788777
## 2                  MAD  3.10198121874735
## 3                  MSE  12.9580518418772
## 4                  MPE -35.3402804931411
## 5                 MAPE  70.7122316484674
## 6                  AIC          126.9327
## 7                 AICc          127.5994
## 8                  BIC          129.0218
## 9                 BICc          130.0366

Conclusion

  1. The best smoothing is the simple moving average with range N=2 because it has a high forecasting accuracy than other ranges.

  2. The best range results are used to refine the test data and for the accuracy measure seen from the ME, MAD, MSE, MPE, MAPE, AIC, AICc, BIC, and BICc value

Referensi

  1. Rácz A, Bajusz D, Héberger K. Effect of Dataset Size and Train/Test Split Ratios in QSAR/QSPR Multiclass Classification. Molecules. 2021; 26(4):1111. https://doi.org/10.3390/molecules26041111