Metode SSA dikombinasikan dengan bagging berbasis K-Means clustering (bagging-SSA) untuk meningkatkan akurasi peramalan harga saham BCA. Teknik bagging yang digabungkan dengan K-Means clustering bertujuan mengurangi variansi model dan meningkatkan stabilitas prediksi dengan membagi data ke dalam kelompok yang lebih homogen. Sebagai perbandingan, metode ARIMA juga diterapkan untuk mengevaluasi kinerja bagging-SSA.
library(readxl)
library(clusterCrit)
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(data.table)
library(ggplot2)
library(readr)
library(openxlsx)
library(writexl)
library(Rssa)
## Loading required package: svd
##
## Attaching package: 'Rssa'
## The following object is masked from 'package:stats':
##
## decompose
library(readxl)
data <- read_excel("D:/data BCA.xlsx")
View(data)
# Load the data
set.seed(123)
total_data <- nrow(data)
total_data
## [1] 84
training_size <- floor((72/84) * total_data)
training_size
## [1] 72
testing_size <- total_data - training_size
testing_size
## [1] 12
# Data training dan testing
datrain0 <- data[1:training_size, ]
datest <- data[(training_size + 1):total_data, ]
datrain<- data.frame(datrain0)
datrain
## Date Price Open High Low Volume
## 1 2018-01-01 4545 4380 4690 4265 1.69
## 2 2018-02-01 4635 4570 4940 4570 1.47
## 3 2018-03-01 4660 4620 4760 4505 1.85
## 4 2018-04-01 4420 4690 4730 4210 1.35
## 5 2018-05-01 4540 4420 4610 4295 1.73
## 6 2018-06-01 4295 4590 4630 4165 1.3
## 7 2018-07-01 4655 4330 4725 4120 1.44
## 8 2018-08-01 4960 4680 5095 4605 1.71
## 9 2018-09-01 4830 5010 5040 4720 1.45
## 10 2018-10-01 4730 4800 4840 4435 1.44
## 11 2018-11-01 5210 4770 5240 4670 1.94
## 12 2018-12-01 5200 5215 5395 4980 1.7
## 13 2019-01-01 5635 5200 5640 5115 1.86
## 14 2019-02-01 5515 5680 5750 5335 1.49
## 15 2019-03-01 5550 5565 5600 5425 1.17
## 16 2019-04-01 5750 5550 5805 5450 1.15
## 17 2019-05-01 5820 5800 5895 5140 1.7
## 18 2019-06-01 5995 6000 6190 5790 1.18
## 19 2019-07-01 6190 5995 6290 5865 1.05
## 20 2019-08-01 6100 6190 6270 5765 1.53
## 21 2019-09-01 6070 6100 6105 5780 1.26
## 22 2019-10-01 6290 6010 6325 5950 1.25
## 23 2019-11-01 6280 6300 6380 6210 1.3
## 24 2019-12-01 6685 6280 6800 6270 1.28
## 25 2020-01-01 6480 6695 7060 6480 1.55
## 26 2020-02-01 6290 6480 6820 6035 2.12
## 27 2020-03-01 5525 6290 6540 4325 2.37
## 28 2020-04-01 5170 5560 6100 4800 2.55
## 29 2020-05-01 5190 5150 5400 4680 2.38
## 30 2020-06-01 5695 5260 5995 5240 2.22
## 31 2020-07-01 6240 5700 6265 5675 1.5
## 32 2020-08-01 6275 6220 6600 5825 1.1
## 33 2020-09-01 5420 6280 6560 5390 2.82
## 34 2020-10-01 5790 5485 5900 5440 1.46
## 35 2020-11-01 6205 5760 6650 5720 2.53
## 36 2020-12-01 6770 6220 7000 6220 2.01
## 37 2021-01-01 6760 6800 7380 6705 1.83
## 38 2021-02-01 6710 6760 7055 6595 1.41
## 39 2021-03-01 6215 6830 7160 6145 2.37
## 40 2021-04-01 6405 6215 6460 5980 1.97
## 41 2021-05-01 6375 6480 6500 6260 1.68
## 42 2021-06-01 6025 6500 6620 6000 1.58
## 43 2021-07-01 5970 6060 6190 5960 1.22
## 44 2021-08-01 6550 6060 6760 5905 1.77
## 45 2021-09-01 7000 6550 7000 6410 1.47
## 46 2021-10-01 7475 6900 8250 6710 2.02
## 47 2021-11-01 7275 7550 7750 7175 1.54
## 48 2021-12-01 7300 7275 7525 7275 1.28
## 49 2022-01-01 7625 7325 7950 7300 1.47
## 50 2022-02-01 8050 7775 8175 7650 1.31
## 51 2022-03-01 7975 8000 8300 7650 2.25
## 52 2022-04-01 8125 8075 8250 7625 1.71
## 53 2022-05-01 7750 7875 7900 7250 2.61
## 54 2022-06-01 7250 7625 7675 7250 1.99
## 55 2022-07-01 7350 7300 7475 7000 1.42
## 56 2022-08-01 8200 7350 8275 7350 2.04
## 57 2022-09-01 8550 8150 8875 8125 2.37
## 58 2022-10-01 8800 8450 8900 8125 1.68
## 59 2022-11-01 9300 9000 9400 8550 1.92
## 60 2022-12-01 8550 9275 9350 8350 1.92
## 61 2023-01-01 8475 8575 8850 8000 1.85
## 62 2023-02-01 8750 8575 8950 8400 1.28
## 63 2023-03-01 8750 8725 8900 8250 1.84
## 64 2023-04-01 9050 8825 9200 8650 1.06
## 65 2023-05-01 9050 9100 9325 8700 1.88
## 66 2023-06-01 9150 9150 9325 8950 1.03
## 67 2023-07-01 9125 9025 9400 9025 1.32
## 68 2023-08-01 9175 9175 9450 9100 1.45
## 69 2023-09-01 8825 9200 9275 8825 1.28
## 70 2023-10-01 8750 8900 9250 8700 1.55
## 71 2023-11-01 8975 8750 9075 8600 1.44
## 72 2023-12-01 9400 8925 9450 8675 1.73
# Check for missing values and display a message
if (sum(is.na(datrain)) > 0) {
cat("Data contains missing values. Missing values will be removed.\n")
data_saham <- na.omit(data_saham)
cat("Missing values have been removed.\n")
} else {
cat("No missing values found in the data.\n")
}
## No missing values found in the data.
# Mengonversi 7 kolom ke dalam time series, misalnya dengan frekuensi bulanan (12)
ts_price <- ts(datrain[2])
ts_price
## Time Series:
## Start = 1
## End = 72
## Frequency = 1
## Price
## [1,] 4545
## [2,] 4635
## [3,] 4660
## [4,] 4420
## [5,] 4540
## [6,] 4295
## [7,] 4655
## [8,] 4960
## [9,] 4830
## [10,] 4730
## [11,] 5210
## [12,] 5200
## [13,] 5635
## [14,] 5515
## [15,] 5550
## [16,] 5750
## [17,] 5820
## [18,] 5995
## [19,] 6190
## [20,] 6100
## [21,] 6070
## [22,] 6290
## [23,] 6280
## [24,] 6685
## [25,] 6480
## [26,] 6290
## [27,] 5525
## [28,] 5170
## [29,] 5190
## [30,] 5695
## [31,] 6240
## [32,] 6275
## [33,] 5420
## [34,] 5790
## [35,] 6205
## [36,] 6770
## [37,] 6760
## [38,] 6710
## [39,] 6215
## [40,] 6405
## [41,] 6375
## [42,] 6025
## [43,] 5970
## [44,] 6550
## [45,] 7000
## [46,] 7475
## [47,] 7275
## [48,] 7300
## [49,] 7625
## [50,] 8050
## [51,] 7975
## [52,] 8125
## [53,] 7750
## [54,] 7250
## [55,] 7350
## [56,] 8200
## [57,] 8550
## [58,] 8800
## [59,] 9300
## [60,] 8550
## [61,] 8475
## [62,] 8750
## [63,] 8750
## [64,] 9050
## [65,] 9050
## [66,] 9150
## [67,] 9125
## [68,] 9175
## [69,] 8825
## [70,] 8750
## [71,] 8975
## [72,] 9400
KMboot.norm <- function(x, num = 10, k_range = c(12,20)) {
freq <- frequency(x)
x_clust <- data.matrix(x)
if (sd(x) == 0) {
km_res <- rep(1, length(x))
} else {
km_res <- cluster::pam(x_clust, k = k_range[1])$cluster # Using PAM as an alternative
km_res
}}
k <-KMboot.norm(ts_price)
k
## [1] 1 1 1 1 1 1 1 2 1 1 2 2 3 3 3 4 4 5 6 5 5 6 6 7 6
## [26] 6 3 2 2 4 6 6 3 4 6 7 7 7 6 6 6 5 5 7 7 8 8 8 8 9
## [51] 9 9 9 8 8 9 10 11 12 10 10 11 11 12 12 12 12 12 11 11 12 12
KMboot.norm <- function(x, num = 100, k_range = c(12,20)) {
freq <- frequency(x)
x_clust <- data.matrix(x)
if (sd(x) == 0) {
km_res <- rep(1, length(x))
} else {
km_res <- cluster::pam(x_clust, k_range[1])$cluster
}
clus_means <- sapply(sort(unique(km_res)), function(i) mean(x[km_res == i]))
}
clusmeans <- KMboot.norm(ts_price)
clusmeans
## [1] 4590.000 5146.000 5529.000 5763.750 6032.000 6295.000 6745.833 7379.167
## [9] 8020.000 8525.000 8775.000 9153.125
KMboot.norm <- function(x, num = 100, k_range = c(12, 20)) {
freq <- frequency(x)
x_clust <- data.matrix(x)
# Periksa apakah standar deviasi adalah nol
if (sd(x) == 0) {
km_res <- rep(1, length(x))
} else {
# Gunakan jumlah cluster yang diinginkan
km_res <- cluster::pam(x_clust, 12)$cluster
}
# Hitung rata-rata dan standar deviasi untuk tiap cluster
clus_means <- sapply(sort(unique(km_res)), function(i) mean(x[km_res == i]))
clus_sd <- sapply(sort(unique(km_res)), function(i) sd(x[km_res == i]))
# Kembalikan hasil
list(cluster_means = clus_means, cluster_sd = clus_sd, clusters = km_res)
}
# Panggil fungsi dengan data
result <- KMboot.norm(ts_price)
result$cluster_sd
## [1] 161.55494 105.02381 77.08761 54.06401 53.22124 90.52624 147.45903
## [8] 144.40972 172.66297 43.30127 35.35534 139.79417
KMboot.norm <- function(x, num = 10, k_range = c(12,20)) {
freq <- frequency(x)
x_clust <- data.matrix(x)
if (sd(x) == 0) {
km_res <- rep(1, length(x))
} else {
km_res <- cluster::pam(x_clust, k = k_range[1])$cluster # Using PAM as an alternative
}
clus_means <- sapply(sort(unique(km_res)), function(i) mean(x[km_res == i]))
clus_means
clus_sd <- sapply(sort(unique(km_res)), function(i) sd(x[km_res == i]))
xs <- list()
xs[[1]] <- ts(x, freq = freq)
for (j in 2:num) {
xs[[j]] <- vector(length = length(x))
for (i in 1:length(x)) {
xs[[j]][i] <- rnorm(1, mean = clus_means[km_res[i]], sd = clus_sd[km_res[i]])
}
xs[[j]] <- ts(xs[[j]], freq = freq)
}
return(xs)
}
datbag<-KMboot.norm(ts_price)
datbag
## [[1]]
## Time Series:
## Start = 1
## End = 72
## Frequency = 1
## Price
## [1,] 4545
## [2,] 4635
## [3,] 4660
## [4,] 4420
## [5,] 4540
## [6,] 4295
## [7,] 4655
## [8,] 4960
## [9,] 4830
## [10,] 4730
## [11,] 5210
## [12,] 5200
## [13,] 5635
## [14,] 5515
## [15,] 5550
## [16,] 5750
## [17,] 5820
## [18,] 5995
## [19,] 6190
## [20,] 6100
## [21,] 6070
## [22,] 6290
## [23,] 6280
## [24,] 6685
## [25,] 6480
## [26,] 6290
## [27,] 5525
## [28,] 5170
## [29,] 5190
## [30,] 5695
## [31,] 6240
## [32,] 6275
## [33,] 5420
## [34,] 5790
## [35,] 6205
## [36,] 6770
## [37,] 6760
## [38,] 6710
## [39,] 6215
## [40,] 6405
## [41,] 6375
## [42,] 6025
## [43,] 5970
## [44,] 6550
## [45,] 7000
## [46,] 7475
## [47,] 7275
## [48,] 7300
## [49,] 7625
## [50,] 8050
## [51,] 7975
## [52,] 8125
## [53,] 7750
## [54,] 7250
## [55,] 7350
## [56,] 8200
## [57,] 8550
## [58,] 8800
## [59,] 9300
## [60,] 8550
## [61,] 8475
## [62,] 8750
## [63,] 8750
## [64,] 9050
## [65,] 9050
## [66,] 9150
## [67,] 9125
## [68,] 9175
## [69,] 8825
## [70,] 8750
## [71,] 8975
## [72,] 9400
##
## [[2]]
## Time Series:
## Start = 1
## End = 72
## Frequency = 1
## [1] 4499.452 4552.814 4841.817 4601.391 4610.887 4867.077 4664.463 5013.138
## [9] 4479.036 4518.001 5274.558 5183.789 5559.895 5537.532 5486.152 5860.358
## [17] 5790.666 5927.334 6358.491 6006.837 5975.169 6275.268 6202.120 6638.352
## [25] 6238.418 6142.310 5593.583 5162.108 5026.469 5831.536 6333.606 6268.288
## [33] 5598.003 5811.225 6369.375 6847.380 6827.513 6736.704 6267.302 6260.557
## [41] 6232.111 6020.934 5964.654 7065.665 6923.958 7216.979 7320.986 7311.777
## [49] 7491.801 8005.605 8063.739 8015.071 8012.598 7576.806 7346.563 8281.838
## [57] 8457.937 8795.669 9170.439 8534.351 8541.439 8757.240 8763.219 9010.734
## [65] 9003.295 9195.557 9215.782 9160.535 8807.607 8847.481 9084.482 8830.317
##
## [[3]]
## Time Series:
## Start = 1
## End = 72
## Frequency = 1
## [1] 4752.482 4475.425 4478.849 4755.686 4543.994 4392.787 4619.290 5131.413
## [9] 4590.931 4652.244 5107.072 5213.675 5512.003 5554.576 5613.553 5787.278
## [17] 5746.129 6093.141 6384.938 6061.186 6044.706 6238.158 6418.175 6657.320
## [25] 6493.011 6433.741 5510.830 5038.201 5071.390 5777.638 6272.668 6263.538
## [33] 5455.642 5761.316 6223.946 6499.880 6689.765 6881.348 6242.916 6350.037
## [41] 6148.539 6029.043 6059.643 6790.241 6761.416 7286.642 7256.461 7231.273
## [49] 7396.156 7856.406 7935.299 7975.782 8338.367 7285.019 7413.159 8033.461
## [57] 8483.350 8772.479 9355.065 8544.551 8526.785 8760.062 8702.407 9311.279
## [65] 8948.936 9256.565 9420.007 8951.277 8799.812 8765.730 8933.348 8941.383
##
## [[4]]
## Time Series:
## Start = 1
## End = 72
## Frequency = 1
## [1] 4331.264 4504.229 4353.846 4701.136 4929.283 4382.074 4717.263 5226.768
## [9] 4643.669 4427.092 5133.455 5116.552 5572.400 5500.290 5604.313 5743.499
## [17] 5820.664 5976.162 6180.923 6204.492 6009.814 6321.997 6352.626 6674.496
## [25] 6341.790 6328.401 5512.397 5152.857 5142.422 5878.823 6227.890 6195.784
## [33] 5531.913 5780.536 6334.517 6678.243 6589.036 6932.101 6263.347 6216.648
## [41] 6273.610 6021.506 6091.071 6758.329 6857.025 7307.064 7410.135 7332.279
## [49] 7392.825 7865.404 7793.673 8364.845 8123.720 7198.471 7290.908 7815.311
## [57] 8620.211 8821.401 9116.059 8548.521 8507.059 8758.162 8747.119 9070.001
## [65] 9383.912 9145.572 9169.795 9187.191 8818.575 8756.754 9014.378 9387.378
##
## [[5]]
## Time Series:
## Start = 1
## End = 72
## Frequency = 1
## [1] 4518.728 4473.185 4390.274 4382.448 4497.272 4689.839 4769.301 5220.314
## [9] 4531.249 4599.653 5072.001 5070.675 5597.196 5450.710 5679.729 5758.867
## [17] 5775.349 5992.695 6243.003 5961.907 6022.264 6332.929 6324.358 6630.589
## [25] 6223.609 6249.538 5644.328 5026.556 5127.195 5866.599 6285.859 6171.899
## [33] 5477.755 5789.996 6260.998 6662.980 6695.120 6759.178 6439.707 6286.983
## [41] 6392.841 6065.570 6025.952 6519.793 6668.990 7308.425 7385.976 7566.928
## [49] 7710.310 8287.210 7997.010 7716.713 7952.872 7392.049 7501.195 8186.193
## [57] 8554.631 8725.670 9271.900 8505.664 8532.569 8777.636 8790.138 9156.574
## [65] 8920.022 9256.083 9207.089 9115.988 8779.177 8779.739 9184.022 9382.506
##
## [[6]]
## Time Series:
## Start = 1
## End = 72
## Frequency = 1
## [1] 4554.611 4617.152 4778.758 4760.308 4775.023 4496.707 4913.511 5153.005
## [9] 4891.599 4371.755 5148.204 5277.271 5473.864 5470.977 5456.650 5706.847
## [17] 5740.115 6049.626 6112.661 6043.282 6097.817 6479.454 6412.791 6857.427
## [25] 6138.686 6240.548 5501.862 5219.887 5134.902 5695.702 6447.486 6377.505
## [33] 5547.303 5829.606 6173.806 6843.277 6668.725 6846.658 6289.494 6352.300
## [41] 6415.899 6032.388 6086.156 6570.588 6639.426 7598.556 7433.665 7082.806
## [49] 7182.186 7985.333 8169.488 8002.409 8127.774 7517.656 7620.483 8029.672
## [57] 8522.749 8713.014 9167.010 8500.238 8482.824 8768.639 8810.884 8874.550
## [65] 9093.394 9169.430 9028.260 9199.803 8789.546 8773.832 8808.407 9512.600
##
## [[7]]
## Time Series:
## Start = 1
## End = 72
## Frequency = 1
## [1] 4556.833 4695.203 4634.228 4755.541 4722.097 4556.107 4651.095 5046.710
## [9] 4728.440 4515.517 5399.819 4972.601 5493.232 5592.627 5568.325 5731.880
## [17] 5709.860 6039.689 6293.705 5936.719 6033.839 6312.221 6310.817 6590.262
## [25] 6338.103 6419.797 5564.170 5026.736 5100.247 5782.462 6236.425 6099.676
## [33] 5597.165 5718.905 6243.078 6967.597 6631.679 6870.544 6180.875 6262.905
## [41] 6288.341 5969.803 5998.218 6741.580 6844.734 7140.812 7328.659 7488.399
## [49] 7301.357 8059.245 8104.990 8066.245 8132.793 7361.446 7319.428 7563.626
## [57] 8520.976 8790.213 9227.971 8500.956 8602.055 8785.127 8779.466 9330.980
## [65] 9052.688 9090.170 9488.275 9154.681 8832.755 8724.141 9126.492 9206.026
##
## [[8]]
## Time Series:
## Start = 1
## End = 72
## Frequency = 1
## [1] 4638.473 4427.534 4593.111 4415.937 4705.141 4765.251 4230.542 5275.777
## [9] 4389.503 4663.470 5215.305 5125.007 5479.270 5541.744 5562.827 5811.505
## [17] 5652.792 5944.910 6424.489 6087.703 6055.167 6359.742 6378.028 6353.456
## [25] 6395.509 6251.096 5546.778 5115.001 5237.577 5744.910 6341.938 6259.633
## [33] 5444.760 5829.168 6362.071 7000.091 6755.441 6911.725 6473.827 6269.518
## [41] 6175.238 6019.261 6020.608 6768.200 6998.328 7332.068 7433.032 7346.287
## [49] 7382.120 8074.226 8249.333 8040.947 8143.081 7491.642 7511.269 7920.823
## [57] 8595.446 8761.531 9138.337 8585.797 8581.035 8736.463 8744.132 8963.273
## [65] 9178.546 9176.169 9204.026 9230.313 8753.720 8739.867 9296.664 9258.119
##
## [[9]]
## Time Series:
## Start = 1
## End = 72
## Frequency = 1
## [1] 4346.187 4574.628 4445.255 4255.460 4614.253 4577.203 4574.270 5168.701
## [9] 4732.567 4623.215 5081.260 5068.829 5518.840 5552.898 5448.854 5753.786
## [17] 5816.044 6026.237 6231.775 6017.314 6091.323 6344.793 6406.952 6766.345
## [25] 6332.141 6244.445 5575.667 5092.823 4996.807 5770.670 6471.151 6367.504
## [33] 5618.827 5783.151 6239.910 6716.011 6705.540 6676.719 6358.746 6186.607
## [41] 6373.429 6077.991 5968.208 6840.132 7104.192 7298.699 7501.179 7266.209
## [49] 7539.564 8063.135 8305.225 7768.090 8011.143 7303.074 7350.680 7911.295
## [57] 8488.894 8795.461 9001.088 8589.260 8473.636 8778.574 8793.844 9235.147
## [65] 9110.943 9164.239 9287.504 8949.520 8747.361 8786.328 9090.947 9344.644
##
## [[10]]
## Time Series:
## Start = 1
## End = 72
## Frequency = 1
## [1] 4698.767 4601.659 4346.414 4594.217 4538.881 4573.465 4399.113 5198.371
## [9] 4422.151 4553.453 5186.059 5063.712 5573.941 5427.513 5312.401 5788.888
## [17] 5809.193 6016.787 6340.637 5970.481 6025.233 6119.242 6401.928 7020.094
## [25] 6392.226 6292.524 5526.431 4986.777 5229.009 5752.357 6235.548 6167.175
## [33] 5505.892 5717.846 6259.058 6566.287 6994.684 6743.474 6392.311 6059.478
## [41] 6253.974 5996.050 5966.914 6973.895 6537.137 7425.145 7501.400 7404.899
## [49] 7252.771 8182.504 8049.454 7836.373 7780.335 7680.509 7281.184 7699.611
## [57] 8548.091 8785.968 8963.867 8440.868 8519.964 8815.284 8797.490 9084.215
## [65] 9036.510 9191.019 9175.122 9241.155 8761.006 8806.797 9036.982 9106.917
frame_datbag <- as.data.frame(datbag)
frame_datbag
## Price structure.c.4499.45238818793..4552.8136885272..4841.81703473831..
## 1 4545 4499.452
## 2 4635 4552.814
## 3 4660 4841.817
## 4 4420 4601.391
## 5 4540 4610.887
## 6 4295 4867.077
## 7 4655 4664.463
## 8 4960 5013.138
## 9 4830 4479.036
## 10 4730 4518.001
## 11 5210 5274.558
## 12 5200 5183.789
## 13 5635 5559.895
## 14 5515 5537.532
## 15 5550 5486.152
## 16 5750 5860.358
## 17 5820 5790.666
## 18 5995 5927.334
## 19 6190 6358.491
## 20 6100 6006.837
## 21 6070 5975.169
## 22 6290 6275.268
## 23 6280 6202.120
## 24 6685 6638.352
## 25 6480 6238.418
## 26 6290 6142.310
## 27 5525 5593.583
## 28 5170 5162.108
## 29 5190 5026.469
## 30 5695 5831.536
## 31 6240 6333.606
## 32 6275 6268.288
## 33 5420 5598.003
## 34 5790 5811.225
## 35 6205 6369.375
## 36 6770 6847.380
## 37 6760 6827.513
## 38 6710 6736.704
## 39 6215 6267.302
## 40 6405 6260.557
## 41 6375 6232.111
## 42 6025 6020.934
## 43 5970 5964.654
## 44 6550 7065.665
## 45 7000 6923.958
## 46 7475 7216.979
## 47 7275 7320.986
## 48 7300 7311.777
## 49 7625 7491.801
## 50 8050 8005.605
## 51 7975 8063.739
## 52 8125 8015.071
## 53 7750 8012.598
## 54 7250 7576.806
## 55 7350 7346.563
## 56 8200 8281.838
## 57 8550 8457.937
## 58 8800 8795.669
## 59 9300 9170.439
## 60 8550 8534.351
## 61 8475 8541.439
## 62 8750 8757.240
## 63 8750 8763.219
## 64 9050 9010.734
## 65 9050 9003.295
## 66 9150 9195.557
## 67 9125 9215.782
## 68 9175 9160.535
## 69 8825 8807.607
## 70 8750 8847.481
## 71 8975 9084.482
## 72 9400 8830.317
## structure.c.4752.48203121341..4475.42511036445..4478.84880634784..
## 1 4752.482
## 2 4475.425
## 3 4478.849
## 4 4755.686
## 5 4543.994
## 6 4392.787
## 7 4619.290
## 8 5131.413
## 9 4590.931
## 10 4652.244
## 11 5107.072
## 12 5213.675
## 13 5512.003
## 14 5554.576
## 15 5613.553
## 16 5787.278
## 17 5746.129
## 18 6093.141
## 19 6384.938
## 20 6061.186
## 21 6044.706
## 22 6238.158
## 23 6418.175
## 24 6657.320
## 25 6493.011
## 26 6433.741
## 27 5510.830
## 28 5038.201
## 29 5071.390
## 30 5777.638
## 31 6272.668
## 32 6263.538
## 33 5455.642
## 34 5761.316
## 35 6223.946
## 36 6499.880
## 37 6689.765
## 38 6881.348
## 39 6242.916
## 40 6350.037
## 41 6148.539
## 42 6029.043
## 43 6059.643
## 44 6790.241
## 45 6761.416
## 46 7286.642
## 47 7256.461
## 48 7231.273
## 49 7396.156
## 50 7856.406
## 51 7935.299
## 52 7975.782
## 53 8338.367
## 54 7285.019
## 55 7413.159
## 56 8033.461
## 57 8483.350
## 58 8772.479
## 59 9355.065
## 60 8544.551
## 61 8526.785
## 62 8760.062
## 63 8702.407
## 64 9311.279
## 65 8948.936
## 66 9256.565
## 67 9420.007
## 68 8951.277
## 69 8799.812
## 70 8765.730
## 71 8933.348
## 72 8941.383
## structure.c.4331.2639128214..4504.22942642791..4353.84615801143..
## 1 4331.264
## 2 4504.229
## 3 4353.846
## 4 4701.136
## 5 4929.283
## 6 4382.074
## 7 4717.263
## 8 5226.768
## 9 4643.669
## 10 4427.092
## 11 5133.455
## 12 5116.552
## 13 5572.400
## 14 5500.290
## 15 5604.313
## 16 5743.499
## 17 5820.664
## 18 5976.162
## 19 6180.923
## 20 6204.492
## 21 6009.814
## 22 6321.997
## 23 6352.626
## 24 6674.496
## 25 6341.790
## 26 6328.401
## 27 5512.397
## 28 5152.857
## 29 5142.422
## 30 5878.823
## 31 6227.890
## 32 6195.784
## 33 5531.913
## 34 5780.536
## 35 6334.517
## 36 6678.243
## 37 6589.036
## 38 6932.101
## 39 6263.347
## 40 6216.648
## 41 6273.610
## 42 6021.506
## 43 6091.071
## 44 6758.329
## 45 6857.025
## 46 7307.064
## 47 7410.135
## 48 7332.279
## 49 7392.825
## 50 7865.404
## 51 7793.673
## 52 8364.845
## 53 8123.720
## 54 7198.471
## 55 7290.908
## 56 7815.311
## 57 8620.211
## 58 8821.401
## 59 9116.059
## 60 8548.521
## 61 8507.059
## 62 8758.162
## 63 8747.119
## 64 9070.001
## 65 9383.912
## 66 9145.572
## 67 9169.795
## 68 9187.191
## 69 8818.575
## 70 8756.754
## 71 9014.378
## 72 9387.378
## structure.c.4518.72790110358..4473.1851175633..4390.2739652455..
## 1 4518.728
## 2 4473.185
## 3 4390.274
## 4 4382.448
## 5 4497.272
## 6 4689.839
## 7 4769.301
## 8 5220.314
## 9 4531.249
## 10 4599.653
## 11 5072.001
## 12 5070.675
## 13 5597.196
## 14 5450.710
## 15 5679.729
## 16 5758.867
## 17 5775.349
## 18 5992.695
## 19 6243.003
## 20 5961.907
## 21 6022.264
## 22 6332.929
## 23 6324.358
## 24 6630.589
## 25 6223.609
## 26 6249.538
## 27 5644.328
## 28 5026.556
## 29 5127.195
## 30 5866.599
## 31 6285.859
## 32 6171.899
## 33 5477.755
## 34 5789.996
## 35 6260.998
## 36 6662.980
## 37 6695.120
## 38 6759.178
## 39 6439.707
## 40 6286.983
## 41 6392.841
## 42 6065.570
## 43 6025.952
## 44 6519.793
## 45 6668.990
## 46 7308.425
## 47 7385.976
## 48 7566.928
## 49 7710.310
## 50 8287.210
## 51 7997.010
## 52 7716.713
## 53 7952.872
## 54 7392.049
## 55 7501.195
## 56 8186.193
## 57 8554.631
## 58 8725.670
## 59 9271.900
## 60 8505.664
## 61 8532.569
## 62 8777.636
## 63 8790.138
## 64 9156.574
## 65 8920.022
## 66 9256.083
## 67 9207.089
## 68 9115.988
## 69 8779.177
## 70 8779.739
## 71 9184.022
## 72 9382.506
## structure.c.4554.61132825134..4617.1517937178..4778.75819143426..
## 1 4554.611
## 2 4617.152
## 3 4778.758
## 4 4760.308
## 5 4775.023
## 6 4496.707
## 7 4913.511
## 8 5153.005
## 9 4891.599
## 10 4371.755
## 11 5148.204
## 12 5277.271
## 13 5473.864
## 14 5470.977
## 15 5456.650
## 16 5706.847
## 17 5740.115
## 18 6049.626
## 19 6112.661
## 20 6043.282
## 21 6097.817
## 22 6479.454
## 23 6412.791
## 24 6857.427
## 25 6138.686
## 26 6240.548
## 27 5501.862
## 28 5219.887
## 29 5134.902
## 30 5695.702
## 31 6447.486
## 32 6377.505
## 33 5547.303
## 34 5829.606
## 35 6173.806
## 36 6843.277
## 37 6668.725
## 38 6846.658
## 39 6289.494
## 40 6352.300
## 41 6415.899
## 42 6032.388
## 43 6086.156
## 44 6570.588
## 45 6639.426
## 46 7598.556
## 47 7433.665
## 48 7082.806
## 49 7182.186
## 50 7985.333
## 51 8169.488
## 52 8002.409
## 53 8127.774
## 54 7517.656
## 55 7620.483
## 56 8029.672
## 57 8522.749
## 58 8713.014
## 59 9167.010
## 60 8500.238
## 61 8482.824
## 62 8768.639
## 63 8810.884
## 64 8874.550
## 65 9093.394
## 66 9169.430
## 67 9028.260
## 68 9199.803
## 69 8789.546
## 70 8773.832
## 71 8808.407
## 72 9512.600
## structure.c.4556.83288991254..4695.20349427945..4634.22833018708..
## 1 4556.833
## 2 4695.203
## 3 4634.228
## 4 4755.541
## 5 4722.097
## 6 4556.107
## 7 4651.095
## 8 5046.710
## 9 4728.440
## 10 4515.517
## 11 5399.819
## 12 4972.601
## 13 5493.232
## 14 5592.627
## 15 5568.325
## 16 5731.880
## 17 5709.860
## 18 6039.689
## 19 6293.705
## 20 5936.719
## 21 6033.839
## 22 6312.221
## 23 6310.817
## 24 6590.262
## 25 6338.103
## 26 6419.797
## 27 5564.170
## 28 5026.736
## 29 5100.247
## 30 5782.462
## 31 6236.425
## 32 6099.676
## 33 5597.165
## 34 5718.905
## 35 6243.078
## 36 6967.597
## 37 6631.679
## 38 6870.544
## 39 6180.875
## 40 6262.905
## 41 6288.341
## 42 5969.803
## 43 5998.218
## 44 6741.580
## 45 6844.734
## 46 7140.812
## 47 7328.659
## 48 7488.399
## 49 7301.357
## 50 8059.245
## 51 8104.990
## 52 8066.245
## 53 8132.793
## 54 7361.446
## 55 7319.428
## 56 7563.626
## 57 8520.976
## 58 8790.213
## 59 9227.971
## 60 8500.956
## 61 8602.055
## 62 8785.127
## 63 8779.466
## 64 9330.980
## 65 9052.688
## 66 9090.170
## 67 9488.275
## 68 9154.681
## 69 8832.755
## 70 8724.141
## 71 9126.492
## 72 9206.026
## structure.c.4638.47271043278..4427.53449019512..4593.1114310377..
## 1 4638.473
## 2 4427.534
## 3 4593.111
## 4 4415.937
## 5 4705.141
## 6 4765.251
## 7 4230.542
## 8 5275.777
## 9 4389.503
## 10 4663.470
## 11 5215.305
## 12 5125.007
## 13 5479.270
## 14 5541.744
## 15 5562.827
## 16 5811.505
## 17 5652.792
## 18 5944.910
## 19 6424.489
## 20 6087.703
## 21 6055.167
## 22 6359.742
## 23 6378.028
## 24 6353.456
## 25 6395.509
## 26 6251.096
## 27 5546.778
## 28 5115.001
## 29 5237.577
## 30 5744.910
## 31 6341.938
## 32 6259.633
## 33 5444.760
## 34 5829.168
## 35 6362.071
## 36 7000.091
## 37 6755.441
## 38 6911.725
## 39 6473.827
## 40 6269.518
## 41 6175.238
## 42 6019.261
## 43 6020.608
## 44 6768.200
## 45 6998.328
## 46 7332.068
## 47 7433.032
## 48 7346.287
## 49 7382.120
## 50 8074.226
## 51 8249.333
## 52 8040.947
## 53 8143.081
## 54 7491.642
## 55 7511.269
## 56 7920.823
## 57 8595.446
## 58 8761.531
## 59 9138.337
## 60 8585.797
## 61 8581.035
## 62 8736.463
## 63 8744.132
## 64 8963.273
## 65 9178.546
## 66 9176.169
## 67 9204.026
## 68 9230.313
## 69 8753.720
## 70 8739.867
## 71 9296.664
## 72 9258.119
## structure.c.4346.18668425217..4574.62845888594..4445.25519947589..
## 1 4346.187
## 2 4574.628
## 3 4445.255
## 4 4255.460
## 5 4614.253
## 6 4577.203
## 7 4574.270
## 8 5168.701
## 9 4732.567
## 10 4623.215
## 11 5081.260
## 12 5068.829
## 13 5518.840
## 14 5552.898
## 15 5448.854
## 16 5753.786
## 17 5816.044
## 18 6026.237
## 19 6231.775
## 20 6017.314
## 21 6091.323
## 22 6344.793
## 23 6406.952
## 24 6766.345
## 25 6332.141
## 26 6244.445
## 27 5575.667
## 28 5092.823
## 29 4996.807
## 30 5770.670
## 31 6471.151
## 32 6367.504
## 33 5618.827
## 34 5783.151
## 35 6239.910
## 36 6716.011
## 37 6705.540
## 38 6676.719
## 39 6358.746
## 40 6186.607
## 41 6373.429
## 42 6077.991
## 43 5968.208
## 44 6840.132
## 45 7104.192
## 46 7298.699
## 47 7501.179
## 48 7266.209
## 49 7539.564
## 50 8063.135
## 51 8305.225
## 52 7768.090
## 53 8011.143
## 54 7303.074
## 55 7350.680
## 56 7911.295
## 57 8488.894
## 58 8795.461
## 59 9001.088
## 60 8589.260
## 61 8473.636
## 62 8778.574
## 63 8793.844
## 64 9235.147
## 65 9110.943
## 66 9164.239
## 67 9287.504
## 68 8949.520
## 69 8747.361
## 70 8786.328
## 71 9090.947
## 72 9344.644
## structure.c.4698.76749033617..4601.65889566047..4346.41435067706..
## 1 4698.767
## 2 4601.659
## 3 4346.414
## 4 4594.217
## 5 4538.881
## 6 4573.465
## 7 4399.113
## 8 5198.371
## 9 4422.151
## 10 4553.453
## 11 5186.059
## 12 5063.712
## 13 5573.941
## 14 5427.513
## 15 5312.401
## 16 5788.888
## 17 5809.193
## 18 6016.787
## 19 6340.637
## 20 5970.481
## 21 6025.233
## 22 6119.242
## 23 6401.928
## 24 7020.094
## 25 6392.226
## 26 6292.524
## 27 5526.431
## 28 4986.777
## 29 5229.009
## 30 5752.357
## 31 6235.548
## 32 6167.175
## 33 5505.892
## 34 5717.846
## 35 6259.058
## 36 6566.287
## 37 6994.684
## 38 6743.474
## 39 6392.311
## 40 6059.478
## 41 6253.974
## 42 5996.050
## 43 5966.914
## 44 6973.895
## 45 6537.137
## 46 7425.145
## 47 7501.400
## 48 7404.899
## 49 7252.771
## 50 8182.504
## 51 8049.454
## 52 7836.373
## 53 7780.335
## 54 7680.509
## 55 7281.184
## 56 7699.611
## 57 8548.091
## 58 8785.968
## 59 8963.867
## 60 8440.868
## 61 8519.964
## 62 8815.284
## 63 8797.490
## 64 9084.215
## 65 9036.510
## 66 9191.019
## 67 9175.122
## 68 9241.155
## 69 8761.006
## 70 8806.797
## 71 9036.982
## 72 9106.917
write.xlsx(frame_datbag, "D:/Dataoutputbagging.xlsx")
# Convert the bagging list into a data frame with 10 columns
library(readxl)
daging <- read_excel("D:/DataBagging.xlsx",
col_names = FALSE)
## New names:
## • `` -> `...1`
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
## • `` -> `...6`
## • `` -> `...7`
## • `` -> `...8`
## • `` -> `...9`
## • `` -> `...10`
View(daging)
frame_daging <- as.data.frame(do.call(cbind, daging))
frame_daging
## ...1 ...2 ...3 ...4 ...5 ...6 ...7 ...8
## 1 4642.477 4664.929 4588.894 4712.993 4461.950 4456.467 4415.734 4381.697
## 2 4449.354 4667.080 4811.823 4772.419 4635.609 4595.578 4607.317 4484.251
## 3 4581.645 4510.611 4487.360 4542.324 4470.338 4733.473 4848.244 4580.739
## 4 4736.764 4376.847 4680.164 4676.633 4505.452 4276.593 4345.192 4793.034
## 5 4468.878 4799.282 4645.116 4545.429 4875.850 4755.303 4660.063 4846.461
## 6 4538.043 4360.557 4399.443 4700.231 4697.964 4590.882 4735.326 4641.614
## 7 4404.572 4438.317 4308.729 4571.051 4243.481 4682.051 4430.136 4651.648
## 8 5183.215 5212.056 4936.731 5109.801 5159.276 4972.369 5140.455 5120.411
## 9 4658.629 4386.086 4679.061 4608.033 4517.007 4482.299 4723.058 4597.763
## 10 4694.744 4500.843 4584.387 4544.214 4406.372 4517.586 4548.721 4363.089
## 11 5017.891 5021.778 5340.354 5083.929 5168.033 5255.633 5122.823 5176.450
## 12 5157.262 5211.184 5206.250 5112.819 5159.649 5253.983 5178.319 5089.754
## 13 5456.225 5563.405 5594.501 5528.372 5503.676 5562.540 5524.374 5554.800
## 14 5528.970 5561.522 5631.864 5544.995 5681.071 5652.665 5486.166 5502.329
## 15 5632.500 5563.109 5490.401 5647.131 5355.654 5489.268 5518.314 5477.998
## 16 5736.527 5793.877 5791.328 5690.331 5809.067 5818.492 5865.544 5751.904
## 17 5802.497 5798.316 5810.720 5752.958 5748.124 5761.807 5810.984 5743.914
## 18 5992.102 5927.225 6104.879 6065.610 6066.940 5996.483 5983.324 6090.255
## 19 6251.681 6281.528 6364.040 6454.509 6253.901 6378.590 6182.302 6313.939
## 20 6055.349 6037.985 6054.414 6054.673 6000.394 6105.504 6012.841 6055.018
## 21 5995.857 6070.568 5985.792 6031.268 5940.971 6078.742 6102.719 5965.960
## 22 6140.837 6187.501 6361.044 6267.158 6276.039 6248.886 6321.495 6430.502
## 23 6409.531 6249.773 6340.287 6332.506 6519.392 6252.472 6231.495 6309.427
## 24 6798.971 6587.515 6839.359 6891.679 6891.774 6948.984 6875.927 6619.567
## 25 6242.165 6390.708 6333.351 6278.356 6446.683 6326.940 6282.926 6322.977
## 26 6114.484 6410.790 6276.728 6309.825 6377.828 6370.098 6193.549 6373.797
## 27 5675.637 5589.720 5523.075 5545.723 5617.208 5502.890 5564.552 5422.336
## 28 5502.070 5017.619 5218.190 5222.592 5240.824 5278.439 5306.071 5323.501
## 29 5167.790 5193.466 5164.025 5262.721 5195.928 5061.061 5191.630 5129.403
## 30 5809.694 5825.948 5718.871 5778.843 5732.256 5797.559 5774.130 5824.365
## 31 6405.855 6310.203 6268.733 6288.105 6246.755 6221.024 6235.593 6301.542
## 32 6231.468 6243.752 6175.585 6421.254 6150.082 6072.072 6346.455 6264.907
## 33 5501.927 5445.274 5454.454 5541.684 5528.552 5425.475 5446.472 5387.550
## 34 5670.375 5727.781 5755.932 5849.055 5812.373 5771.119 5674.374 5704.270
## 35 6228.320 6359.713 6132.222 6289.394 6388.416 6374.928 6291.075 6291.258
## 36 6837.613 6682.181 6496.842 6836.362 6759.862 6487.588 6740.732 6867.908
## 37 6702.965 6779.397 6908.417 6517.849 6665.081 6561.299 7094.582 6468.363
## 38 6714.246 6936.785 6660.806 6729.260 7231.050 7006.032 6566.472 6948.655
## 39 6284.810 6347.354 6127.373 6293.027 6361.689 6255.721 6310.472 6421.645
## 40 6126.289 6418.539 6284.783 6226.350 6423.599 6340.779 6367.878 6191.500
## 41 6370.827 6140.962 6414.591 6201.225 6264.431 6247.299 6390.106 6337.756
## 42 5955.176 6017.062 6067.246 6082.462 6029.980 6016.109 6031.429 5976.988
## 43 6020.900 6035.463 6055.491 6080.653 6055.875 6036.643 5992.443 6025.337
## 44 6681.163 6831.152 6920.387 6554.324 6993.052 6747.450 6736.133 6882.773
## 45 6713.600 6573.423 6632.068 6808.412 6699.904 6717.439 7031.868 6873.878
## 46 7590.000 7495.588 7484.541 7218.504 7502.437 7311.323 7448.879 7256.538
## 47 7295.112 7423.557 7294.386 7227.381 7076.655 6939.026 7083.924 7323.333
## 48 7266.080 7417.263 7379.277 7455.041 7305.914 7649.019 7584.728 7238.199
## 49 7159.714 7452.597 7698.957 7280.098 7192.588 7637.721 7457.221 7428.200
## 50 7880.886 7999.909 8187.385 8191.537 8212.237 7829.884 8014.203 7750.805
## 51 7818.643 8179.808 8152.606 8026.652 7991.605 7990.974 8016.916 7566.013
## 52 8090.437 8131.925 7828.633 8112.573 7952.597 8257.459 7994.137 8273.782
## 53 7870.991 7994.064 7884.246 7929.589 8256.393 8192.368 8064.298 8412.545
## 54 7423.073 7529.407 7709.015 7212.919 7540.367 7563.520 7306.403 7313.455
## 55 7358.021 7421.415 7221.283 7511.266 7249.484 7224.396 7419.170 7489.077
## 56 7772.477 8135.469 8057.033 8061.106 8093.877 8464.999 7859.189 8018.705
## 57 8490.766 8499.271 8563.649 8514.648 8471.807 8475.920 8533.667 8588.840
## 58 8806.293 8830.877 8811.019 8777.448 8758.184 8801.655 8814.133 8794.592
## 59 9279.370 9152.567 9305.377 9338.479 9379.113 9172.875 9224.309 9181.596
## 60 8611.844 8561.713 8517.936 8494.768 8587.792 8507.519 8569.763 8447.095
## 61 8524.845 8520.665 8489.450 8492.550 8573.022 8508.571 8477.764 8571.893
## 62 8722.115 8765.114 8764.137 8753.093 8754.815 8739.949 8776.937 8762.595
## 63 8747.832 8802.734 8743.106 8718.962 8708.481 8832.370 8796.823 8725.379
## 64 9210.229 8931.605 9240.786 9267.704 8988.769 9165.638 9003.824 9124.915
## 65 9418.753 9219.998 9309.744 9180.017 9286.287 9189.362 9372.017 9135.402
## 66 9168.504 9208.143 9450.497 9182.086 9112.505 9182.430 9008.465 9301.196
## 67 9312.544 8776.334 9204.306 9147.065 8850.805 9100.678 9176.124 8989.930
## 68 9260.498 9204.622 9030.836 9081.808 9127.936 8994.595 9174.350 9075.170
## 69 8733.702 8698.335 8811.221 8745.888 8824.859 8783.971 8779.302 8827.613
## 70 8768.950 8798.328 8806.988 8805.118 8797.750 8700.979 8767.560 8823.036
## 71 9335.593 9089.671 9119.819 8953.753 9038.318 8954.818 9216.024 9315.736
## 72 9275.598 9055.977 8935.346 9214.676 8937.015 9002.651 9008.974 9385.396
## ...9 ...10
## 1 4622.962 4545
## 2 4495.994 4635
## 3 4679.696 4660
## 4 4761.042 4420
## 5 4979.934 4540
## 6 4272.547 4295
## 7 4634.143 4655
## 8 5214.769 4960
## 9 4581.179 4830
## 10 4338.326 4730
## 11 5223.875 5210
## 12 5064.177 5200
## 13 5567.996 5635
## 14 5598.961 5515
## 15 5627.977 5550
## 16 5679.526 5750
## 17 5822.233 5820
## 18 5991.713 5995
## 19 6178.310 6190
## 20 6101.950 6100
## 21 6093.005 6070
## 22 6273.040 6290
## 23 6363.758 6280
## 24 6618.971 6685
## 25 6281.328 6480
## 26 6286.516 6290
## 27 5507.358 5525
## 28 5223.098 5170
## 29 5307.456 5190
## 30 5739.109 5695
## 31 6292.044 6240
## 32 6443.169 6275
## 33 5503.635 5420
## 34 5622.965 5790
## 35 6341.529 6205
## 36 6615.116 6770
## 37 6598.590 6760
## 38 6955.346 6710
## 39 6516.608 6215
## 40 6200.872 6405
## 41 6388.335 6375
## 42 6026.989 6025
## 43 6039.547 5970
## 44 6926.063 6550
## 45 6777.342 7000
## 46 7256.221 7475
## 47 7311.235 7275
## 48 7478.251 7300
## 49 7041.833 7625
## 50 8209.108 8050
## 51 7749.411 7975
## 52 8023.787 8125
## 53 7987.132 7750
## 54 7565.898 7250
## 55 7406.438 7350
## 56 8037.601 8200
## 57 8555.230 8550
## 58 8745.761 8800
## 59 9125.739 9300
## 60 8575.991 8550
## 61 8554.595 8475
## 62 8729.904 8750
## 63 8797.555 8750
## 64 8960.546 9050
## 65 9069.485 9050
## 66 9322.405 9150
## 67 8838.442 9125
## 68 8904.429 9175
## 69 8821.010 8825
## 70 8746.193 8750
## 71 9326.988 8975
## 72 9129.605 9400
##Foecast Bagging ARIMA
# Function to forecast ARIMA for each column in the data frame
forecast_arima_per_column <- function(frame_daging, h = 12) {
forecasts <- lapply(frame_daging, function(column) {
ts_data <- ts(column, frequency = 12)
model <- auto.arima(ts_data)
forecast(model, h = h)$mean
})
forecast_df <- do.call(cbind, forecasts)
return(forecast_df)
}
# Perform forecasting ARIMA for each column
forecast_results <- forecast_arima_per_column(frame_daging)
forecast_results
## ...1 ...2 ...3 ...4 ...5 ...6 ...7 ...8
## Jan 7 9340.853 9046.788 8935.346 9278.080 8907.532 9062.885 9008.974 9370.636
## Feb 7 9406.109 9101.508 8935.346 9341.484 8878.722 9126.644 9008.974 9416.750
## Mar 7 9471.364 9109.929 8935.346 9404.888 8864.349 9190.404 9008.974 9583.556
## Apr 7 9536.619 9138.777 8935.346 9468.292 8968.649 9254.163 9008.974 9493.083
## May 7 9601.874 9203.334 8935.346 9531.696 9027.811 9317.923 9008.974 9568.691
## Jun 7 9667.129 9200.680 8935.346 9595.100 9034.753 9381.682 9008.974 9960.649
## Jul 7 9732.385 9104.020 8935.346 9658.504 8976.390 9445.441 9008.974 9827.055
## Aug 7 9797.640 9199.892 8935.346 9721.908 9008.661 9509.201 9008.974 9847.145
## Sep 7 9862.895 9086.560 8935.346 9785.312 8865.965 9572.960 9008.974 9785.331
## Oct 7 9928.150 9108.943 8935.346 9848.716 8852.677 9636.720 9008.974 9852.829
## Nov 7 9993.406 9174.160 8935.346 9912.120 8843.194 9700.479 9008.974 9794.828
## Dec 7 10058.661 9166.618 8935.346 9975.524 8900.268 9764.239 9008.974 10084.472
## ...9 ...10
## Jan 7 9172.684 9468.380
## Feb 7 9290.550 9536.761
## Mar 7 9355.715 9605.141
## Apr 7 9420.881 9673.521
## May 7 9486.046 9741.901
## Jun 7 9551.212 9810.282
## Jul 7 9616.377 9878.662
## Aug 7 9681.543 9947.042
## Sep 7 9746.708 10015.423
## Oct 7 9811.873 10083.803
## Nov 7 9877.039 10152.183
## Dec 7 9942.204 10220.563
# Create a data frame for the forecast results
forecast_results_df <- data.frame(
forecast_results
)
# Save the forecast results to Excel
write.xlsx(forecast_results_df, "D:/Dataoutput_forecast_per_column.xlsx")
ssaAPB=ssa(daging,36)
plot(ssaAPB)
ssaAPB$sigma
## [1] 771827.258 27526.297 23615.821 17640.554 17538.549 15999.807
## [7] 15822.555 11608.375 10117.494 9579.597 8324.168 7147.907
## [13] 6812.290 6668.550 6647.671 6564.967 5697.656 5243.894
## [19] 4757.166 4443.327 4284.748 4269.138 4136.795 3953.450
## [25] 3797.034 3733.186 3596.281 3248.034 3079.033 3046.144
## [31] 3024.534 2725.953 2566.970 2488.645 2474.299 2401.023
plot(ssaAPB, type= 'paired')
plot(wcor(ssaAPB))
plot(wcor(ssaAPB,groups=list(c(1:9),c(10:36))))
ramalAPB=rforecast(ssaAPB,groups=list(c(1:9)), len=12)
ramalAPB
## [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,] 9928.676 9717.276 9741.175 9721.089 9765.175 9633.507 9797.886
## [2,] 9785.941 9597.105 9651.554 9587.546 9611.817 9532.542 9696.690
## [3,] 9559.754 9455.259 9536.225 9439.829 9435.730 9418.984 9552.853
## [4,] 9487.979 9461.133 9555.261 9459.997 9431.234 9449.748 9542.599
## [5,] 9689.032 9667.401 9767.176 9693.757 9658.739 9671.864 9739.472
## [6,] 10051.463 9967.823 10067.240 10006.953 9997.110 9977.774 10044.509
## [7,] 10318.835 10178.149 10262.027 10193.657 10235.481 10183.584 10257.984
## [8,] 10305.185 10183.107 10231.881 10147.039 10239.188 10176.953 10245.836
## [9,] 10065.489 10040.441 10049.432 9958.875 10067.471 10021.424 10067.687
## [10,] 9865.367 9948.851 9938.887 9856.627 9940.121 9920.732 9945.717
## [11,] 9963.013 10090.628 10092.840 10020.122 10064.552 10056.676 10083.688
## [12,] 10384.694 10475.788 10501.180 10428.211 10460.747 10433.533 10487.090
## [,8] [,9] [,10]
## [1,] 9817.044 9758.841 9810.439
## [2,] 9647.703 9599.438 9662.425
## [3,] 9445.979 9434.238 9492.249
## [4,] 9424.964 9444.745 9493.528
## [5,] 9656.953 9666.880 9711.157
## [6,] 10012.204 9970.372 10008.633
## [7,] 10261.722 10168.209 10189.077
## [8,] 10261.389 10163.835 10158.301
## [9,] 10076.541 10030.884 10005.928
## [10,] 9938.578 9960.809 9936.958
## [11,] 10059.172 10113.055 10107.433
## [12,] 10451.625 10484.244 10495.432
SSA_bag<-data.frame(ramalAPB)
write_xlsx(SSA_bag,"D:/Dataoutput_forecast_bagging_SSA.xlsx")
library(readxl)
SSA_Bagging <- read_excel("D:/Dataoutput_forecast_bagging_SSA.xlsx")
View(SSA_Bagging)
ssaAPF=ssa(SSA_Bagging,6)
ramalAPF=rforecast(ssaAPF,groups=list(c(1:3)), len=12)
ramalAPF
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,] 10793.62 10712.07 10784.99 10712.16 10751.39 10700.55 10777.09 10767.47
## [2,] 10919.18 10761.37 10831.47 10747.32 10828.07 10761.29 10840.77 10854.60
## [3,] 10698.65 10606.45 10636.16 10543.04 10655.34 10598.86 10656.17 10675.16
## [4,] 10396.68 10458.63 10446.04 10354.12 10458.77 10430.39 10460.01 10460.10
## [5,] 10373.74 10538.49 10521.48 10439.71 10503.16 10494.96 10517.47 10490.98
## [6,] 10749.71 10866.39 10889.33 10816.97 10843.08 10827.45 10871.64 10835.43
## [7,] 11263.59 11221.99 11293.28 11220.14 11248.44 11203.63 11279.21 11259.68
## [8,] 11534.32 11364.73 11449.23 11364.82 11434.75 11364.57 11453.36 11462.57
## [9,] 11379.36 11232.91 11281.59 11184.77 11299.50 11231.32 11302.31 11326.10
## [10,] 11006.40 11019.79 11014.88 10915.36 11037.07 10997.36 11035.07 11044.97
## [11,] 10838.69 11005.58 10978.79 10888.60 10971.76 10961.34 10981.06 10960.24
## [12,] 11126.94 11297.66 11302.74 11225.07 11258.61 11250.72 11285.63 11245.06
## [,9] [,10]
## [1,] 10704.22 10725.93
## [2,] 10740.41 10745.65
## [3,] 10591.54 10571.50
## [4,] 10464.33 10433.14
## [5,] 10560.81 10543.75
## [6,] 10885.49 10895.94
## [7,] 11220.46 11246.36
## [8,] 11343.39 11358.13
## [9,] 11211.09 11197.08
## [10,] 11018.15 10983.72
## [11,] 11026.92 10999.79
## [12,] 11323.46 11325.77
SSA_2025<-data.frame(ramalAPF)
write_xlsx(SSA_2025,"D:/Dataoutput_forecast_bagging_SSA_2025.xlsx")