You are on page 1of 33

####### DATA GNP

gnp = read.table('gnp96.dat')
gnp.ts = ts(gnp[,2], frequency = 4, start = 1947)

##(1)## PLOT DATA


plot(gnp.ts)
acf(gnp.ts)

##(2)## TRANSFORMASI DATA


plot(diff(gnp.ts))
##increasing variance with time (suggest log- or square root transformation)
##difference of log has nice interpretation (=growth rate)
plot(diff(log(gnp.ts)))

##STASIONERITAS
gnp.gr = diff(log(gnp.ts))

##(3)## IDENTIFIKASI P DAN Q


par(mfrow = c(2,1))
acf(gnp.gr)
pacf(gnp.gr)
par(mfrow = c(1,1))

## ACF DAN PACF TIDAK BAGUS UNTUK DIBANDINGKAN


par(mfrow=c(2,1))
acf(gnp.gr,12,xlim=c(1/4,3), ylim=c(-.2,0.5), xlab="Lag = years",
main="ACF(diff(log(GNP)))")

##AXIS
pacf(gnp.gr,12,ylim=c(-.2,0.5), xlab="Lag = years",
main="PACF(diff(log(GNP)))")
par(mfrow=c(1,1))

##Kemungkinan: - ACF: cuts of after 2nd lag, PACF declines exponentially [ARMA(0,2)]
## - PACF cuts off after 1st lag, ACF declines exponentially [ARMA(1,0)]
## - both ACF and PACF decline exponentially [for example ARMA(1,1)]

## ESTIMASI
gnp.gr.AR = arima(gnp.gr, order = c(1,0,0))
gnp.gr.AR
gnp.gr.AR2 = ar.ols(gnp.gr, order = 1)
gnp.gr.AR2
gnp.gr.AR3 = ar.yw(gnp.gr, order = 1)
gnp.gr.AR3
gnp.gr.AR4 = ar.mle(gnp.gr, order = 1)
gnp.gr.AR4

gnp.gr.MA = arima(gnp.gr, order = c(0,0,2))


gnp.gr.MA
##ROBUSTNESS CHECK
gnp.gr.MA2 = arima(gnp.gr, order = c(0,0,2), method = "CSS")
gnp.gr.MA2

gnp.gr.ARMA = arima(gnp.gr, order = c(1,0,1))


gnp.gr.ARMA

## DIAGNOSTICS
plot(gnp.gr.AR$resid)
par(mfrow = c(2,1))
hist(gnp.gr.AR$resid)
qqnorm(gnp.gr.AR$resid)
par(mfrow = c(1,1))
shapiro.test(gnp.gr.AR$resid)

##R-COMMAND UNTUK CEK DIAGNOSTIC


tsdiag(gnp.gr.MA)

##AUTOKORELASI RESIDUAL

plot(gnp.gr.MA$resid)
par(mfrow = c(2,1))
hist(gnp.gr.MA$resid)
qqnorm(gnp.gr.AR$resid)
par(mfrow = c(1,1))
shapiro.test(gnp.gr.MA$resid)

## R-COMMAND UNTUK CEK DIAGNOSTIC


tsdiag(gnp.gr.MA)

## SELEKSI MODEL
N = length(gnp.gr.AR$resid)

##BANDINGKAN NILAI AIC


gnp.gr.AR$aic
gnp.gr.MA$aic
gnp.gr.ARMA$aic

##BANDINGKAN NILAI AICC


log(gnp.gr.AR$sigma2)+(N+1)/(N-1-2)
log(gnp.gr.MA$sigma2)+(N+2)/(N-2-2)

##BANDINGKAN NILAI SIC


log(gnp.gr.AR$sigma2)+(1*log(N))/N
log(gnp.gr.MA$sigma2)+(2*log(N))/N
#SYNTAX PAS PRAKTIKUM

####### DATA GNP

gnp = read.table('gnp96.dat')

gnp.ts = ts(gnp[,2], frequency = 4, start = 1947)

##(1)## PLOT DATA

plot(gnp.ts)

acf(gnp.ts)

library(forecast)

BoxCox.lambda(gnp.ts,upper=0)

[1] -0.9999339

#boxcox harus sama dengan 1 biar stabil

DT=BoxCox(gnp.ts,BoxCox.lambda(gnp.ts,upper=0))

DT1=log(gnp.ts)

#timeseris harus stationer dlm rata2 dan variasn: varians dulu baru rata2

##(2)## TRANSFORMASI DATA

plot(diff(gnp.ts))

##increasing variance with time (suggest log- or square root transformation)

##difference of log has nice interpretation (=growth rate)

