| Kontak | \(\downarrow\) |
| naftaligunawan@gmail.com | |
| https://www.instagram.com/nbrigittag/ | |
| RPubs | https://rpubs.com/naftalibrigitta/ |
| Nama | Naftali Brigitta Gunawan |
| NIM | 20214920002 |
1. Data for Sales Analysis
1.1 Dataset
The dataset below represents the monthly sales data of a company, including various factors that might influence product sales. The data is presented in a tabular format with each row representing a month and each column representing a variable.
library(tibble)
sales_data <- tibble::tibble(
Month = seq.Date(from = as.Date("2019-01-01"), to = as.Date("2024-05-01"), by = "1 month"),
Advertising_Expense = c(50, 75, 60, 65, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200, 205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 260, 265, 270, 275, 280, 285, 290, 295, 300, 305, 310, 315, 320, 325, 330, 335, 340, 345, 350, 355, 360, 365, 370, 375, 380),
Product_Quality = c(20, 25, 22, 23, 28, 30, 32, 35, 38, 40, 42, 45, 48, 50, 55, 60, 65, 68, 70, 72, 75, 78, 80, 82, 85, 88, 90, 92, 95, 98, 100, 102, 105, 108, 110, 112, 115, 118, 120, 122, 125, 128, 130, 132, 135, 138, 140, 142, 145, 148, 150, 152, 155, 158, 160, 162, 165, 168, 170, 172, 175, 178, 180, 182, 185),
Product_Price = c(95, 112, 107,100, 110, 105, 108, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180, 185, 190, 195, 200, 205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 260, 265, 270, 275, 280, 285, 290, 295, 300, 305, 310, 315, 320, 325, 330, 335, 340, 345, 350, 355, 360, 365, 370, 375, 380, 385, 390, 395, 400),
Sales_Promotion = c(15, 20, 18, 19, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142),
Online_Marketing = c(76, 77, 78, 79, 80, 85, 82, 84, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200),
Offline_Marketing = c(84,85, 87, 89, 89, 90, 95, 92, 94, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208),
Product_Sales = c(200, 220, 210, 215, 230, 240, 250, 255, 260, 265, 270, 275, 280, 285, 290, 295, 300, 305, 310, 315, 320, 325, 330, 335, 340, 345, 350, 355, 360, 365, 370, 375, 380, 385, 390, 395, 400, 405, 410, 415, 420, 425, 430, 435, 440, 445, 450, 455, 460, 465, 470, 475, 480, 485, 490, 495, 500, 505, 510, 515, 520, 525, 530, 535, 540)
)
head(sales_data)
This dataset includes the following variables:
Month: The month of observation.Advertising_Expense: The amount spent on advertising (in dollars).Product_Quality: The quality score of the product (on a scale from 1 to 100).Product_Price: The price of the product (in dollars).Sales_Promotion: The expenditure on sales promotion (in dollars).Online_Marketing: The expenditure on online marketing (in dollars).Offline_Marketing: The expenditure on offline marketing (in dollars).Product_Sales: The number of products sold.
1.2 Regression Analysis
# Multiple Linear Regression Model
model <- lm(Product_Sales ~ Advertising_Expense + Product_Quality + Product_Price + Sales_Promotion + Online_Marketing + Offline_Marketing, data = sales_data)
summary(model)
##
## Call:
## lm(formula = Product_Sales ~ Advertising_Expense + Product_Quality +
## Product_Price + Sales_Promotion + Online_Marketing + Offline_Marketing,
## data = sales_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.6031 -0.0697 -0.0051 0.0594 3.3179
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 297.58588 17.69853 16.814 < 2e-16 ***
## Advertising_Expense 0.46830 0.09830 4.764 1.31e-05 ***
## Product_Quality 0.12252 0.04597 2.665 0.009955 **
## Product_Price -0.82782 0.03965 -20.880 < 2e-16 ***
## Sales_Promotion 4.68575 0.51594 9.082 9.71e-13 ***
## Online_Marketing -0.85343 0.17905 -4.767 1.30e-05 ***
## Offline_Marketing -0.58501 0.15959 -3.666 0.000537 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7478 on 58 degrees of freedom
## Multiple R-squared: 0.9999, Adjusted R-squared: 0.9999
## F-statistic: 1.78e+05 on 6 and 58 DF, p-value: < 2.2e-16
Output Summary:
The regression model is
Product_Sales = 297.59 + (0.468 × Advertising_Expense) + (0.123 × Product_Quality) − (0.828 × Product_Price) + (4.686 × Sales_Promotion) − (0.853 × Online_Marketing) − (0.585 × Offline_Marketing)Meaning of:
Intercept (297.59): Represents the baseline sales when all other variables are zero, though practically, this scenario is unrealistic.
Advertising Expense (0.468):
Every unit increase in advertising expense is associated with an increase of 0.468 units in sales.This indicates a significant positive effect of advertising on sales, with a very high statistical significance.Product Quality (0.123): Improvement in product quality correlates with an increase in sales, significant at a 0.01 level.
Product Price (-0.828):
Each unit increase in product price will decrease sales by 0.828 units, showing a strong negative relationship.Sales Promotion (4.686): Every increase in sales promotion efforts is associated with a substantial increase in sales.
Online Marketing (-0.853) and Offline Marketing (-0.585): Both have
a negative impact on sales, suggesting that current strategies may be less effective or possibly oversaturated.p-value: < 2.2e-16, has a meaning the results are highly statistically significant.
1.3 Time Series Analysis
library(plotly)
# Prepare time series data
sales_ts <- ts(sales_data$Product_Sales, frequency = 12)
# Decomposing the time series
decomposed <- stl(sales_ts, s.window = "periodic")
# Adjust scale for seasonal to match trend's visibility
adjusted_seasonal <- decomposed$time.series[, "seasonal"] / max(abs(decomposed$time.series[, "seasonal"])) * max(decomposed$time.series[, "trend"])
# Creating a combined Plotly plot for trend and adjusted seasonal components
combined_plot <- plot_ly() %>%
add_trace(x = time(decomposed$time.series), y = decomposed$time.series[, "trend"], name = 'Trend', type = 'scatter', mode = 'lines', line = list(color = 'blue')) %>%
add_trace(x = time(decomposed$time.series), y = adjusted_seasonal, name = 'Seasonal (adjusted)', type = 'scatter', mode = 'lines', line = list(color = 'orange'))
# Showing the combined plot
combined_plot
Output Summary:
Upward Trend (blue): The graph shows an increasing sales trend over time, indicating consistent growth or increase in sales of that product.
Seasonal Patterns (orange): The seasonally adjusted component highlights fluctuations that occur periodically throughout the year. This indicates that there are seasonal factors affecting sales, such as celebrations, seasons, or consumer spending habits that change with time.
1.4 Comparission Forecasting
library(plotly)
library(forecast)
# Your time series object
sales_ts <- ts(sales_data$Advertising_Expense, start=c(2019,1), frequency=12)
# Forecasting
fit_ets <- ets(sales_ts)
forecast_ets <- forecast(fit_ets, h = 12)
fit_arima <- auto.arima(sales_ts)
forecast_arima <- forecast(fit_arima, h = 12)
# Plotting
ets_plot <- plot_ly() %>%
add_lines(x = time(forecast_ets$mean), y = forecast_ets$mean, name = 'ETS Forecast') %>%
add_ribbons(x = time(forecast_ets$mean), ymin = forecast_ets$lower[,2], ymax = forecast_ets$upper[,2], name = 'ETS Confidence', fillcolor = 'rgba(0,0,255,0.2)')
ets_plot
arima_plot <- plot_ly() %>%
add_lines(x = time(forecast_arima$mean), y = forecast_arima$mean, name = 'ARIMA Forecast') %>%
add_ribbons(x = time(forecast_arima$mean), ymin = forecast_arima$lower[,2], ymax = forecast_arima$upper[,2], name = 'ARIMA Confidence', fillcolor = 'rgba(255,0,0,0.2)')
arima_plot
Output Summary:
The orange line (Confidence) meaning the specific point in time and confidence interval. Upper line meaning the highest prediction, and lower the lowest line prediction in that year.
The blue line (forecast) meaning the specific point in time and confidence interval.
2. Study Case (Data BPS)
Collect dataset from BPS to analyze the relationship between monthly economic indicators, including inflation rate, GDP growth rate, unemployment rate, interest rate, consumer confidence, stock market index, and exchange rate, over a specified period. In this study case you need to apply econometric techniques to analyze the relationships between various economic indicators and gain insights into the dynamics of the economy. By conducting correlation analysis, time series analysis, and regression modeling, you can identify key factors driving economic trends and inform decision-making processes.
2.1 Data Collection
Obtain the extended dataset containing monthly observations of economic indicators from January 2010 to December 2021.
library(readxl)
library(dplyr)
library(tidyr)
library(knitr)
# Inflation Rate Data
nilai_inflasi <- read_excel("Inflation_Rate.xlsx")
kable(head(nilai_inflasi), caption = "Nilai Inflasi")
| Tahun | Bulan | Nilai_Inflasi |
|---|---|---|
| 2010 | 1 | 0.84 |
| 2010 | 2 | 1.14 |
| 2010 | 3 | 0.99 |
| 2010 | 4 | 1.15 |
| 2010 | 5 | 1.44 |
| 2010 | 6 | 2.42 |
# Interest Rate Data
nilai_bunga <- read_excel("Interest_Rate.xlsx")
kable(head(nilai_bunga), caption = "Nilai Suku Bunga")
| Tahun | Bulan | Suku_Bunga |
|---|---|---|
| 2010 | 1 | 6.5 |
| 2010 | 2 | 6.5 |
| 2010 | 3 | 6.5 |
| 2010 | 4 | 6.5 |
| 2010 | 5 | 6.5 |
| 2010 | 6 | 6.5 |
# Consumer Confidence Data
nilai_kepercayaan <- read_excel("Consumer_Confidence.xlsx")
kable(head(nilai_kepercayaan), caption = "Nilai Kepercayaan Konsumen")
| Tahun | Bulan | Konsumen |
|---|---|---|
| 2010 | 1 | 106.7 |
| 2010 | 2 | 101.8 |
| 2010 | 3 | 101.9 |
| 2010 | 4 | 105.6 |
| 2010 | 5 | 106.3 |
| 2010 | 6 | 104.8 |
# Stock Market Index Data
nilai_saham <- read_excel("Stock_Market_Index.xlsx")
kable(head(nilai_saham), caption = "Nilai Saham")
| Tahun | Bulan | Saham |
|---|---|---|
| 2010 | 1 | 2610.80 |
| 2010 | 2 | 2549.03 |
| 2010 | 3 | 2777.30 |
| 2010 | 4 | 2971.25 |
| 2010 | 5 | 2796.96 |
| 2010 | 6 | 2913.68 |
# Exchange Rate Data (nilai_tukar)s
Kurs_USD <- read_excel("Exchange_Rate.xlsx")
# Separate 'Tanggal' into 'Bulan', 'Hari', 'Tahun'
nilai_tukar <- Kurs_USD %>%
separate(Tanggal, into = c("Bulan", "Hari", "Tahun"), remove = TRUE, convert = TRUE) %>%
# Ensure separation was successful
mutate(Tahun = as.numeric(Tahun), Bulan = as.numeric(Bulan)) %>%
# Check for NA values that might have been introduced
drop_na(Tahun, Bulan) %>%
# Group by 'Tahun' and 'Bulan', calculate mean
group_by(Tahun, Bulan) %>%
summarise(BuyUSD = mean(Kurs_Jual, na.rm = TRUE), .groups = 'drop') %>%
# Arrange by 'Tahun' and 'Bulan'
arrange(Tahun, Bulan)
# Display the data frame
kable(head(nilai_tukar), caption = "Nilai Tukar Rupiah")
| Tahun | Bulan | BuyUSD |
|---|---|---|
| 2010 | 1 | 9321.950 |
| 2010 | 2 | 9395.105 |
| 2010 | 3 | 9219.682 |
| 2010 | 4 | 9072.333 |
| 2010 | 5 | 9229.158 |
| 2010 | 6 | 9194.000 |
# GDP Growth Rate Data (nilai_pertumbuhan)
percentage <- c(5.69,6.17,5.8,6.9,
6.48,6.27,6.01,5.94,
6.11,6.21,5.94,5.87,
5.54,5.59,5.52,5.58,
5.12,4.94,4.93,5.05,
4.83,4.74,4.78,5.15,
4.94,5.21,5.03,4.94,
5.01,5.01,5.06,5.19,
5.06,5.27,5.17,5.18,
5.07,5.05,5.02,4.97,
2.97,-5.32,-3.49,-2.19,
-0.69,7.08,3.53,5.03)
sd_gdp <- c(
sd(c(5.69,6.17,5.8,6.9)),
sd(c(6.48,6.27,6.01,5.94)),
sd(c(6.11,6.21,5.94,5.87)),
sd(c(5.54,5.59,5.52,5.58)),
sd(c(5.12,4.94,4.93,5.05)),
sd(c(4.83,4.74,4.78,5.15)),
sd(c(4.94,5.21,5.03,4.94)),
sd(c(5.01,5.01,5.06,5.19)),
sd(c(5.06,5.27,5.17,5.18)),
sd(c(5.07,5.05,5.02,4.97)),
sd(c(2.97,-5.32,-3.49,-2.19)),
sd(c(-0.69,7.08,3.53,5.03)))
set.seed(1993)
GDP_growth <- c(
rnorm(3, mean = percentage[1], sd= sd_gdp[1]),
rnorm(3, mean = percentage[2], sd= sd_gdp[1]),
rnorm(3, mean = percentage[3], sd= sd_gdp[1]),
rnorm(3, mean = percentage[4], sd= sd_gdp[1]),
rnorm(3, mean = percentage[5], sd= sd_gdp[2]),
rnorm(3, mean = percentage[6], sd= sd_gdp[2]),
rnorm(3, mean = percentage[7], sd= sd_gdp[2]),
rnorm(3, mean = percentage[8], sd= sd_gdp[2]),
rnorm(3, mean = percentage[9], sd= sd_gdp[3]),
rnorm(3, mean = percentage[10], sd= sd_gdp[3]),
rnorm(3, mean = percentage[11], sd= sd_gdp[3]),
rnorm(3, mean = percentage[12], sd= sd_gdp[3]),
rnorm(3, mean = percentage[13], sd= sd_gdp[4]),
rnorm(3, mean = percentage[14], sd= sd_gdp[4]),
rnorm(3, mean = percentage[15], sd= sd_gdp[4]),
rnorm(3, mean = percentage[16], sd= sd_gdp[4]),
rnorm(3, mean = percentage[17], sd= sd_gdp[5]),
rnorm(3, mean = percentage[18], sd= sd_gdp[5]),
rnorm(3, mean = percentage[19], sd= sd_gdp[5]),
rnorm(3, mean = percentage[20], sd= sd_gdp[5]),
rnorm(3, mean = percentage[21], sd= sd_gdp[6]),
rnorm(3, mean = percentage[22], sd= sd_gdp[6]),
rnorm(3, mean = percentage[23], sd= sd_gdp[6]),
rnorm(3, mean = percentage[24], sd= sd_gdp[6]),
rnorm(3, mean = percentage[25], sd= sd_gdp[7]),
rnorm(3, mean = percentage[26], sd= sd_gdp[7]),
rnorm(3, mean = percentage[27], sd= sd_gdp[7]),
rnorm(3, mean = percentage[28], sd= sd_gdp[7]),
rnorm(3, mean = percentage[29], sd= sd_gdp[8]),
rnorm(3, mean = percentage[30], sd= sd_gdp[8]),
rnorm(3, mean = percentage[31], sd= sd_gdp[8]),
rnorm(3, mean = percentage[32], sd= sd_gdp[8]),
rnorm(3, mean = percentage[33], sd= sd_gdp[9]),
rnorm(3, mean = percentage[34], sd= sd_gdp[9]),
rnorm(3, mean = percentage[35], sd= sd_gdp[9]),
rnorm(3, mean = percentage[36], sd= sd_gdp[9]),
rnorm(3, mean = percentage[37], sd= sd_gdp[10]),
rnorm(3, mean = percentage[38], sd= sd_gdp[10]),
rnorm(3, mean = percentage[39], sd= sd_gdp[10]),
rnorm(3, mean = percentage[40], sd= sd_gdp[10]),
rnorm(3, mean = percentage[41], sd= sd_gdp[11]),
rnorm(3, mean = percentage[42], sd= sd_gdp[11]),
rnorm(3, mean = percentage[43], sd= sd_gdp[11]),
rnorm(3, mean = percentage[44], sd= sd_gdp[11]),
rnorm(3, mean = percentage[45], sd= sd_gdp[12]),
rnorm(3, mean = percentage[46], sd= sd_gdp[12]),
rnorm(3, mean = percentage[47], sd= sd_gdp[12]),
rnorm(3, mean = percentage[48], sd= sd_gdp[12])
)
# Output dari GDP Growth
gdp_growth_values <- c(
5.4163848, 5.4837772, 5.7137781, 5.8142523, 6.8004721, 6.3402159, 4.7397348, 5.5465389,
5.3877582, 6.9092869, 6.3664372, 5.9077773, 6.3451445, 6.2558354, 6.3413239, 6.2927741,
5.9585015, 5.9648999, 6.0520481, 6.4688165, 6.1538450, 5.9879285, 5.7373696, 6.0746382,
5.9526711, 6.2887034, 6.2737958, 6.1827170, 6.3493182, 6.4098360, 6.3991359, 5.9569445,
5.8826380, 5.8356599, 6.0242495, 5.6983690, 5.5573506, 5.5863537, 5.5587287, 5.5989197,
5.5843377, 5.5708576, 5.5490074, 5.6012861, 5.4939938, 5.5733849, 5.5405670, 5.5673211,
5.1015700, 5.0668485, 5.0229061, 4.8382735, 4.9595595, 4.8994399, 4.9009821, 4.8282473,
4.9423208, 4.9963747, 5.0324045, 5.1890825, 4.8281307, 4.8206504, 5.0514900, 4.8116047,
4.5287398, 4.7509278, 4.8775531, 4.7626807, 4.5942255, 5.3803181, 5.0804715, 5.3977233,
4.9052554, 4.8811743, 4.8566025, 5.0907175, 5.3245923, 5.0908117, 4.9980807, 5.1165003,
4.7332134, 4.8073653, 4.9343169, 4.9559100, 4.9678955, 5.0769971, 5.0431073, 4.8607873,
5.1423404, 4.9244008, 5.0346898, 4.9995460, 5.1247033, 5.0895989, 5.2347949, 5.3068461,
5.0635165, 4.9811067, 5.1994085, 5.2097125, 5.2008862, 5.2301588, 5.5073553, 5.1777419,
5.1936860, 5.0874174, 5.2951971, 5.2195796, 5.0147470, 5.1229402, 5.0522446, 5.0097816,
5.0328231, 5.0382537, 4.9912730, 4.9555817, 5.0384996, 5.0389573, 4.9748922, 4.9436009,
2.3063121, 2.4934051, -2.2483475, -10.0996313, 3.1495871, -3.8124191, -3.6334591, -8.5514860,
-3.1944063, -6.2352736, -4.5321295, -6.4131797, -2.7394728, -2.3517171, 2.4037798, 11.1190972,
8.9815733, 9.0929959, 1.3254293, 7.4149391, 4.0196040, 6.2518839, 7.6232925, 0.7870286)
# Pastikan panjang gdp_growth_values adalah 144
if (length(gdp_growth_values) == 144) {
# Menetapkan jumlah tahun dan bulan (dari tahun 2010-2021 setiap bulan)
tahun <- rep(2010:2021, each = 12)
bulan <- rep(1:12, times = 12)
# Membuat dataframe
gdp_df <- data.frame(
Tahun = tahun,
Bulan = bulan,
GDP_Growth = gdp_growth_values
)
# Melihat sebagian dari dataframe
kable(head(gdp_df), caption = "Nilai PDB")
} else {
print("Jumlah data GDP tidak sesuai dengan jumlah tahun dan bulan yang diinginkan.")
}
| Tahun | Bulan | GDP_Growth |
|---|---|---|
| 2010 | 1 | 5.416385 |
| 2010 | 2 | 5.483777 |
| 2010 | 3 | 5.713778 |
| 2010 | 4 | 5.814252 |
| 2010 | 5 | 6.800472 |
| 2010 | 6 | 6.340216 |
# Unemployment Data
nilai_pengangguran <- read_excel("anggur.xlsx")
# Transform the original data to facilitate merging
nilai_pengangguran_long <- nilai_pengangguran %>%
pivot_longer(
cols = -tahun, # Exclude 'tahun' from the pivoting process
names_to = "bulan",
values_to = "Nilai"
) %>%
mutate(
bulan = case_when(
bulan == "februari" ~ 2, # Convert 'februari' to numeric month
bulan == "agustus" ~ 8 # Convert 'agustus' to numeric month
)
)
# Creating a complete dataframe
data_full <- expand.grid(
tahun = 2010:2021,
bulan = 1:12
)
# Join the data if needed (skipped if not necessary)
data_lengkap <- left_join(data_full, nilai_pengangguran_long, by = c("tahun", "bulan"))
# Fill missing values
set.seed(123)
data_lengkap$Nilai[is.na(data_lengkap$Nilai)] <- runif(sum(is.na(data_lengkap$Nilai)),
min = min(data_lengkap$Nilai, na.rm = TRUE),
max = max(data_lengkap$Nilai, na.rm = TRUE))
# Arrange the data by 'tahun' and 'bulan'
jumlah_pengangguran <- arrange(data_lengkap, tahun, bulan)
# Display the data
kable(head(jumlah_pengangguran), caption = "Jumlah Pengangguran (dalam persen)", col.names = c("Tahun", "Bulan", "Pengangguran"))
| Tahun | Bulan | Pengangguran |
|---|---|---|
| 2010 | 1 | 4.507770 |
| 2010 | 2 | 5.840000 |
| 2010 | 3 | 5.237057 |
| 2010 | 4 | 5.196170 |
| 2010 | 5 | 5.388319 |
| 2010 | 6 | 4.467369 |
# Unemployment Data
unemployment_data <- read_excel("Unemployment.xlsx")
kable(head(unemployment_data), caption = "Nilai Pengangguran di Indonesia")
| Tahun | Bulan | Pengangguran |
|---|---|---|
| 2010 | 1 | 4.507770 |
| 2010 | 2 | 5.840000 |
| 2010 | 3 | 5.237057 |
| 2010 | 4 | 5.196170 |
| 2010 | 5 | 5.388319 |
| 2010 | 6 | 4.467369 |
# Merge all data into 1 data
all_data <- nilai_bunga %>%
full_join(nilai_inflasi, by = c("Tahun", "Bulan")) %>%
full_join(nilai_kepercayaan, by = c("Tahun", "Bulan")) %>%
full_join(nilai_saham, by = c("Tahun", "Bulan")) %>%
full_join(nilai_tukar, by = c("Tahun", "Bulan")) %>%
full_join(unemployment_data, by = c("Tahun", "Bulan")) %>%
full_join(gdp_df, by = c("Tahun", "Bulan"))
all_data
shapiro.test(all_data$Suku_Bunga)
##
## Shapiro-Wilk normality test
##
## data: all_data$Suku_Bunga
## W = 0.93621, p-value = 4.182e-06
shapiro.test(all_data$Nilai_Inflasi)
##
## Shapiro-Wilk normality test
##
## data: all_data$Nilai_Inflasi
## W = 0.83733, p-value = 2.461e-11
shapiro.test(all_data$Konsumen)
##
## Shapiro-Wilk normality test
##
## data: all_data$Konsumen
## W = 0.89353, p-value = 9.861e-09
shapiro.test(all_data$Saham)
##
## Shapiro-Wilk normality test
##
## data: all_data$Saham
## W = 0.96468, p-value = 0.0009088
shapiro.test(all_data$BuyUSD)
##
## Shapiro-Wilk normality test
##
## data: all_data$BuyUSD
## W = 0.86108, p-value = 2.547e-10
shapiro.test(all_data$Pengangguran)
##
## Shapiro-Wilk normality test
##
## data: all_data$Pengangguran
## W = 0.95144, p-value = 6.189e-05
shapiro.test(all_data$GDP_Growth)
##
## Shapiro-Wilk normality test
##
## data: all_data$GDP_Growth
## W = 0.60165, p-value < 2.2e-16
summary(all_data) # Get a summary of the data
## Tahun Bulan Suku_Bunga Nilai_Inflasi
## Min. :2010 Min. : 1.00 Min. :3.500 Min. :-0.610
## 1st Qu.:2013 1st Qu.: 3.75 1st Qu.:4.750 1st Qu.: 0.890
## Median :2016 Median : 6.50 Median :5.750 Median : 1.710
## Mean :2016 Mean : 6.50 Mean :5.788 Mean : 2.112
## 3rd Qu.:2018 3rd Qu.: 9.25 3rd Qu.:6.750 3rd Qu.: 2.663
## Max. :2021 Max. :12.00 Max. :7.750 Max. : 8.380
## Konsumen Saham BuyUSD Pengangguran
## Min. : 77.3 Min. :2549 Min. : 8575 Min. :3.970
## 1st Qu.:108.6 1st Qu.:4272 1st Qu.: 9725 1st Qu.:4.429
## Median :114.3 Median :5078 Median :13367 Median :4.833
## Mean :113.1 Mean :5008 Mean :12305 Mean :4.896
## 3rd Qu.:119.3 3rd Qu.:5949 3rd Qu.:14134 3rd Qu.:5.383
## Max. :128.0 Max. :6606 Max. :15947 Max. :5.840
## GDP_Growth
## Min. :-10.100
## 1st Qu.: 4.904
## Median : 5.109
## Mean : 4.576
## 3rd Qu.: 5.702
## Max. : 11.119
Output Summary:
Suku Bunga (Interest Rates): p-value = 4.182e-06
Nilai Inflasi (Inflation Rate): p-value = 2.461e-11
Konsumen (Consumer Confidence): p-value = 9.861e-09
Saham (Stock Market Index): p-value = 0.0009088
BuyUSD (Exchange Rate): p-value = 2.547e-10
Pengangguran (Unemployment Rate): p-value = 6.189e-05
GDP Growth: p-value < 2.2e-16
Since all these p-values are significantly less than 0.05, we reject the null hypothesis for each Shapiro-Wilk test.
2.2 Data Exploration
summary(all_data)
## Tahun Bulan Suku_Bunga Nilai_Inflasi
## Min. :2010 Min. : 1.00 Min. :3.500 Min. :-0.610
## 1st Qu.:2013 1st Qu.: 3.75 1st Qu.:4.750 1st Qu.: 0.890
## Median :2016 Median : 6.50 Median :5.750 Median : 1.710
## Mean :2016 Mean : 6.50 Mean :5.788 Mean : 2.112
## 3rd Qu.:2018 3rd Qu.: 9.25 3rd Qu.:6.750 3rd Qu.: 2.663
## Max. :2021 Max. :12.00 Max. :7.750 Max. : 8.380
## Konsumen Saham BuyUSD Pengangguran
## Min. : 77.3 Min. :2549 Min. : 8575 Min. :3.970
## 1st Qu.:108.6 1st Qu.:4272 1st Qu.: 9725 1st Qu.:4.429
## Median :114.3 Median :5078 Median :13367 Median :4.833
## Mean :113.1 Mean :5008 Mean :12305 Mean :4.896
## 3rd Qu.:119.3 3rd Qu.:5949 3rd Qu.:14134 3rd Qu.:5.383
## Max. :128.0 Max. :6606 Max. :15947 Max. :5.840
## GDP_Growth
## Min. :-10.100
## 1st Qu.: 4.904
## Median : 5.109
## Mean : 4.576
## 3rd Qu.: 5.702
## Max. : 11.119
Output Summary:
Interest Rate
Range: Ranges from 3.500% to 7.750%.
Mean: The average interest rate is 5.788%, indicating a moderate interest rate trend during the period.Inflation (Inflation Rate)
Variation: Inflation fluctuations recorded from -0.610% to 8.380%.
Mean: The average inflation rate is 2.112%, indicating that inflation tends to be stable with some peaks during the observed period.Consumer Confidence
Range: The consumer confidence index ranges from 77.3 to 128.0.
Mean: The average consumer confidence is 113.1, showing a relatively high level of optimism among consumers.Stock Value
Range: Stock values fluctuate between 2549 and 6606.
Mean: The average stock value is 5008, showing a level of stability in the stock market with significant periods of increase.Exchange Rate (BuyUSD)
Range: The exchange rate ranges from 8575 to 15947 Rupiah per USD.
Mean: The average exchange rate is 12305 Rupiah per USD, showing considerable variability in the exchange rate during the period.Unemployment Rate
Range: The unemployment rate ranges from 3.970% to 5.840%.
Mean: The average unemployment rate is 4.896%, indicating that the unemployment rate is relatively stable but with some peaks during the period.GDP Growth
Range: GDP growth ranges from -10.100% to 11.119%, showing significant variability that may be influenced by global and domestic economic factors.
Mean: The average GDP growth is 4.576%, reflecting several years with lower economic growth and some years with strong growth.
2.3 Correlation Analysis
library(reshape2)
library(plotly)
# Select only numeric columns and exclude 'Tahun' and 'Bulan'
numeric_data <- all_data[, sapply(all_data, is.numeric)]
numeric_data <- select(numeric_data, -c(Tahun, Bulan))
# Calculate correlation matrix
cor_matrix <- cor(numeric_data, use = "complete.obs")
melted_cor_matrix <- melt(cor_matrix)
# Plotting the heatmap with Plotly
cor_heatmap <- plot_ly(data = melted_cor_matrix, x = ~Var1, y = ~Var2, z = ~value, type = "heatmap", colors = c('red', 'yellow', 'green'),
colorbar = list(title = "Correlation Color"))
cor_heatmap
Output Summary:
If the color is
Green: Indicates astrong positive correlation, meaning that the two variables tend tomove in the same direction.If the color is
Red: Indicates astrong negative correlation, meaning thatone variable tends to go up while the other goes down.If the color is
Yellow to Orange: Indicates aweaker correlationorno significant correlation.
2.4 Time Series Analysis
library(forecast)
# Function to perform time series analysis and fit an ARIMA model
perform_time_series_analysis <- function(data, variable_name) {
# Extract the variable as a time series object
ts_data <- ts(data[[variable_name]], frequency = 12, start = c(2010, 1))
# Fit ARIMA model
arima_model <- auto.arima(ts_data)
print(paste("ARIMA Model for", variable_name))
print(summary(arima_model))
# Forecast future values
forecast_variable <- forecast(arima_model, h = 12)
print(paste("Forecast for", variable_name))
print(summary(forecast_variable))
# Plot the forecast
plot(forecast_variable)
}
# Apply the function to each variable
variables <- c("Suku_Bunga", "Nilai_Inflasi", "Konsumen", "Saham", "BuyUSD", "Pengangguran", "GDP_Growth")
lapply(variables, function(v) perform_time_series_analysis(all_data, v))
## [1] "ARIMA Model for Suku_Bunga"
## Series: ts_data
## ARIMA(1,1,1)
##
## Coefficients:
## ar1 ma1
## 0.7363 -0.4268
## s.e. 0.1341 0.1844
##
## sigma^2 = 0.02698: log likelihood = 56.29
## AIC=-106.58 AICc=-106.41 BIC=-97.69
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.009539998 0.1625362 0.08326552 -0.1891552 1.536469 0.09216812
## ACF1
## Training set 0.0069565
## [1] "Forecast for Suku_Bunga"
##
## Forecast method: ARIMA(1,1,1)
##
## Model Information:
## Series: ts_data
## ARIMA(1,1,1)
##
## Coefficients:
## ar1 ma1
## 0.7363 -0.4268
## s.e. 0.1341 0.1844
##
## sigma^2 = 0.02698: log likelihood = 56.29
## AIC=-106.58 AICc=-106.41 BIC=-97.69
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.009539998 0.1625362 0.08326552 -0.1891552 1.536469 0.09216812
## ACF1
## Training set 0.0069565
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2022 3.499983 3.289480 3.710486 3.178047 3.821919
## Feb 2022 3.499971 3.153134 3.846807 2.969530 4.030411
## Mar 2022 3.499962 3.025593 3.974330 2.774478 4.225446
## Apr 2022 3.499955 2.905092 4.094818 2.590191 4.409719
## May 2022 3.499950 2.791401 4.208499 2.416318 4.583582
## Jun 2022 3.499947 2.684270 4.315623 2.252477 4.747416
## Jul 2022 3.499944 2.583316 4.416571 2.098083 4.901804
## Aug 2022 3.499942 2.488076 4.511807 1.952427 5.047457
## Sep 2022 3.499940 2.398057 4.601824 1.814755 5.185125
## Oct 2022 3.499939 2.312774 4.687105 1.684327 5.315552
## Nov 2022 3.499939 2.231769 4.768108 1.560440 5.439437
## Dec 2022 3.499938 2.154621 4.845255 1.442454 5.557422
## [1] "ARIMA Model for Nilai_Inflasi"
## Series: ts_data
## ARIMA(1,0,1)(2,1,2)[12]
##
## Coefficients:
## ar1 ma1 sar1 sar2 sma1 sma2
## 0.7736 0.1765 0.3375 -0.6983 -0.6605 0.3861
## s.e. 0.0651 0.1033 0.1831 0.1224 0.2222 0.2175
##
## sigma^2 = 0.445: log likelihood = -136.98
## AIC=287.96 AICc=288.86 BIC=308.14
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.05899188 0.6240334 0.389205 5.721138 41.01166 0.3765948
## ACF1
## Training set -0.001428381
## [1] "Forecast for Nilai_Inflasi"
##
## Forecast method: ARIMA(1,0,1)(2,1,2)[12]
##
## Model Information:
## Series: ts_data
## ARIMA(1,0,1)(2,1,2)[12]
##
## Coefficients:
## ar1 ma1 sar1 sar2 sma1 sma2
## 0.7736 0.1765 0.3375 -0.6983 -0.6605 0.3861
## s.e. 0.0651 0.1033 0.1831 0.1224 0.2222 0.2175
##
## sigma^2 = 0.445: log likelihood = -136.98
## AIC=287.96 AICc=288.86 BIC=308.14
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.05899188 0.6240334 0.389205 5.721138 41.01166 0.3765948
## ACF1
## Training set -0.001428381
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2022 0.4013526 -0.453611214 1.256317 -0.90620174 1.708907
## Feb 2022 0.4915134 -0.687802782 1.670830 -1.31209506 2.295122
## Mar 2022 0.5971463 -0.739146222 1.933439 -1.44653678 2.640829
## Apr 2022 0.8524542 -0.569520552 2.274429 -1.32226852 3.027177
## May 2022 1.2972387 -0.173629563 2.768107 -0.95226019 3.546738
## Jun 2022 1.4727085 -0.026659022 2.972076 -0.82037623 3.765793
## Jul 2022 1.6493120 0.133144742 3.165479 -0.66946573 3.968090
## Aug 2022 1.6939816 0.167848771 3.220114 -0.64003714 4.028000
## Sep 2022 1.5253069 -0.006758548 3.057372 -0.81778498 3.868399
## Oct 2022 1.6754646 0.139860577 3.211069 -0.67303908 4.023968
## Nov 2022 1.9320691 0.394352838 3.469785 -0.41966498 4.283803
## Dec 2022 2.4260296 0.887053269 3.965006 0.07236842 4.779691
## [1] "ARIMA Model for Konsumen"
## Series: ts_data
## ARIMA(2,0,1)(1,0,0)[12] with non-zero mean
##
## Coefficients:
## ar1 ar2 ma1 sar1 mean
## -0.1863 0.7224 0.8177 0.2405 112.7025
## s.e. 0.0855 0.0682 0.0885 0.0996 2.4312
##
## sigma^2 = 36.24: log likelihood = -461.33
## AIC=934.66 AICc=935.27 BIC=952.48
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.1021328 5.914251 3.859076 -0.2496808 3.618736 0.4862525
## ACF1
## Training set 0.05279101
## [1] "Forecast for Konsumen"
##
## Forecast method: ARIMA(2,0,1)(1,0,0)[12] with non-zero mean
##
## Model Information:
## Series: ts_data
## ARIMA(2,0,1)(1,0,0)[12] with non-zero mean
##
## Coefficients:
## ar1 ar2 ma1 sar1 mean
## -0.1863 0.7224 0.8177 0.2405 112.7025
## s.e. 0.0855 0.0682 0.0885 0.0996 2.4312
##
## sigma^2 = 36.24: log likelihood = -461.33
## AIC=934.66 AICc=935.27 BIC=952.48
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.1021328 5.914251 3.859076 -0.2496808 3.618736 0.4862525
## ACF1
## Training set 0.05279101
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2022 109.9983 102.28374 117.7128 98.19991 121.7966
## Feb 2022 118.8204 109.69666 127.9441 104.86686 132.7739
## Mar 2022 111.0314 100.78418 121.2786 95.35962 126.7032
## Apr 2022 118.1867 107.60245 128.7709 101.99949 134.3739
## May 2022 110.4525 99.48441 121.4206 93.67825 127.2267
## Jun 2022 118.3938 107.33947 129.4481 101.48766 135.2999
## Jul 2022 101.7067 90.50341 112.9100 84.57274 118.8407
## Aug 2022 115.0282 103.80566 126.2507 97.86483 132.1915
## Sep 2022 109.4652 98.17940 120.7509 92.20508 126.7252
## Oct 2022 116.8278 105.53922 128.1163 99.56341 134.0921
## Nov 2022 109.3944 98.07642 120.7123 92.08506 126.7037
## Dec 2022 116.4190 105.10104 127.7370 99.10966 133.7284
## [1] "ARIMA Model for Saham"
## Series: ts_data
## ARIMA(0,1,0)
##
## sigma^2 = 56777: log likelihood = -985.61
## AIC=1973.22 AICc=1973.25 BIC=1976.19
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 27.5923 237.4514 166.9619 0.5247602 3.478043 0.2801256 -0.05971234
## [1] "Forecast for Saham"
##
## Forecast method: ARIMA(0,1,0)
##
## Model Information:
## Series: ts_data
## ARIMA(0,1,0)
##
## sigma^2 = 56777: log likelihood = -985.61
## AIC=1973.22 AICc=1973.25 BIC=1976.19
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 27.5923 237.4514 166.9619 0.5247602 3.478043 0.2801256 -0.05971234
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2022 6581.48 6276.112 6886.848 6114.459 7048.501
## Feb 2022 6581.48 6149.624 7013.336 5921.013 7241.947
## Mar 2022 6581.48 6052.567 7110.393 5772.577 7390.383
## Apr 2022 6581.48 5970.743 7192.217 5647.439 7515.521
## May 2022 6581.48 5898.656 7264.304 5537.190 7625.770
## Jun 2022 6581.48 5833.483 7329.477 5437.518 7725.442
## Jul 2022 6581.48 5773.551 7389.409 5345.860 7817.100
## Aug 2022 6581.48 5717.768 7445.192 5260.546 7902.414
## Sep 2022 6581.48 5665.375 7497.585 5180.418 7982.542
## Oct 2022 6581.48 5615.821 7547.139 5104.631 8058.329
## Nov 2022 6581.48 5568.688 7594.272 5032.548 8130.412
## Dec 2022 6581.48 5523.653 7639.307 4963.673 8199.287
## [1] "ARIMA Model for BuyUSD"
## Series: ts_data
## ARIMA(0,1,2) with drift
##
## Coefficients:
## ma1 ma2 drift
## 0.2917 -0.2924 35.6802
## s.e. 0.0825 0.0846 19.9369
##
## sigma^2 = 57895: log likelihood = -985.67
## AIC=1979.34 AICc=1979.63 BIC=1991.19
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.1099729 237.2492 160.5378 -0.01196701 1.262497 0.2181402
## ACF1
## Training set 0.02343315
## [1] "Forecast for BuyUSD"
##
## Forecast method: ARIMA(0,1,2) with drift
##
## Model Information:
## Series: ts_data
## ARIMA(0,1,2) with drift
##
## Coefficients:
## ma1 ma2 drift
## 0.2917 -0.2924 35.6802
## s.e. 0.0825 0.0846 19.9369
##
## sigma^2 = 57895: log likelihood = -985.67
## AIC=1979.34 AICc=1979.63 BIC=1991.19
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.1099729 237.2492 160.5378 -0.01196701 1.262497 0.2181402
## ACF1
## Training set 0.02343315
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2022 14425.48 14117.12 14733.84 13953.88 14897.07
## Feb 2022 14463.84 13960.11 14967.57 13693.45 15234.23
## Mar 2022 14499.52 13909.01 15090.03 13596.41 15402.63
## Apr 2022 14535.20 13869.12 15201.28 13516.52 15553.88
## May 2022 14570.88 13836.97 15304.79 13448.47 15693.30
## Jun 2022 14606.56 13810.58 15402.54 13389.22 15823.90
## Jul 2022 14642.24 13788.70 15495.79 13336.86 15947.62
## Aug 2022 14677.92 13770.45 15585.39 13290.07 16065.77
## Sep 2022 14713.60 13755.24 15671.96 13247.91 16179.29
## Oct 2022 14749.28 13742.60 15755.97 13209.69 16288.87
## Nov 2022 14784.96 13732.17 15837.76 13174.85 16395.07
## Dec 2022 14820.64 13723.68 15917.61 13142.98 16498.31
## [1] "ARIMA Model for Pengangguran"
## Series: ts_data
## ARIMA(0,0,0)(1,0,1)[12] with non-zero mean
##
## Coefficients:
## sar1 sma1 mean
## -0.6555 0.8394 4.8989
## s.e. 0.2580 0.2341 0.0487
##
## sigma^2 = 0.2843: log likelihood = -113.34
## AIC=234.68 AICc=234.97 BIC=246.56
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.001640261 0.5276214 0.4568886 -1.215264 9.455504 0.7839525
## ACF1
## Training set -0.03884174
## [1] "Forecast for Pengangguran"
##
## Forecast method: ARIMA(0,0,0)(1,0,1)[12] with non-zero mean
##
## Model Information:
## Series: ts_data
## ARIMA(0,0,0)(1,0,1)[12] with non-zero mean
##
## Coefficients:
## sar1 sma1 mean
## -0.6555 0.8394 4.8989
## s.e. 0.2580 0.2341 0.0487
##
## sigma^2 = 0.2843: log likelihood = -113.34
## AIC=234.68 AICc=234.97 BIC=246.56
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.001640261 0.5276214 0.4568886 -1.215264 9.455504 0.7839525
## ACF1
## Training set -0.03884174
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2022 4.755034 4.071451 5.438617 3.709584 5.800484
## Feb 2022 4.994487 4.310904 5.678070 3.949037 6.039937
## Mar 2022 5.118395 4.434812 5.801978 4.072945 6.163845
## Apr 2022 5.052035 4.368452 5.735618 4.006585 6.097485
## May 2022 4.929987 4.246404 5.613570 3.884537 5.975437
## Jun 2022 4.797122 4.113539 5.480705 3.751672 5.842572
## Jul 2022 4.737928 4.054345 5.421511 3.692478 5.783378
## Aug 2022 4.849284 4.165701 5.532867 3.803834 5.894734
## Sep 2022 5.043759 4.360176 5.727342 3.998309 6.089209
## Oct 2022 4.927219 4.243636 5.610802 3.881769 5.972669
## Nov 2022 4.938703 4.255120 5.622286 3.893253 5.984153
## Dec 2022 4.889139 4.205556 5.572722 3.843689 5.934589
## [1] "ARIMA Model for GDP_Growth"
## Series: ts_data
## ARIMA(0,1,1)(1,0,0)[12]
##
## Coefficients:
## ma1 sar1
## -0.4692 -0.4263
## s.e. 0.0784 0.1045
##
## sigma^2 = 3.516: log likelihood = -293.13
## AIC=592.26 AICc=592.43 BIC=601.15
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.0883944 1.855498 0.7241287 -4.881224 23.32692 0.3767776
## ACF1
## Training set -0.01249724
## [1] "Forecast for GDP_Growth"
##
## Forecast method: ARIMA(0,1,1)(1,0,0)[12]
##
## Model Information:
## Series: ts_data
## ARIMA(0,1,1)(1,0,0)[12]
##
## Coefficients:
## ma1 sar1
## -0.4692 -0.4263
## s.e. 0.0784 0.1045
##
## sigma^2 = 3.516: log likelihood = -293.13
## AIC=592.26 AICc=592.43 BIC=601.15
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.0883944 1.855498 0.7241287 -4.881224 23.32692 0.3767776
## ACF1
## Training set -0.01249724
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 2022 2.28991601 -0.1131648 4.6929968 -1.385279 5.965111
## Feb 2022 2.12461418 -0.5960031 4.8452314 -2.036211 6.285439
## Mar 2022 0.09732648 -2.9074562 3.1021092 -4.498092 4.692745
## Apr 2022 -3.61804881 -6.8823528 -0.3537449 -8.610371 1.374273
## May 2022 -2.70681367 -6.2114736 0.7978463 -8.066729 2.653101
## Jun 2022 -2.75431358 -6.4838715 0.9752443 -8.458180 2.949553
## Jul 2022 0.55703169 -3.3846131 4.4986764 -5.471194 6.585257
## Aug 2022 -2.03895113 -6.1818395 2.1039373 -8.374952 4.297050
## Sep 2022 -0.59150595 -4.9263053 3.7432934 -7.221009 6.037998
## Oct 2022 -1.54313596 -6.0617028 2.9754309 -8.453688 5.367416
## Nov 2022 -2.12777303 -6.8229202 2.5673742 -9.308381 5.052835
## Dec 2022 0.78655410 -4.0787689 5.6518772 -6.654315 8.227424
## [[1]]
## [[1]]$mean
## Jan Feb Mar Apr May Jun Jul Aug
## 2022 3.499983 3.499971 3.499962 3.499955 3.499950 3.499947 3.499944 3.499942
## Sep Oct Nov Dec
## 2022 3.499940 3.499939 3.499939 3.499938
##
## [[1]]$lower
## 80% 95%
## Jan 2022 3.289480 3.178047
## Feb 2022 3.153134 2.969530
## Mar 2022 3.025593 2.774478
## Apr 2022 2.905092 2.590191
## May 2022 2.791401 2.416318
## Jun 2022 2.684270 2.252477
## Jul 2022 2.583316 2.098083
## Aug 2022 2.488076 1.952427
## Sep 2022 2.398057 1.814755
## Oct 2022 2.312774 1.684327
## Nov 2022 2.231769 1.560440
## Dec 2022 2.154621 1.442454
##
## [[1]]$upper
## 80% 95%
## Jan 2022 3.710486 3.821919
## Feb 2022 3.846807 4.030411
## Mar 2022 3.974330 4.225446
## Apr 2022 4.094818 4.409719
## May 2022 4.208499 4.583582
## Jun 2022 4.315623 4.747416
## Jul 2022 4.416571 4.901804
## Aug 2022 4.511807 5.047457
## Sep 2022 4.601824 5.185125
## Oct 2022 4.687105 5.315552
## Nov 2022 4.768108 5.439437
## Dec 2022 4.845255 5.557422
##
##
## [[2]]
## [[2]]$mean
## Jan Feb Mar Apr May Jun Jul
## 2022 0.4013526 0.4915134 0.5971463 0.8524542 1.2972387 1.4727085 1.6493120
## Aug Sep Oct Nov Dec
## 2022 1.6939816 1.5253069 1.6754646 1.9320691 2.4260296
##
## [[2]]$lower
## 80% 95%
## Jan 2022 -0.453611214 -0.90620174
## Feb 2022 -0.687802782 -1.31209506
## Mar 2022 -0.739146222 -1.44653678
## Apr 2022 -0.569520552 -1.32226852
## May 2022 -0.173629563 -0.95226019
## Jun 2022 -0.026659022 -0.82037623
## Jul 2022 0.133144742 -0.66946573
## Aug 2022 0.167848771 -0.64003714
## Sep 2022 -0.006758548 -0.81778498
## Oct 2022 0.139860577 -0.67303908
## Nov 2022 0.394352838 -0.41966498
## Dec 2022 0.887053269 0.07236842
##
## [[2]]$upper
## 80% 95%
## Jan 2022 1.256317 1.708907
## Feb 2022 1.670830 2.295122
## Mar 2022 1.933439 2.640829
## Apr 2022 2.274429 3.027177
## May 2022 2.768107 3.546738
## Jun 2022 2.972076 3.765793
## Jul 2022 3.165479 3.968090
## Aug 2022 3.220114 4.028000
## Sep 2022 3.057372 3.868399
## Oct 2022 3.211069 4.023968
## Nov 2022 3.469785 4.283803
## Dec 2022 3.965006 4.779691
##
##
## [[3]]
## [[3]]$mean
## Jan Feb Mar Apr May Jun Jul Aug
## 2022 109.9983 118.8204 111.0314 118.1867 110.4525 118.3938 101.7067 115.0282
## Sep Oct Nov Dec
## 2022 109.4652 116.8278 109.3944 116.4190
##
## [[3]]$lower
## 80% 95%
## Jan 2022 102.28374 98.19991
## Feb 2022 109.69666 104.86686
## Mar 2022 100.78418 95.35962
## Apr 2022 107.60245 101.99949
## May 2022 99.48441 93.67825
## Jun 2022 107.33947 101.48766
## Jul 2022 90.50341 84.57274
## Aug 2022 103.80566 97.86483
## Sep 2022 98.17940 92.20508
## Oct 2022 105.53922 99.56341
## Nov 2022 98.07642 92.08506
## Dec 2022 105.10104 99.10966
##
## [[3]]$upper
## 80% 95%
## Jan 2022 117.7128 121.7966
## Feb 2022 127.9441 132.7739
## Mar 2022 121.2786 126.7032
## Apr 2022 128.7709 134.3739
## May 2022 121.4206 127.2267
## Jun 2022 129.4481 135.2999
## Jul 2022 112.9100 118.8407
## Aug 2022 126.2507 132.1915
## Sep 2022 120.7509 126.7252
## Oct 2022 128.1163 134.0921
## Nov 2022 120.7123 126.7037
## Dec 2022 127.7370 133.7284
##
##
## [[4]]
## [[4]]$mean
## Jan Feb Mar Apr May Jun Jul Aug Sep
## 2022 6581.48 6581.48 6581.48 6581.48 6581.48 6581.48 6581.48 6581.48 6581.48
## Oct Nov Dec
## 2022 6581.48 6581.48 6581.48
##
## [[4]]$lower
## 80% 95%
## Jan 2022 6276.112 6114.459
## Feb 2022 6149.624 5921.013
## Mar 2022 6052.567 5772.577
## Apr 2022 5970.743 5647.439
## May 2022 5898.656 5537.190
## Jun 2022 5833.483 5437.518
## Jul 2022 5773.551 5345.860
## Aug 2022 5717.768 5260.546
## Sep 2022 5665.375 5180.418
## Oct 2022 5615.821 5104.631
## Nov 2022 5568.688 5032.548
## Dec 2022 5523.653 4963.673
##
## [[4]]$upper
## 80% 95%
## Jan 2022 6886.848 7048.501
## Feb 2022 7013.336 7241.947
## Mar 2022 7110.393 7390.383
## Apr 2022 7192.217 7515.521
## May 2022 7264.304 7625.770
## Jun 2022 7329.477 7725.442
## Jul 2022 7389.409 7817.100
## Aug 2022 7445.192 7902.414
## Sep 2022 7497.585 7982.542
## Oct 2022 7547.139 8058.329
## Nov 2022 7594.272 8130.412
## Dec 2022 7639.307 8199.287
##
##
## [[5]]
## [[5]]$mean
## Jan Feb Mar Apr May Jun Jul Aug
## 2022 14425.48 14463.84 14499.52 14535.20 14570.88 14606.56 14642.24 14677.92
## Sep Oct Nov Dec
## 2022 14713.60 14749.28 14784.96 14820.64
##
## [[5]]$lower
## 80% 95%
## Jan 2022 14117.12 13953.88
## Feb 2022 13960.11 13693.45
## Mar 2022 13909.01 13596.41
## Apr 2022 13869.12 13516.52
## May 2022 13836.97 13448.47
## Jun 2022 13810.58 13389.22
## Jul 2022 13788.70 13336.86
## Aug 2022 13770.45 13290.07
## Sep 2022 13755.24 13247.91
## Oct 2022 13742.60 13209.69
## Nov 2022 13732.17 13174.85
## Dec 2022 13723.68 13142.98
##
## [[5]]$upper
## 80% 95%
## Jan 2022 14733.84 14897.07
## Feb 2022 14967.57 15234.23
## Mar 2022 15090.03 15402.63
## Apr 2022 15201.28 15553.88
## May 2022 15304.79 15693.30
## Jun 2022 15402.54 15823.90
## Jul 2022 15495.79 15947.62
## Aug 2022 15585.39 16065.77
## Sep 2022 15671.96 16179.29
## Oct 2022 15755.97 16288.87
## Nov 2022 15837.76 16395.07
## Dec 2022 15917.61 16498.31
##
##
## [[6]]
## [[6]]$mean
## Jan Feb Mar Apr May Jun Jul Aug
## 2022 4.755034 4.994487 5.118395 5.052035 4.929987 4.797122 4.737928 4.849284
## Sep Oct Nov Dec
## 2022 5.043759 4.927219 4.938703 4.889139
##
## [[6]]$lower
## 80% 95%
## Jan 2022 4.071451 3.709584
## Feb 2022 4.310904 3.949037
## Mar 2022 4.434812 4.072945
## Apr 2022 4.368452 4.006585
## May 2022 4.246404 3.884537
## Jun 2022 4.113539 3.751672
## Jul 2022 4.054345 3.692478
## Aug 2022 4.165701 3.803834
## Sep 2022 4.360176 3.998309
## Oct 2022 4.243636 3.881769
## Nov 2022 4.255120 3.893253
## Dec 2022 4.205556 3.843689
##
## [[6]]$upper
## 80% 95%
## Jan 2022 5.438617 5.800484
## Feb 2022 5.678070 6.039937
## Mar 2022 5.801978 6.163845
## Apr 2022 5.735618 6.097485
## May 2022 5.613570 5.975437
## Jun 2022 5.480705 5.842572
## Jul 2022 5.421511 5.783378
## Aug 2022 5.532867 5.894734
## Sep 2022 5.727342 6.089209
## Oct 2022 5.610802 5.972669
## Nov 2022 5.622286 5.984153
## Dec 2022 5.572722 5.934589
##
##
## [[7]]
## [[7]]$mean
## Jan Feb Mar Apr May Jun
## 2022 2.28991601 2.12461418 0.09732648 -3.61804881 -2.70681367 -2.75431358
## Jul Aug Sep Oct Nov Dec
## 2022 0.55703169 -2.03895113 -0.59150595 -1.54313596 -2.12777303 0.78655410
##
## [[7]]$lower
## 80% 95%
## Jan 2022 -0.1131648 -1.385279
## Feb 2022 -0.5960031 -2.036211
## Mar 2022 -2.9074562 -4.498092
## Apr 2022 -6.8823528 -8.610371
## May 2022 -6.2114736 -8.066729
## Jun 2022 -6.4838715 -8.458180
## Jul 2022 -3.3846131 -5.471194
## Aug 2022 -6.1818395 -8.374952
## Sep 2022 -4.9263053 -7.221009
## Oct 2022 -6.0617028 -8.453688
## Nov 2022 -6.8229202 -9.308381
## Dec 2022 -4.0787689 -6.654315
##
## [[7]]$upper
## 80% 95%
## Jan 2022 4.6929968 5.965111
## Feb 2022 4.8452314 6.285439
## Mar 2022 3.1021092 4.692745
## Apr 2022 -0.3537449 1.374273
## May 2022 0.7978463 2.653101
## Jun 2022 0.9752443 2.949553
## Jul 2022 4.4986764 6.585257
## Aug 2022 2.1039373 4.297050
## Sep 2022 3.7432934 6.037998
## Oct 2022 2.9754309 5.367416
## Nov 2022 2.5673742 5.052835
## Dec 2022 5.6518772 8.227424
2.5 Regression Analysis
library(car) # for variance inflation factor (VIF) to check multicollinearity
# Fit the linear regression model
model <- lm(GDP_Growth ~ Suku_Bunga + Nilai_Inflasi + Konsumen + Saham + BuyUSD + Pengangguran, data = all_data)
# Print the summary of the model to see the coefficients and statistics
summary(model)
##
## Call:
## lm(formula = GDP_Growth ~ Suku_Bunga + Nilai_Inflasi + Konsumen +
## Saham + BuyUSD + Pengangguran, data = all_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.0059 -0.7579 0.2168 1.0040 8.4466
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4.2007972 3.9824642 -1.055 0.29336
## Suku_Bunga 0.6130854 0.2081316 2.946 0.00379 **
## Nilai_Inflasi 0.0239675 0.1206298 0.199 0.84280
## Konsumen 0.0965353 0.0307359 3.141 0.00206 **
## Saham 0.0008206 0.0004892 1.678 0.09571 .
## BuyUSD -0.0007625 0.0001849 -4.124 6.43e-05 ***
## Pengangguran -0.0948692 0.3842556 -0.247 0.80536
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.473 on 137 degrees of freedom
## Multiple R-squared: 0.3606, Adjusted R-squared: 0.3326
## F-statistic: 12.88 on 6 and 137 DF, p-value: 1.664e-11
# Calculate VIF for each independent variable
vif_values <- vif(model)
vif_values # High VIF values (> 5 or 10) might indicate problematic multicollinearity
## Suku_Bunga Nilai_Inflasi Konsumen Saham BuyUSD
## 1.670518 1.150678 1.749304 5.773649 3.825904
## Pengangguran
## 1.023701
# Enhanced Diagnostic Plots
par(mfrow=c(2,2))
plot(model)
Output Summary:
Regression model is
Y = −4.2007972 + (0.6130854 × Suku_Bunga) + (0.0239675 × Nilai_Inflasi) + (0.0965353 × Konsumen) + (0.0008206 × Saham) − (0.0007625× BuyUSD) − (0.0948692 × Pengangguran).p-value: 1.664e-11which means \(H_0\)is rejected, or there is a difference in each variable.All VIF values are under 10, so it generally indicates that there is
not a serious issue with multicollinearityamong the predictors.Adjusted R-Squared: 0.3326, the meaning is approximately
33.26% of the variability in the dependent variable can be explained by the predictors in the model. The rest of the variability is due to other factors or random noise.
2.6 Model Evaluation
library(forecast)
library(Metrics)
# Inisialisasi dataframe untuk menyimpan hasil MAE
mae_results <- data.frame(Model = character(), MAE = numeric(), stringsAsFactors = FALSE)
# Fungsi untuk melakukan time series analysis dan menghitung MAE
perform_time_series_analysis <- function(data, variable_name) {
# Mendapatkan data time series dari variabel tertentu
ts_data <- ts(data[[variable_name]], frequency = 12, start = c(2010, 1))
# Membangun model ARIMA
arima_model <- auto.arima(ts_data)
# Memprediksi 12 periode ke depan
forecast_variable <- forecast(arima_model, h = 12)$mean
# Ambil data aktual untuk 12 bulan terakhir untuk validasi
actual_data <- window(ts_data, start = c(2021, 1), end = c(2021, 12))
# Menghitung MAE
mae_value <- mae(actual_data, forecast_variable)
# Menyimpan hasil ke dataframe global
mae_results <<- rbind(mae_results, data.frame(Model = variable_name, MAE = mae_value))
}
# Menerapkan fungsi ke setiap variabel
set.seed(123)
variable_list <- c("Suku_Bunga", "Nilai_Inflasi", "Konsumen", "Saham", "BuyUSD", "Pengangguran", "GDP_Growth")
for (variable in variable_list) {
perform_time_series_analysis(all_data, variable)
}
# Menampilkan hasil MAE
print(mae_results)
## Model MAE
## 1 Suku_Bunga NaN
## 2 Nilai_Inflasi NaN
## 3 Konsumen NaN
## 4 Saham NaN
## 5 BuyUSD NaN
## 6 Pengangguran NaN
## 7 GDP_Growth NaN
Output Summary:
* Insufficient Data or too Many Missing Values: If there isn’t enough data or if there are many missing values, it can be hard to build a good ARIMA model. This might cause the calculations to fail, resulting in NaN values.
2.7 Policy Implications
Impact of Changes in Economic Indicators
- Inflation and Interest Rates
Relationship: High inflation often prompts the central bank to raise interest rates to curb demand and control inflation.
Impact: Higher interest rates can reduce investment and consumption, which in turn can slow down economic growth.
- Exchange Rate (Rupiah)
Relationship: Depreciation of the exchange rate can increase import prices and trigger inflation.
Impact: Higher import prices can reduce consumer purchasing power and increase production costs for companies reliant on imported raw materials.
- Consumer Confidence
Relationship: High consumer confidence typically correlates with increased consumer spending.
Impact: Higher consumer spending can boost economic growth, but it also risks increasing inflation if not matched by higher production.
- Unemployment Rate
Relationship: A decrease in the unemployment rate usually boosts household income and consumer spending.
Impact: Increased consumer spending can drive economic growth but may also lead to inflationary pressures.
- GDP Growth
Relationship: Strong GDP growth reflects increased economic activity and overall economic welfare.
Impact: Sustained growth can enhance employment and income, but too rapid growth may cause overheating and inflation.
Recommendations for Managing Economic Policy and Promoting Economic Stability
Monetary Policy
Fiscal Policy
Exchange Rate Stability
Increasing Consumer Confidence
Reducing Unemployment
Sustainable Economic Growth
2.8 Documentation
Already attach in this RMD :)
2.9 Presentation
This link to check my visualization with flexdashboard in R. I know the visualization is not good, but next time i’ll try…
Check this out:
References
saham: https://www.bps.go.id/id/statistics-table/2/MTI1IzI=/transaksi-dan-indeks-saham-di-bursa-efek.html
suku bunga: https://www.bps.go.id/id/statistics-table/2/Mzc5IzI=/bi-rate.html
kepercayaan konsumen: https://id.tradingeconomics.com/indonesia/consumer-confidence
pertumbuhan PDB: https://id.tradingeconomics.com/indonesia/gdp-growth-annual
https://www.geeksforgeeks.org/union-union_all-functions-in-dplyr-package-in-r/
https://stackoverflow.com/questions/15561631/how-to-union-tables-in-r
https://bookdown.org/yihui/rmarkdown-cookbook/html-tabs.html