Professional Documents
Culture Documents
gnp = read.table('gnp96.dat')
gnp.ts = ts(gnp[,2], frequency = 4, start = 1947)
##STASIONERITAS
gnp.gr = diff(log(gnp.ts))
##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
## 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)
##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)
## SELEKSI MODEL
N = length(gnp.gr.AR$resid)
gnp = read.table('gnp96.dat')
plot(gnp.ts)
acf(gnp.ts)
library(forecast)
BoxCox.lambda(gnp.ts,upper=0)
[1] -0.9999339
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
plot(diff(gnp.ts))
plot(diff(log(gnp.ts)))
##STASIONERITAS
gnp.gr = diff(log(gnp.ts))
acf(gnp.gr)
pacf(gnp.gr)
par(mfrow = c(1,1))
par(mfrow=c(2,1))
##AXIS
par(mfrow=c(1,1))
## ESTIMASI
gnp.gr.AR
gnp.gr.AR2
gnp.gr.AR3
gnp.gr.MA
##ROBUSTNESS CHECK
gnp.gr.MA2
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)
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)
tsdiag(gnp.gr.MA)
## SELEKSI MODEL
N = length(DT1$resid)
DT1.AR$aic
DT1$aic
DT1MA$aic
log(gnp.gr.AR$sigma2)+(N+1)/(N-1-2)
log(gnp.gr.MA$sigma2)+(N+2)/(N-2-2)
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")
> GNP=read.table("E:tour.txt")
> GNP=read.table("E:tour.txt")
> 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)
> gnp.ts
> plot(gnp.ts)
> acf(gnp.ts)
> plot(gnp.ts)
> acf(gnp.ts)
> boxplot(gnp)
> boxplot(GNP)
> BoxCox.lambda(gnp.ts,upper=0)
> library(forecast)
Error in library(forecast) : there is no package called ‘forecast’
> utils:::menuInstallPkgs()
--- Please select a CRAN mirror for use in this session ---
Do you want to install from sources the package which needs compilation?
y/n: y
downloaded 714 KB
downloaded 433 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/curl_3.0.zip'
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/stringr_1.2.0.zip'
downloaded 145 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/RColorBrewer_1.1-2.zip'
downloaded 26 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/dichromat_2.0-0.zip'
downloaded 144 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/munsell_0.4.3.zip'
downloaded 131 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/labeling_0.3.zip'
downloaded 39 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/R6_2.2.2.zip'
downloaded 309 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/viridisLite_0.2.0.zip'
downloaded 56 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/rlang_0.1.4.zip'
downloaded 454 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/quadprog_1.5-5.zip'
downloaded 51 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/quantmod_0.4-11.zip'
downloaded 473 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/digest_0.6.12.zip'
downloaded 168 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/gtable_0.2.0.zip'
downloaded 56 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/plyr_1.8.4.zip'
downloaded 1.2 MB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/reshape2_1.4.2.zip'
downloaded 595 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/scales_0.5.0.zip'
downloaded 679 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/tibble_1.3.4.zip'
downloaded 660 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/lazyeval_0.2.1.zip'
downloaded 136 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/tseries_0.10-42.zip'
downloaded 319 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/fracdiff_1.4-2.zip'
downloaded 104 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/Rcpp_0.12.13.zip'
downloaded 4.1 MB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/colorspace_1.3-2.zip'
downloaded 431 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/ggplot2_2.2.1.zip'
downloaded 2.6 MB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/magrittr_1.5.zip'
downloaded 146 KB
downloaded 282 KB
trying URL 'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/zoo_1.8-
0.zip'
downloaded 881 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/timeDate_3042.101.zip'
downloaded 772 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/RcppArmadillo_0.8.100.1
.0.zip'
downloaded 2.1 MB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/forecast_8.2.zip'
downloaded 2.0 MB
C:\Users\User\AppData\Local\Temp\RtmpYFKmot\downloaded_packages
downloaded 3.5 MB
* removing 'C:/Users/User/Documents/R/win-library/3.3/stringi'
‘C:\Users\User\AppData\Local\Temp\RtmpYFKmot\downloaded_packages’
Warning messages:
> BoxCox.lambda(gnp.ts,upper=0)
> BoxCox.lambda(gnp.ts,upper=0)
> BoxCox.lambda(gnp.ts,upper=0)
> library(forecast)
Warning message:
> 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
> DT1=log(gnp.ts)
> DT1
> library(TSA)
> install.packages("TSA")
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/leaps_3.0.zip'
downloaded 320 KB
downloaded 581 KB
trying URL
'https://repo.bppt.go.id/cran/bin/windows/contrib/3.3/TSA_1.01.zip'
downloaded 363 KB
> library(TSA)
getResponse
finance.
tar
Warning messages:
data: DT1
Warning message:
> #h1:STATIONER
> #3
> boxplot(gnp.ts ~ cycle(gnp.ts))
> #asumsi tidak ada outlier, dari boxplot dilihat bahwa pada quarter pertama
stabil, dsl.
> #4
> acf(gnp.gr)
> pacf(gnp.gr)
> acf(DT1)
> pacf(DT1)
> acf(DT1)
> pacf(DT1)
> par(mfrow=c(2,1))
> ##AXIS
Error in pacf(gnp.gr, 12, ylim = c(-0.2, 0.5), xlab = "Lag = years", main =
"PACF(diff(log(GNP)))") :
> par(mfrow=c(1,1))
> ##AXIS
> par(mfrow=c(1,1))
> plot(DT1,ylim(0,100)
+ )
> plot(DT1,ylim=c(0,100)
+ )
> DDT=diff(DT1,1)
> DDT
> plot(DDT,type="l")
> #ARma(p=1,q=0)
> ## ESTIMASI
> gnp.gr.AR
Call:
Coefficients:
ar1 intercept
0.6311 15.0253
> gnp.gr.MA
Call:
Coefficients:
> tsdiag(gnp.gr.MA)
> N = length(DT1$resid)
>
> DT1.AR$aic
> DT1$aic
> DT1MA$aic
> ## DIAGNOSTICS
> plot(DT1.AR$resid)
>