plot(diff(log(gnp.ts)))

##STASIONERITAS

gnp.gr = diff(log(gnp.ts))

##(3)## IDENTIFIKASI P DAN Q


par(mfrow = c(2,1))

acf(gnp.gr)

pacf(gnp.gr)

par(mfrow = c(1,1))

## ACF DAN PACF TIDAK BAGUS UNTUK DIBANDINGKAN

par(mfrow=c(2,1))

acf(DT1,12,xlim=c(1/4,3), ylim=c(-.2,0.5), xlab="Lag = years",


main="ACF(diff(log(GNP)))")

##AXIS

pacf(DT1,12,ylim=c(-.2,0.5), xlab="Lag = years", main="PACF(diff(log(GNP)))")

par(mfrow=c(1,1))

##Kemungkinan: - ACF: cuts of after 2nd lag, PACF declines exponentially


[ARMA(0,2)]

## - PACF cuts off after 1st lag, ACF declines exponentially


[ARMA(1,0)]

## - both ACF and PACF decline exponentially [for example


ARMA(1,1)]

## ESTIMASI

gnp.gr.AR = arima(DT1, order = c(1,0,0))

gnp.gr.AR

gnp.gr.AR2 = ar.ols(gnp.gr, order = 1)

gnp.gr.AR2

gnp.gr.AR3 = ar.yw(gnp.gr, order = 1) #yule wall

gnp.gr.AR3

gnp.gr.AR4 = ar.mle(gnp.gr, order = 1)


gnp.gr.AR4

gnp.gr.MA = arima(DT1, order = c(0,0,2))

gnp.gr.MA

##ROBUSTNESS CHECK

gnp.gr.MA2 = arima(gnp.gr, order = c(0,0,2), method = "CSS")

gnp.gr.MA2

gnp.gr.ARMA = arima(gnp.gr, order = c(1,0,1))

gnp.gr.ARMA

## DIAGNOSTICS

plot(DT1.AR$resid)

par(mfrow = c(2,1))

hist(gnp.gr.AR$resid)

qqnorm(gnp.gr.AR$resid)

par(mfrow = c(1,1))

shapiro.test(gnp.gr.AR$resid)

##R-COMMAND UNTUK CEK DIAGNOSTIC

tsdiag(gnp.gr.MA)

##AUTOKORELASI RESIDUAL
plot(gnp.gr.MA$resid)

par(mfrow = c(2,1))

hist(gnp.gr.MA$resid)

qqnorm(gnp.gr.AR$resid)

par(mfrow = c(1,1))

shapiro.test(gnp.gr.MA$resid)

## R-COMMAND UNTUK CEK DIAGNOSTIC

tsdiag(gnp.gr.MA)

## SELEKSI MODEL

N = length(DT1$resid)

##BANDINGKAN NILAI AIC

DT1.AR$aic

DT1$aic

DT1MA$aic

##BANDINGKAN NILAI AICC

log(gnp.gr.AR$sigma2)+(N+1)/(N-1-2)

log(gnp.gr.MA$sigma2)+(N+2)/(N-2-2)

##BANDINGKAN NILAI SIC

log(gnp.gr.AR$sigma2)+(1*log(N))/N

log(gnp.gr.MA$sigma2)+(2*log(N))/N
output r

> GNP=read.table("E:tour.text")

Error in file(file, "rt") : cannot open the connection

In addition: Warning message:

In file(file, "rt") : cannot open file 'E:tour.text': Permission denied

> GNP=read.table("E:tour.txt")

Error in file(file, "rt") : cannot open the connection

In addition: Warning message:

In file(file, "rt") : cannot open file 'E:tour.txt': Permission denied

> GNP=read.table("E:tour.txt")

Error in file(file, "rt") : cannot open the connection

In addition: Warning message:

In file(file, "rt") : cannot open file 'E:tour.txt': Permission denied

> GNP=read.table("D:tour.txt")

> GNP

V1

1 2565289

2 2443603

3 3400808

4 3107737

5 3243037

6 3147353

7 4278520

8 4255329

9 3503282

10 3530139
11 2786362

12 3034125

13 2689328

14 2618174

15 3670249

16 3325419

17 3568482

18 3517073

19 4832796

20 4851935

21 3740513

22 3470398

23 2901506

24 3026328

25 2824423

26 2632421

27 3333021

28 3516849

29 3531727

30 3276059

31 4454271

32 4314430

33 3432739

34 3329209

35 2773192

36 3072958

37 2662506

38 2616495
39 3503346

40 3356722

41 3607195

42 3447131

43 4764381

44 4607091

45 3796606

46 3672352

47 3123702

