0% found this document useful (0 votes)
376 views

Lampiran Syntax R Sarima

This document analyzes time series inflation data from West Java Province using ARIMA and SARIMA models. It tests for stationarity, calculates autocorrelation functions, compares various ARIMA models, compares various SARIMA models with different orders and seasonal periods, analyzes residuals of the best fitting model, and forecasts inflation values. The best fitting SARIMA model is identified and its residuals are further analyzed to check that it meets assumptions of white noise.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
376 views

Lampiran Syntax R Sarima

This document analyzes time series inflation data from West Java Province using ARIMA and SARIMA models. It tests for stationarity, calculates autocorrelation functions, compares various ARIMA models, compares various SARIMA models with different orders and seasonal periods, analyzes residuals of the best fitting model, and forecasts inflation values. The best fitting SARIMA model is identified and its residuals are further analyzed to check that it meets assumptions of white noise.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#PLOT DATA INFLASI PROVINSI JAWA BARAT

#=====================================
mydata<- read.csv("data inflasi2.csv")
myts<- ts(mydata, start=c(2008, 1), end=c(2014, 12), frequency=12)
myts
plot.ts(myts)
myts2<- ts(mydata, start=c(2008, 1), end=c(2013, 12), frequency=12)
myts2

#UJI STASIONER DENGAN ADF


#========================
library(tseries)
adf.test(myts2,k=0)
pp.test(myts2)
#TEST ARFIMA
#============
library(fracdiff)
fdGPH(myts, bandw.exp = 0.5)$d
fdSperio(myts, bandw.exp = 0.5, beta = 0.9)$d

#HITUNG ACF DAN PACF


#===================
library(astsa)
tsdisplay(myts2,main="")
acf2(myts)
acf(myts)
Pacf(myts)
#PERBANDINGAN MODEL ARIMA
#========================
arima(myts2, order = c(1,0,1))
arima(myts2, order = c(2,0,1))
arima(myts2, order = c(1,0,0))
arima(myts2, order = c(0,0,1))
arima(myts2, order = c(2,0,0))
#PERBANDINGAN MODEL SARIMA
#=========================
#SARIMA (1,0,1)(0,0,1)6
#-----------------------#
dog <- sarima(myts2,1,0,1,0,0,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)

#SARIMA (1,0,1)(1,0,1)6
#-----------------------#
dog <- sarima(myts2,1,0,1,1,0,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (1,0,1)(0,1,1)6
#-----------------------#
dog <- sarima(myts2,1,0,1,0,1,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (2,0,1)(0,0,1)6
#-----------------------#
dog <- sarima(myts2,2,0,1,0,0,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (2,0,1)(1,0,1)6
#-----------------------#
dog <- sarima(myts2,2,0,1,1,0,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (2,0,1)(0,1,1)6
#-----------------------#
dog <- sarima(myts2,2,0,1,0,1,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (1,0,0)(0,0,1)6
#-----------------------#
dog <- sarima(myts2,1,0,0,0,0,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (1,0,0)(1,0,1)6
#-----------------------#
dog <- sarima(myts2,1,0,0,1,0,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (1,0,0)(0,1,1)6
#-----------------------#
dog <- sarima(myts2,1,0,0,0,1,1,6)
summary(dog$fit) # fit has all the returned arima() values

plot(resid(dog$fit)) # plot the innovations (residuals)


#SARIMA (0,0,1)(0,0,1)6
#-----------------------#
dog <- sarima(myts2,0,0,1,0,0,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (0,0,1)(1,0,1)6
#-----------------------#
dog <- sarima(myts2,0,0,1,1,0,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (0,0,1)(0,1,1)6
#-----------------------#
dog <- sarima(myts2,0,0,1,0,1,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (2,0,0)(0,0,1)6
#-----------------------#
dog <- sarima(myts2,2,0,0,0,0,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (2,0,0)(1,0,1)6
#-----------------------#
dog <- sarima(myts2,2,0,0,1,0,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (2,0,0)(1,0,0)6
#-----------------------#
dog <- sarima(myts2,2,0,0,1,0,0,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#SARIMA (2,0,0)(0,1,1)6
#-----------------------#
dog <- sarima(myts2,2,0,0,0,1,1,6)
summary(dog$fit) # fit has all the returned arima() values
plot(resid(dog$fit)) # plot the innovations (residuals)
#FORECASTING ARIMA
#=================

dog <- sarima(myts2,0,0,1,0,1,1,6)


summary(dog$fit) # fit has all the returned arima() values
f<-sarima.for(myts2, 12, 0, 0, 1, P = 0, D = 1, Q = 1, S = 6)
f$pred[1:12]
myts[73:84]
##########################
errorC4<-myts[73:84]-f$pred[1:12] ##################
MSE=(sum(errorC4^2))/12
################## 25%
MAPE =((sum(abs(errorC4)/myts[73:84]))/12)*100#########
MSE
MAPE
dog <- sarima(myts2,0,0,1,1,0,1,6)
summary(dog$fit) # fit has all the returned arima() values
f<-sarima.for(myts2, 12, 0, 0, 1, P = 1, D = 0, Q = 1, S = 6)
f$pred[1:12]
myts[73:84]
##########################
errorC4<-myts[73:84]-f$pred[1:12] ##################
MSE=(sum(errorC4^2))/12
################## 25%
MAPE =((sum(abs(errorC4)/myts[73:84]))/12)*100#########
MSE
MAPE
modelfit<-dog$fit
res <- residuals(modelfit)
res
win.graph(width=3,height=3,pointsize=8)
qqnorm(res)
qqline(res)
#QQ Plot
shapiro.test(res) #Shapiro_Wilk
#Uji Serial Korelasi untuk white noise residual (Box pierce)
Box.test(res,6,"Ljung-Box")
Box.test(res,12,"Ljung-Box")
Box.test(res,18,"Ljung-Box")
Box.test(res,24,"Ljung-Box")
Box.test(res,30,"Ljung-Box")
Box.test(res,36,"Ljung-Box")
#Efek heteroskedastisitas Lagrange Multiplier
plot(res,main="residual")
ArchTest (res, lags=12, demean = FALSE)

You might also like