PACKAGES
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(readxl)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.0 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.1 ✔ tibble 3.2.0
## ✔ purrr 1.0.1 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(readxl)
DATA
data <- read_excel("C:/Users/HP/Downloads/DC/FKP12.3_mingguanDC.xlsx")
View(data)
data
## # A tibble: 159 × 3
## tahun minggu total_kedatangan
## <dbl> <dbl> <dbl>
## 1 2019 1 1045
## 2 2019 2 1174
## 3 2019 3 1139
## 4 2019 4 1067
## 5 2019 5 1138
## 6 2019 6 1161
## 7 2019 7 1243
## 8 2019 8 1191
## 9 2019 9 1198
## 10 2019 10 1088
## # … with 149 more rows
Membuat objek time series
ts_data <- ts(data$minggu, frequency=106, start=c(2019, 1),end = c(2022,53))
ts_data
## Time Series:
## Start = c(2019, 1)
## End = c(2022, 53)
## Frequency = 106
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
## [26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
## [51] 51 52 53 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
## [76] 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
## [101] 48 49 50 51 52 53 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
## [126] 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
## [151] 45 46 47 48 49 50 51 52 53 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
## [176] 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
## [201] 42 43 44 45 46 47 48 49 50 51 52 53 1 2 3 4 5 6 7 8 9 10 11 12 13
## [226] 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
## [251] 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 1 2 3 4 5 6 7 8 9 10
## [276] 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
## [301] 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 1 2 3 4 5 6 7
## [326] 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
## [351] 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
Memeriksa plot data
plot(ts_data)

Membangun model SARIMA
sarima_model <- auto.arima(ts_data, seasonal=TRUE, stepwise=TRUE, approximation=FALSE)
sarima_model
## Series: ts_data
## ARIMA(0,0,0)(0,1,0)[106] with drift
##
## Coefficients:
## drift
## 0
##
## sigma^2 = 0.0003852: log likelihood = Inf
## AIC=-Inf AICc=-Inf BIC=-Inf
Melihat hasil prediksi
forecast_data <- forecast(sarima_model, h=12)
plot(forecast_data)