48 2993308

49 2863913

50 2945797

51 3706650

52 4095762

53 3701004

54 3590225

55 4945166

56 4645940

57 3870719

58 3648532

59 3198909

60 3395933

61 3033546

62 2864022

63 3584633

64 3869685

65 3509407

66 3481220
67 4742157

68 4639969

69 2608006

70 2237335

71 2095665

72 2501658

73 2236118

74 2245127

75 3266150

76 2804249

77 2991154

78 2934672

79 3973737

80 3969950

81 3106540

82 2902652

83 2532041

84 2968221

85 2357402

86 2199181

87 2603060

88 2629720

89 2638792

90 2717481

91 3810804

92 3871664

93 2998364

94 2923432
95 2712359

96 2996099

97 2395029

98 2483862

99 3120231

100 3360606

101 3177203

102 3062783

103 4242509

104 4026394

105 3192481

106 3118695

107 2782482

108 3209833

109 2630190

110 2592882

111 3785309

112 3231539

113 3421369

114 3312134

115 4647303

116 4289177

117 3463853

118 3304422

119 3006121

120 3464238

121 2921118

122 2624018
123 3500718

124 3939351

125 3467672

126 3343628

127 4852445

128 4597807

129 3653145

130 3572079

131 3334861

132 3695369

133 3075704

134 2852998

135 3942704

136 4004560

137 3822145

138 3760085

139 5267816

140 5271333

141 4144142

142 4109749

143 3896808

144 4211074

145 3401064

146 3278560

147 4705090

148 4081128

149 4345931

150 4049690
> gnp.ts = ts(gnp[,2], frequency = 4, start = 1947)

Error in is.data.frame(data) : object 'gnp' not found

> gnp.ts = ts(GNP[,2], frequency = 4, start = 1947)

Error in `[.data.frame`(GNP, , 2) : undefined columns selected

> gnp.ts = ts(GNP, frequency = 4, start = 1947)

> gnp.ts

Qtr1 Qtr2 Qtr3 Qtr4

1947 2565289 2443603 3400808 3107737

1948 3243037 3147353 4278520 4255329

1949 3503282 3530139 2786362 3034125

1950 2689328 2618174 3670249 3325419

1951 3568482 3517073 4832796 4851935

1952 3740513 3470398 2901506 3026328

1953 2824423 2632421 3333021 3516849

1954 3531727 3276059 4454271 4314430

1955 3432739 3329209 2773192 3072958

1956 2662506 2616495 3503346 3356722

1957 3607195 3447131 4764381 4607091

1958 3796606 3672352 3123702 2993308

1959 2863913 2945797 3706650 4095762

1960 3701004 3590225 4945166 4645940

1961 3870719 3648532 3198909 3395933

1962 3033546 2864022 3584633 3869685

1963 3509407 3481220 4742157 4639969

1964 2608006 2237335 2095665 2501658

1965 2236118 2245127 3266150 2804249

1966 2991154 2934672 3973737 3969950

1967 3106540 2902652 2532041 2968221


1968 2357402 2199181 2603060 2629720

1969 2638792 2717481 3810804 3871664

1970 2998364 2923432 2712359 2996099

1971 2395029 2483862 3120231 3360606

1972 3177203 3062783 4242509 4026394

1973 3192481 3118695 2782482 3209833

1974 2630190 2592882 3785309 3231539

1975 3421369 3312134 4647303 4289177

1976 3463853 3304422 3006121 3464238

1977 2921118 2624018 3500718 3939351

1978 3467672 3343628 4852445 4597807

1979 3653145 3572079 3334861 3695369

1980 3075704 2852998 3942704 4004560

1981 3822145 3760085 5267816 5271333

1982 4144142 4109749 3896808 4211074

1983 3401064 3278560 4705090 4081128

1984 4345931 4049690

> ##(1)## PLOT DATA

> plot(gnp.ts)

> acf(gnp.ts)

> plot(gnp.ts)

> acf(gnp.ts)

> boxplot(gnp)

Error in boxplot(gnp) : object 'gnp' not found

> boxplot(GNP)

> BoxCox.lambda(gnp.ts,upper=0)

Error: could not find function "BoxCox.lambda"

> library(forecast)
Error in library(forecast) : there is no package called ‘forecast’

> local({pkg <- select.list(sort(.packages(all.available =


TRUE)),graphics=TRUE)

+ if(nchar(pkg)) library(pkg, character.only=TRUE)})

> utils:::menuInstallPkgs()

--- Please select a CRAN mirror for use in this session ---

also installing the dependencies ‘stringi’, ‘xts’, ‘TTR’, ‘curl’, ‘stringr’,


