library(astsa)

Príklad 1

x1<-rep(0,11)

#?arima.sim

set.seed(123)
m<-arima.sim(n=1000, list(ar=c(x1,0.7)))
m1<-window(m,end= 60)
plot(m1)

acf2(m1)

##       [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7] [,8] [,9] [,10] [,11] [,12]
## ACF  -0.07 -0.06 -0.11  0.00 -0.23 -0.08 -0.14 0.21 0.06 -0.05 -0.16  0.47
## PACF -0.07 -0.06 -0.12 -0.02 -0.25 -0.14 -0.23 0.09 0.01 -0.14 -0.24  0.41
##      [,13] [,14] [,15] [,16] [,17] [,18]
## ACF  -0.17 -0.02   0.0 -0.07 -0.10  0.01
## PACF -0.14  0.01   0.1 -0.22  0.01  0.04
acf2(m)

##       [,1] [,2]  [,3]  [,4]  [,5] [,6]  [,7]  [,8] [,9] [,10] [,11] [,12] [,13]
## ACF  -0.02 0.02 -0.03 -0.01 -0.05 0.02 -0.03  0.00    0  0.01 -0.02  0.65  0.01
## PACF -0.02 0.02 -0.03 -0.01 -0.05 0.01 -0.02 -0.01    0  0.01 -0.02  0.65  0.05
##      [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
## ACF   0.04 -0.04 -0.03 -0.06  0.02  0.00  0.02  0.03  0.00 -0.04  0.44  0.01
## PACF  0.04  0.00 -0.03  0.00  0.01  0.02  0.03  0.02 -0.01 -0.04  0.02 -0.02
##      [,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37]
## ACF   0.08 -0.07 -0.06 -0.08  0.02  0.01  0.03  0.07  0.00 -0.05  0.26 -0.02
## PACF  0.06 -0.06 -0.04 -0.04  0.00  0.00  0.00  0.05  0.01 -0.01 -0.05 -0.05
##      [,38] [,39] [,40] [,41] [,42]
## ACF   0.09 -0.07 -0.07 -0.11  0.02
## PACF  0.00  0.00 -0.02 -0.05  0.00
acf(window(m,end= 200), lag.max = 36)

pacf(window(m,end= 200), lag.max = 36)

acf_pr1 <- ARMAacf(ar = c(rep(0, 11), 0.7),
                   lag.max = 60)
plot(acf_pr1, type = "h")

pacf_pr1 <- ARMAacf(ar = c(rep(0, 11), 0.7), 
                    lag.max = 60,
                    pacf = TRUE)
plot(pacf_pr1, type = "h")

Priklad 2

ar_koef <- c(rep(0, 11), 0.8, rep(0, 11), -0.3)
korene <- polyroot(c(1,-ar_koef))
plot(korene)

curve(sqrt(1-x^2),-1,1,add=TRUE)
curve(-sqrt(1-x^2),-1,1,add=TRUE)
abline(h=0)
abline(v=0)  

ABSkorene <- abs(korene)
ABSkorene
##  [1] 1.051445 1.051445 1.051445 1.051445 1.051445 1.051445 1.051445 1.051445
##  [9] 1.051445 1.051445 1.051445 1.051445 1.051445 1.051445 1.051445 1.051445
## [17] 1.051445 1.051445 1.051445 1.051445 1.051445 1.051445 1.051445 1.051445
polyroot(c(1,-0.8,0.3))
## [1] 1.333333+1.247219i 1.333333-1.247219i
polyroot(c(1,-0.8,0.1))
## [1] 1.55051+0i 6.44949-0i
ar_koef2 <- c(rep(0, 11), 0.8, rep(0, 11), -0.1)
korene2 <- polyroot(c(1,-ar_koef2))
plot(korene2)

#odhady acf a pacf
set.seed(123)
m24<-arima.sim(n=100, list(ar= c(rep(0, 11), 0.8, rep(0, 11), -0.3)))
acf2(m24)

##       [,1]  [,2] [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9] [,10] [,11] [,12]
## ACF  -0.13 -0.08 0.08 -0.13 -0.01 -0.26 -0.03  0.07 -0.01  0.10 -0.14  0.42
## PACF -0.13 -0.09 0.06 -0.13 -0.04 -0.31 -0.10 -0.03  0.01  0.03 -0.19  0.37
##      [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20]
## ACF   0.09 -0.18  0.22 -0.14 -0.13 -0.07 -0.11  0.08
## PACF  0.15  0.00  0.22  0.01 -0.09  0.04  0.00 -0.02
acf_pr24 <- ARMAacf(ar = c(rep(0, 11), 0.8, rep(0, 11), -0.3),
                   lag.max = 120)
plot(acf_pr24, type = "h")

pacf_pr24 <- ARMAacf(ar = c(rep(0, 11), 0.8, rep(0, 11), -0.3), 
                    lag.max = 120,
                    pacf = TRUE)
plot(pacf_pr24, type = "h")

## Pre realne korene acf a pacf
acf_pr24Real <- ARMAacf(ar = c(rep(0, 11), 0.8, rep(0, 11), -0.1),
                    lag.max = 120)
plot(acf_pr24Real, type = "h")

pacf_pr24Real <- ARMAacf(ar = c(rep(0, 11), 0.8, rep(0, 11), -0.1), 
                     lag.max = 120,
                     pacf = TRUE)
plot(pacf_pr24Real, type = "h")