Analisi ini bertujuan untuk mengetahui bagaimana perubahan harga minyak dunia memengaruhi tingkat inflasi di Indonesia dengan menggunakan pendekatan Vector Autoregression (VAR).
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(tseries) # adf.test()
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(dynlm) # dynlm()
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(vars) # VAR()
## Loading required package: MASS
## Loading required package: strucchange
## Loading required package: sandwich
## Loading required package: urca
## Loading required package: lmtest
library(nlWaldTest) # nlWaldtest()
library(lmtest) # coeftest() & bptest()
library(broom) # glance() & tidy()
library(car) # hccm() robust standard errors
## Loading required package: carData
library(sandwich)
library(knitr) #kable()
library(forecast)
library(ggplot2)
data_uas <- read.csv("C:/Users/Me/OneDrive/Dokumen//EKONOMETRIKA SMT 5/data_uasekomet.csv",sep = ";")
str(data_uas)
## 'data.frame': 120 obs. of 3 variables:
## $ Bulan_Tahun : chr "Jan-15" "Feb-15" "Mar-15" "Apr-15" ...
## $ Harga_Minyak: num 47.2 50.6 47.8 54.5 59.3 ...
## $ Inflasi : num 6.96 6.29 6.38 6.79 7.15 7.26 7.26 7.18 6.83 6.25 ...
head(data_uas)
## Bulan_Tahun Harga_Minyak Inflasi
## 1 Jan-15 47.22 6.96
## 2 Feb-15 50.58 6.29
## 3 Mar-15 47.82 6.38
## 4 Apr-15 54.45 6.79
## 5 May-15 59.27 7.15
## 6 Jun-15 59.82 7.26
# PREPROCESSING
# Cek Missing value
colSums(is.na(data_uas))
## Bulan_Tahun Harga_Minyak Inflasi
## 0 0 0
# Cek Outlier
## Boxplot
boxplot(data_uas[, c("Harga_Minyak", "Inflasi")],
main = "Deteksi Outlier",
col = "lightblue")
## Ubah time series
inflasi_ts <- ts(data_uas$Inflasi, start = c(2015, 1), frequency = 12)
minyak_ts <- ts(data_uas$Harga_Minyak, start = c(2015, 1), frequency = 12)
#plot time series
# Plot Inflasi
inflasi_ts <- ts(data_uas$Inflasi, start = c(2015, 1), frequency = 12)
plot(inflasi_ts,
ylab = "Inflasi (%)",
xlab = "Tahun",
main = "Plot Time Series Inflasi",
col = "blue", lwd = 2)
# Plot Harga Minyak
minyak_ts <- ts(data_uas$Harga_Minyak, start = c(2015, 1), frequency = 12)
plot(minyak_ts,
ylab = "Harga Minyak (USD)",
xlab = "Tahun",
main = "Plot Time Series Harga Minyak Dunia",
col = "red", lwd = 2)
#Uji stasioner
#Uji ACF
Acf(data_uas[,"Inflasi"])
Acf(data_uas[,"Harga_Minyak"])
# Uji ADF untuk Inflasi
adf.test(inflasi_ts)
##
## Augmented Dickey-Fuller Test
##
## data: inflasi_ts
## Dickey-Fuller = -3.1448, Lag order = 4, p-value = 0.1011
## alternative hypothesis: stationary
# Uji ADF untuk Harga Minyak
adf.test(minyak_ts)
##
## Augmented Dickey-Fuller Test
##
## data: minyak_ts
## Dickey-Fuller = -2.5279, Lag order = 4, p-value = 0.3573
## alternative hypothesis: stationary
#differencing
#inflansi
print(adf.test(diff(inflasi_ts)))
##
## Augmented Dickey-Fuller Test
##
## data: diff(inflasi_ts)
## Dickey-Fuller = -3.793, Lag order = 4, p-value = 0.0217
## alternative hypothesis: stationary
#minyak
print(adf.test(diff(minyak_ts)))
## Warning in adf.test(diff(minyak_ts)): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: diff(minyak_ts)
## Dickey-Fuller = -4.8577, Lag order = 4, p-value = 0.01
## alternative hypothesis: stationary
#plot setelah diff
# Inflasi
diff_inflasi <- diff(inflasi_ts)
plot(diff_inflasi,
main = "Plot Inflasi Setelah Differencing (D1)",
ylab = "Diff Inflasi",
xlab = "Tahun")
# Harga Minyak
diff_minyak <- diff(minyak_ts)
plot(diff_minyak,
main = "Plot Harga Minyak Setelah Differencing (D1)",
ylab = "Diff Harga Minyak",
xlab = "Tahun")
#mencari lag optimum
data_uas <- cbind(Inflasi = inflasi_ts,
Minyak = minyak_ts)
VARselect(data_uas, lag.max = 9, type = "const")
## $selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 2 1 1 2
##
## $criteria
## 1 2 3 4 5 6 7 8
## AIC(n) 1.456529 1.448399 1.449411 1.466994 1.476826 1.506597 1.531638 1.584056
## HQ(n) 1.515944 1.547424 1.588046 1.645239 1.694681 1.764062 1.828713 1.920740
## SC(n) 1.602990 1.692501 1.791154 1.906378 2.013850 2.141262 2.263944 2.414002
## FPE(n) 4.291154 4.256814 4.262034 4.339277 4.384743 4.521107 4.641163 4.898427
## 9
## AIC(n) 1.601829
## HQ(n) 1.978123
## SC(n) 2.529416
## FPE(n) 4.995992
# Uji stabilitas
var=VAR(data_uas,p=2,type="const")
roots(var)
## [1] 0.9305485 0.9305485 0.3119314 0.1131951
#uji kointegrasi
cointcy <- dynlm(inflasi_ts~minyak_ts, data=data_uas)
ehat <- resid(cointcy)
adf.test(ehat)
##
## Augmented Dickey-Fuller Test
##
## data: ehat
## Dickey-Fuller = -3.1941, Lag order = 4, p-value = 0.09223
## alternative hypothesis: stationary
#Uji Kausalitas
data_uas <- cbind(
dInflasi = diff(inflasi_ts),
dMinyak = diff(minyak_ts)
)
var_diff <- VAR(data_uas, p = 2, type = "const")
causality(var_diff, cause = "dMinyak")
## $Granger
##
## Granger causality H0: dMinyak do not Granger-cause dInflasi
##
## data: VAR object var_diff
## F-Test = 2.107, df1 = 2, df2 = 224, p-value = 0.124
##
##
## $Instant
##
## H0: No instantaneous causality between: dMinyak and dInflasi
##
## data: VAR object var_diff
## Chi-squared = 2.1672, df = 1, p-value = 0.141
causality(var_diff, cause = "dInflasi")
## $Granger
##
## Granger causality H0: dInflasi do not Granger-cause dMinyak
##
## data: VAR object var_diff
## F-Test = 0.086412, df1 = 2, df2 = 224, p-value = 0.9172
##
##
## $Instant
##
## H0: No instantaneous causality between: dInflasi and dMinyak
##
## data: VAR object var_diff
## Chi-squared = 2.1672, df = 1, p-value = 0.141
#Pembentukan Model VAR
dInflasi <- diff(inflasi_ts)
dMinyak <- diff(minyak_ts)
varmat <- cbind(dInflasi, dMinyak)
varfit <- VAR(varmat, p = 2, type = "const")
summary(varfit)
##
## VAR Estimation Results:
## =========================
## Endogenous variables: dInflasi, dMinyak
## Deterministic variables: const
## Sample size: 117
## Log Likelihood: -415.128
## Roots of the characteristic polynomial:
## 0.395 0.395 0.2655 0.0112
## Call:
## VAR(y = varmat, p = 2, type = "const")
##
##
## Estimation results for equation dInflasi:
## =========================================
## dInflasi = dInflasi.l1 + dMinyak.l1 + dInflasi.l2 + dMinyak.l2 + const
##
## Estimate Std. Error t value Pr(>|t|)
## dInflasi.l1 0.210245 0.095216 2.208 0.0293 *
## dMinyak.l1 0.012853 0.006314 2.036 0.0442 *
## dInflasi.l2 0.008420 0.092440 0.091 0.9276
## dMinyak.l2 -0.001623 0.006432 -0.252 0.8013
## const -0.034000 0.035527 -0.957 0.3406
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 0.3801 on 112 degrees of freedom
## Multiple R-Squared: 0.0713, Adjusted R-squared: 0.03814
## F-statistic: 2.15 on 4 and 112 DF, p-value: 0.0793
##
##
## Estimation results for equation dMinyak:
## ========================================
## dMinyak = dInflasi.l1 + dMinyak.l1 + dInflasi.l2 + dMinyak.l2 + const
##
## Estimate Std. Error t value Pr(>|t|)
## dInflasi.l1 0.01054 1.41436 0.007 0.99407
## dMinyak.l1 0.27247 0.09380 2.905 0.00443 **
## dInflasi.l2 0.55660 1.37313 0.405 0.68599
## dMinyak.l2 -0.16238 0.09555 -1.699 0.09201 .
## const 0.20527 0.52773 0.389 0.69804
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 5.645 on 112 degrees of freedom
## Multiple R-Squared: 0.08216, Adjusted R-squared: 0.04938
## F-statistic: 2.506 on 4 and 112 DF, p-value: 0.04605
##
##
##
## Covariance matrix of residuals:
## dInflasi dMinyak
## dInflasi 0.1444 -0.2948
## dMinyak -0.2948 31.8715
##
## Correlation matrix of residuals:
## dInflasi dMinyak
## dInflasi 1.0000 -0.1374
## dMinyak -0.1374 1.0000
#implus respon
impresp <- irf(varfit)
plot(impresp)
#dekomposisi ragam
plot(fevd(varfit))
fevd(varfit, n.ahead=20)
## $dInflasi
## dInflasi dMinyak
## [1,] 1.0000000 0.00000000
## [2,] 0.9665622 0.03343776
## [3,] 0.9625390 0.03746099
## [4,] 0.9625057 0.03749427
## [5,] 0.9624112 0.03758879
## [6,] 0.9624108 0.03758922
## [7,] 0.9624086 0.03759144
## [8,] 0.9624083 0.03759168
## [9,] 0.9624083 0.03759169
## [10,] 0.9624083 0.03759170
## [11,] 0.9624083 0.03759170
## [12,] 0.9624083 0.03759170
## [13,] 0.9624083 0.03759170
## [14,] 0.9624083 0.03759170
## [15,] 0.9624083 0.03759170
## [16,] 0.9624083 0.03759170
## [17,] 0.9624083 0.03759170
## [18,] 0.9624083 0.03759170
## [19,] 0.9624083 0.03759170
## [20,] 0.9624083 0.03759170
##
## $dMinyak
## dInflasi dMinyak
## [1,] 0.01887248 0.9811275
## [2,] 0.01882442 0.9811756
## [3,] 0.02094602 0.9790540
## [4,] 0.02150662 0.9784934
## [5,] 0.02150714 0.9784929
## [6,] 0.02151510 0.9784849
## [7,] 0.02151544 0.9784846
## [8,] 0.02151557 0.9784844
## [9,] 0.02151560 0.9784844
## [10,] 0.02151560 0.9784844
## [11,] 0.02151560 0.9784844
## [12,] 0.02151560 0.9784844
## [13,] 0.02151560 0.9784844
## [14,] 0.02151560 0.9784844
## [15,] 0.02151560 0.9784844
## [16,] 0.02151560 0.9784844
## [17,] 0.02151560 0.9784844
## [18,] 0.02151560 0.9784844
## [19,] 0.02151560 0.9784844
## [20,] 0.02151560 0.9784844