‘RColorBrewer’, ‘dichromat’, ‘munsell’, ‘labeling’, ‘R6’, ‘viridisLite’,
‘rlang’, ‘quadprog’, ‘quantmod’, ‘digest’, ‘gtable’, ‘plyr’, ‘reshape2’,
‘scales’, ‘tibble’, ‘lazyeval’, ‘tseries’, ‘fracdiff’, ‘Rcpp’, ‘colorspace’,
‘ggplot2’, ‘magrittr’, ‘lmtest’, ‘zoo’, ‘timeDate’, ‘RcppArmadillo’

There is a binary version available but the source version is later:

binary source needs_compilation

stringi 1.1.5 1.1.6 TRUE

Do you want to install from sources the package which needs compilation?

y/n: y

trying URL 'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/xts_0.10-


0.zip'

Content type 'application/zip' length 732081 bytes (714 KB)

downloaded 714 KB

trying URL 'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/TTR_0.23-


2.zip'

Content type 'application/zip' length 444026 bytes (433 KB)

downloaded 433 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/curl_3.0.zip'

Content type 'application/zip' length 3342852 bytes (3.2 MB)


downloaded 3.2 MB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/stringr_1.2.0.zip'

Content type 'application/zip' length 148993 bytes (145 KB)

downloaded 145 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/RColorBrewer_1.1-2.zip'

Content type 'application/zip' length 26706 bytes (26 KB)

downloaded 26 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/dichromat_2.0-0.zip'

Content type 'application/zip' length 147728 bytes (144 KB)

downloaded 144 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/munsell_0.4.3.zip'

Content type 'application/zip' length 134249 bytes (131 KB)

downloaded 131 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/labeling_0.3.zip'

Content type 'application/zip' length 40914 bytes (39 KB)

downloaded 39 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/R6_2.2.2.zip'

Content type 'application/zip' length 316508 bytes (309 KB)

downloaded 309 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/viridisLite_0.2.0.zip'

Content type 'application/zip' length 57586 bytes (56 KB)

downloaded 56 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/rlang_0.1.4.zip'

Content type 'application/zip' length 465802 bytes (454 KB)

downloaded 454 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/quadprog_1.5-5.zip'

Content type 'application/zip' length 52461 bytes (51 KB)

downloaded 51 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/quantmod_0.4-11.zip'

Content type 'application/zip' length 485276 bytes (473 KB)

downloaded 473 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/digest_0.6.12.zip'

Content type 'application/zip' length 172734 bytes (168 KB)

downloaded 168 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/gtable_0.2.0.zip'

Content type 'application/zip' length 57667 bytes (56 KB)

downloaded 56 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/plyr_1.8.4.zip'

Content type 'application/zip' length 1220023 bytes (1.2 MB)

downloaded 1.2 MB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/reshape2_1.4.2.zip'

Content type 'application/zip' length 609528 bytes (595 KB)

downloaded 595 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/scales_0.5.0.zip'

Content type 'application/zip' length 696229 bytes (679 KB)

downloaded 679 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/tibble_1.3.4.zip'

Content type 'application/zip' length 676197 bytes (660 KB)

downloaded 660 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/lazyeval_0.2.1.zip'

Content type 'application/zip' length 140033 bytes (136 KB)

downloaded 136 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/tseries_0.10-42.zip'

Content type 'application/zip' length 326940 bytes (319 KB)

downloaded 319 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/fracdiff_1.4-2.zip'

Content type 'application/zip' length 107451 bytes (104 KB)

downloaded 104 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/Rcpp_0.12.13.zip'

Content type 'application/zip' length 4340885 bytes (4.1 MB)

downloaded 4.1 MB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/colorspace_1.3-2.zip'

Content type 'application/zip' length 442186 bytes (431 KB)

downloaded 431 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/ggplot2_2.2.1.zip'

Content type 'application/zip' length 2760948 bytes (2.6 MB)

downloaded 2.6 MB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/magrittr_1.5.zip'

Content type 'application/zip' length 149783 bytes (146 KB)

downloaded 146 KB

trying URL 'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/lmtest_0.9-


35.zip'

Content type 'application/zip' length 288912 bytes (282 KB)

downloaded 282 KB
trying URL 'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/zoo_1.8-
0.zip'

Content type 'application/zip' length 902405 bytes (881 KB)

downloaded 881 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/timeDate_3042.101.zip'

Content type 'application/zip' length 790902 bytes (772 KB)

downloaded 772 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/RcppArmadillo_0.8.100.1
.0.zip'

Content type 'application/zip' length 2221315 bytes (2.1 MB)

downloaded 2.1 MB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/forecast_8.2.zip'

Content type 'application/zip' length 2076481 bytes (2.0 MB)

downloaded 2.0 MB

package ‘xts’ successfully unpacked and MD5 sums checked

package ‘TTR’ successfully unpacked and MD5 sums checked

package ‘curl’ successfully unpacked and MD5 sums checked

package ‘stringr’ successfully unpacked and MD5 sums checked

package ‘RColorBrewer’ successfully unpacked and MD5 sums checked

package ‘dichromat’ successfully unpacked and MD5 sums checked

package ‘munsell’ successfully unpacked and MD5 sums checked

package ‘labeling’ successfully unpacked and MD5 sums checked

package ‘R6’ successfully unpacked and MD5 sums checked


package ‘viridisLite’ successfully unpacked and MD5 sums checked

package ‘rlang’ successfully unpacked and MD5 sums checked

package ‘quadprog’ successfully unpacked and MD5 sums checked

package ‘quantmod’ successfully unpacked and MD5 sums checked

package ‘digest’ successfully unpacked and MD5 sums checked

package ‘gtable’ successfully unpacked and MD5 sums checked

package ‘plyr’ successfully unpacked and MD5 sums checked

package ‘reshape2’ successfully unpacked and MD5 sums checked

package ‘scales’ successfully unpacked and MD5 sums checked

package ‘tibble’ successfully unpacked and MD5 sums checked

package ‘lazyeval’ successfully unpacked and MD5 sums checked

package ‘tseries’ successfully unpacked and MD5 sums checked

package ‘fracdiff’ successfully unpacked and MD5 sums checked

package ‘Rcpp’ successfully unpacked and MD5 sums checked

package ‘colorspace’ successfully unpacked and MD5 sums checked

package ‘ggplot2’ successfully unpacked and MD5 sums checked

package ‘magrittr’ successfully unpacked and MD5 sums checked

package ‘lmtest’ successfully unpacked and MD5 sums checked

package ‘zoo’ successfully unpacked and MD5 sums checked

package ‘timeDate’ successfully unpacked and MD5 sums checked

package ‘RcppArmadillo’ successfully unpacked and MD5 sums checked

package ‘forecast’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in

C:\Users\User\AppData\Local\Temp\RtmpYFKmot\downloaded_packages

installing the source package ‘stringi’

trying URL 'https://repo.bppt.go.id/cran/src/contrib/stringi_1.1.6.tar.gz'


Content type 'application/x-gzip' length 3647049 bytes (3.5 MB)

downloaded 3.5 MB

* installing *source* package 'stringi' ...

** package 'stringi' successfully unpacked and MD5 sums checked

Warning: running command 'sh ./configure.win' had status 127

ERROR: configuration failed for package 'stringi'

* removing 'C:/Users/User/Documents/R/win-library/3.3/stringi'

The downloaded source packages are in

‘C:\Users\User\AppData\Local\Temp\RtmpYFKmot\downloaded_packages’

Warning messages:

1: running command '"C:/PROGRA~1/R/R-33~1.1/bin/i386/R" CMD INSTALL -l


"C:\Users\User\Documents\R\win-library\3.3"
C:\Users\User\AppData\Local\Temp\RtmpYFKmot/downloaded_packages/stringi_1.1.6
.tar.gz' had status 1

2: In install.packages(NULL, .libPaths()[1L], dependencies = NA, type = type)


:

installation of package ‘stringi’ had non-zero exit status

> BoxCox.lambda(gnp.ts,upper=0)

Error: could not find function "BoxCox.lambda"

> BoxCox.lambda(gnp.ts,upper=0)

Error: could not find function "BoxCox.lambda"

> BoxCox.lambda(gnp.ts,upper=0)

Error: could not find function "BoxCox.lambda"

> library(forecast)

Warning message:

package ‘forecast’ was built under R version 3.3.3

> BoxCox.lambda(gnp.ts,upper=0)

[1] -0.9999339
> #boxcox harus sama DT=BoxCox(gnp.ts,BoxCox.lambda(gnp.ts,upper=0)dengan 1
biar stabil

> DT=BoxCox(gnp.ts,BoxCox.lambda(gnp.ts,upper=0)

+ )

> DT

Qtr1 Qtr2 Qtr3 Qtr4

1947 1.000066 1.000066 1.000066 1.000066

1948 1.000066 1.000066 1.000066 1.000066

1949 1.000066 1.000066 1.000066 1.000066

1950 1.000066 1.000066 1.000066 1.000066

1951 1.000066 1.000066 1.000066 1.000066

1952 1.000066 1.000066 1.000066 1.000066

1953 1.000066 1.000066 1.000066 1.000066

1954 1.000066 1.000066 1.000066 1.000066

1955 1.000066 1.000066 1.000066 1.000066

1956 1.000066 1.000066 1.000066 1.000066

1957 1.000066 1.000066 1.000066 1.000066

1958 1.000066 1.000066 1.000066 1.000066

1959 1.000066 1.000066 1.000066 1.000066

1960 1.000066 1.000066 1.000066 1.000066

1961 1.000066 1.000066 1.000066 1.000066

1962 1.000066 1.000066 1.000066 1.000066

1963 1.000066 1.000066 1.000066 1.000066

1964 1.000066 1.000066 1.000066 1.000066

1965 1.000066 1.000066 1.000066 1.000066

1966 1.000066 1.000066 1.000066 1.000066

1967 1.000066 1.000066 1.000066 1.000066

1968 1.000066 1.000066 1.000066 1.000066

1969 1.000066 1.000066 1.000066 1.000066


1970 1.000066 1.000066 1.000066 1.000066

1971 1.000066 1.000066 1.000066 1.000066

1972 1.000066 1.000066 1.000066 1.000066

1973 1.000066 1.000066 1.000066 1.000066

1974 1.000066 1.000066 1.000066 1.000066

1975 1.000066 1.000066 1.000066 1.000066

1976 1.000066 1.000066 1.000066 1.000066

1977 1.000066 1.000066 1.000066 1.000066

1978 1.000066 1.000066 1.000066 1.000066

1979 1.000066 1.000066 1.000066 1.000066

1980 1.000066 1.000066 1.000066 1.000066

1981 1.000066 1.000066 1.000066 1.000066

1982 1.000066 1.000066 1.000066 1.000066

1983 1.000066 1.000066 1.000066 1.000066

1984 1.000066 1.000066

> DT1=log(gnp.ts)

> DT1

Qtr1 Qtr2 Qtr3 Qtr4

1947 14.75758 14.70898 15.03952 14.94941

1948 14.99202 14.96207 15.26912 15.26368

1949 15.06921 15.07685 14.84025 14.92543

1950 14.80480 14.77799 15.11577 15.01711

1951 15.08765 15.07314 15.39094 15.39489

1952 15.13473 15.05978 14.88074 14.92286

1953 14.85381 14.78341 15.01939 15.07308

1954 15.07730 15.00215 15.30937 15.27748

1955 15.04887 15.01825 14.83551 14.93815

1956 14.79478 14.77735 15.06923 15.02648


1957 15.09844 15.05305 15.37668 15.34311

1958 15.14962 15.11634 14.95453 14.91189

1959 14.86770 14.89589 15.12564 15.22546

1960 15.12411 15.09373 15.41392 15.35150

1961 15.16895 15.10984 14.97832 15.03809

1962 14.92524 14.86774 15.09217 15.16868

1963 15.07096 15.06289 15.37200 15.35022

1964 14.77410 14.62080 14.55538 14.73246

1965 14.62025 14.62427 14.99912 14.84665

1966 14.91117 14.89211 15.19522 15.19426

1967 14.94902 14.88114 14.74454 14.90347

1968 14.67307 14.60360 14.77220 14.78239

1969 14.78583 14.81522 15.15335 15.16919

1970 14.91358 14.88827 14.81333 14.91282

1971 14.68891 14.72533 14.95342 15.02763

1972 14.97151 14.93483 15.26067 15.20838

1973 14.97631 14.95293 14.83885 14.98173

1974 14.78257 14.76828 15.14664 14.98847

1975 15.04555 15.01310 15.35180 15.27161

1976 15.05789 15.01077 14.91616 15.05800

1977 14.88748 14.78022 15.06848 15.18653

1978 15.05899 15.02257 15.39499 15.34109

1979 15.11110 15.08866 15.01994 15.12259

1980 14.93904 14.86388 15.18738 15.20294

1981 15.15632 15.13995 15.47713 15.47779

1982 15.23721 15.22887 15.17567 15.25323

1983 15.03960 15.00291 15.36416 15.22188

1984 15.28475 15.21415


> ts.plot(DT1)

> #sebelum diferencing

> library(TSA)

Error in library(TSA) : there is no package called ‘TSA’

> install.packages("TSA")

Installing package into ‘C:/Users/User/Documents/R/win-library/3.3’

(as ‘lib’ is unspecified)

also installing the dependencies ‘leaps’, ‘locfit’

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/leaps_3.0.zip'

Content type 'application/zip' length 328459 bytes (320 KB)

downloaded 320 KB

trying URL 'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/locfit_1.5-


9.1.zip'

Content type 'application/zip' length 595544 bytes (581 KB)

downloaded 581 KB

trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/TSA_1.01.zip'

Content type 'application/zip' length 371751 bytes (363 KB)

downloaded 363 KB

package ‘leaps’ successfully unpacked and MD5 sums checked

package ‘locfit’ successfully unpacked and MD5 sums checked

package ‘TSA’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in


C:\Users\User\AppData\Local\Temp\RtmpYFKmot\downloaded_packages

> library(TSA)

Loading required package: leaps

Loading required package: locfit

locfit 1.5-9.1 2013-03-22

Loading required package: mgcv

Loading required package: nlme

Attaching package: ‘nlme’

The following object is masked from ‘package:forecast’:

getResponse

This is mgcv 1.8-12. For overview type 'help("mgcv-package")'.

Loading required package: tseries

‘tseries’ version: 0.10-42

‘tseries’ is a package for time series analysis and computational

finance.

See ‘library(help="tseries")’ for details.

Attaching package: ‘TSA’

The following objects are masked from ‘package:stats’:


acf, arima

The following object is masked from ‘package:utils’:

tar

Warning messages:

1: package ‘TSA’ was built under R version 3.3.3

2: package ‘leaps’ was built under R version 3.3.3

3: package ‘locfit’ was built under R version 3.3.3

4: package ‘tseries’ was built under R version 3.3.3

> adf.test(DT1) #STATIONER RT2

Augmented Dickey-Fuller Test

data: DT1

Dickey-Fuller = -7.0132, Lag order = 5, p-value = 0.01

alternative hypothesis: stationary

Warning message:

In adf.test(DT1) : p-value smaller than printed p-value

> #h1:STATIONER

> #tidak usah di diferencing

> #apakah pelu menstabilkan bvariasn

> #hitung pake boxcox lambda

> #hitung pake boxcox lambda : yg tadi DT1

> #3
> boxplot(gnp.ts ~ cycle(gnp.ts))

> #siklus/frekuensi nya 4 = per tiga bulanan

> #asumsi tidak ada outlier, dari boxplot dilihat bahwa pada quarter pertama
stabil, dsl.

> #kemungkinan quarter 1 dan 4 normal, 2 dan 3 tidak normal

> #4

> par(mfrow=c(2,1)), acf(gnp.ts), pacf(gnp.ts)par(mfrow = c(2,1))

Error: unexpected ',' in "par(mfrow=c(2,1)),"

> par(mfrow=c(2,1)), acf(gnp.ts), pacf(gnp.ts)

Error: unexpected ',' in "par(mfrow=c(2,1)),"

> par(mfrow = c(2,1))

> par(mfrow = c(2,1))

> acf(gnp.gr)

Error in as.ts(x) : object 'gnp.gr' not found

> pacf(gnp.gr)

Error in pacf(gnp.gr) : object 'gnp.gr' not found

> par(mfrow = c(1,1))

> #gunakan data pake DT1

> acf(DT1)

> pacf(DT1)

> #ACF BUAT MA, pacf buat

> acf(DT1)

> #ACF ada orde seasonal buat MA, orde seasonal = 5.

> pacf(DT1)

> ## ACF DAN PACF TIDAK BAGUS UNTUK DIBANDINGKAN

> par(mfrow=c(2,1))

> acf(DT1,12,xlim=c(1/4,3), ylim=c(-.2,0.5), xlab="Lag = years",


main="ACF(diff(log(GNP)))")

Error in plot.default(y = x$acf, x = x$lag, type = type, xlab = xlab, :


formal argument "ylim" matched by multiple actual arguments

> ##AXIS

> pacf(gnp.gr,12,ylim=c(-.2,0.5), xlab="Lag = years",


main="PACF(diff(log(GNP)))")

Error in pacf(gnp.gr, 12, ylim = c(-0.2, 0.5), xlab = "Lag = years", main =
"PACF(diff(log(GNP)))") :

object 'gnp.gr' not found

> par(mfrow=c(1,1))

> ##AXIS

> pacf(DT1,12,ylim=c(-.2,0.5), xlab="Lag = years",


main="PACF(diff(log(GNP)))")

> par(mfrow=c(1,1))

> plot(DT1,ylim(0,100)

+ )

Error in plotts(x = x, y = y, plot.type = plot.type, xy.labels = xy.labels,


:

could not find function "ylim"

> plot(DT1,ylim=c(0,100)

+ )

> DDT=diff(DT1,1)

> DDT

Qtr1 Qtr2 Qtr3 Qtr4

1947 -0.0485975534 0.3305394610 -0.0901182419

1948 0.0426154279 -0.0299484543 0.3070453733 -0.0054350756

1949 -0.1944718364 0.0076370035 -0.2366004446 0.0851862775

1950 -0.1206317315 -0.0268142201 0.3377823789 -0.0986638260

1951 0.0705446141 -0.0145111857 0.3177960726 0.0039524123

1952 -0.2601548267 -0.0749534830 -0.1790393722 0.0421200909

1953 -0.0690459075 -0.0704001409 0.2359751449 0.0536863183

1954 0.0042215682 -0.0751458108 0.3072222356 -0.0318981927


1955 -0.2286067337 -0.0306237465 -0.1827357349 0.1026416123

1956 -0.1433728311 -0.0174321487 0.2918828759 -0.0427536093

1957 0.0719655595 -0.0453881711 0.3236253322 -0.0335709848

1958 -0.1934891286 -0.0332751810 -0.1618134918 -0.0426397065

1959 -0.0441902588 0.0281905371 0.2297490951 0.0998242768

1960 -0.1013486464 -0.0303892596 0.3201956591 -0.0624168138

1961 -0.1825534420 -0.0591153830 -0.1315150807 0.0597687250

1962 -0.1128463069 -0.0575053017 0.2244291672 0.0765170106

1963 -0.0977260310 -0.0080642703 0.3091092884 -0.0217844103

1964 -0.5761217405 -0.1533005192 -0.0654145000 0.1770827866

1965 -0.1122123853 0.0040207630 0.3748498315 -0.1524761543

1966 0.0645234992 -0.0190635738 0.3031112694 -0.0009534616

1967 -0.2452439335 -0.0678847648 -0.1365991050 0.1589370866

1968 -0.2304026182 -0.0694751469 0.1686026577 0.0101897006

1969 0.0034438600 0.0293841116 0.3381348422 0.0158441983

1970 -0.2556175822 -0.0253085380 -0.0749395326 0.0994923732

1971 -0.2239157698 0.0364192676 0.2280924306 0.0742142773

1972 -0.0561200649 -0.0366772702 0.3258308597 -0.0522836532

1973 -0.2320728289 -0.0233837124 -0.1140713099 0.1428755757

1974 -0.1991628239 -0.0142860885 0.3783575232 -0.1581690273

1975 0.0570822690 -0.0324480687 0.3386943567 -0.0801921783

1976 -0.2137133197 -0.0471199818 -0.0946110281 0.1418421517

1977 -0.1705262753 -0.1072596889 0.2882613595 0.1180478986

1978 -0.1275325135 -0.0364270304 0.3724262566 -0.0539032509

1979 -0.2299910103 -0.0224406612 -0.0687167799 0.1026494148

1980 -0.1835465960 -0.0751634469 0.3234964111 0.0155669295

1981 -0.0466219285 -0.0163702198 0.3371742919 0.0006674163

1982 -0.2405875010 -0.0083338147 -0.0532041996 0.0775599656


1983 -0.2136293982 -0.0366840222 0.3612405998 -0.1422714806

1984 0.0628665842 -0.0705996701

> plot(DDT,type="l")

> #ARma(p=1,q=0)

> ## ESTIMASI

> gnp.gr.AR = arima(DT1, order = c(1,0,0))

> gnp.gr.AR

Call:

arima(x = DT1, order = c(1, 0, 0))

Coefficients:

ar1 intercept

0.6311 15.0253

s.e. 0.0635 0.0337

sigma^2 estimated as 0.02367: log likelihood = 67.66, aic = -131.32

> gnp.gr.MA = arima(DT1, order = c(0,0,2))

> gnp.gr.MA

Call:

arima(x = DT1, order = c(0, 0, 2))

Coefficients:

ma1 ma2 intercept

0.7091 0.3708 15.0262

s.e. 0.0811 0.1162 0.0261


sigma^2 estimated as 0.02383: log likelihood = 67.11, aic = -128.22

> ##R-COMMAND UNTUK CEK DIAGNOSTIC

> tsdiag(gnp.gr.MA)

> ## SELEKSI MODEL

> N = length(DT1$resid)

Error in DT1$resid : $ operator is invalid for atomic vectors

>

> ##BANDINGKAN NILAI AIC

> DT1.AR$aic

Error: object 'DT1.AR' not found

> DT1$aic

Error in DT1$aic : $ operator is invalid for atomic vectors

> DT1MA$aic

Error: object 'DT1MA' not found

> ## DIAGNOSTICS

> plot(DT1.AR$resid)

Error in plot(DT1.AR$resid) : object 'DT1.AR' not found

>

You might also like