Capítulo 12
Solução. 12.5
all.equal(zoo(1:10, seq(2010, by = 1, length.out = 10), frequency = 1),
zooreg(1:10, start = 2010, frequency = 1))
## [1] TRUE
all.equal(zoo(1:10, seq(2010+1/2, by = 1/2, length.out = 10), frequency = 2),
zooreg(1:10, start = c(2010,2), frequency = 2))
## [1] TRUE
all.equal(zoo(1:10, seq(2010+1/3, by = 1/3, length.out = 10), frequency = 3),
zooreg(1:10, start = c(2010,2), frequency = 3))
## [1] TRUE
all.equal(zoo(1:10, seq(2010+1/4, by = 1/4, length.out = 10), frequency = 4),
zooreg(1:10, start = c(2010,2), frequency = 4))
## [1] TRUE
all.equal(zoo(1:10, seq(2010+1/6, by = 1/6, length.out = 10), frequency = 6),
zooreg(1:10, start = c(2010,2), frequency = 6))
## [1] TRUE
all.equal(zoo(1:10, seq(2010+1/12, by = 1/12, length.out = 10), frequency = 12),
zooreg(1:10, start = c(2010,2), frequency = 12))
## [1] TRUE
all.equal(zoo(1:10, seq(2010+1/(365/7), by = 1/(365/7), length.out = 10), frequency = 365/7),
zooreg(1:10, start = c(2010,2), frequency = 365/7))
## [1] TRUE
Solução. 12.13
# coal_production
coal <- read.csv('https://filipezabala.com/data/coal.csv')
(s3_coal <- smooth(coal$coal_production, '3')) # suavizado por mediana de 3
## 3 Tukey smoother resulting from smooth(x = coal$coal_production, kind = "3")
## used 1 iterations
## [1] 422 422 422 484 520 520 520 518 505 501 468 382 334 334 359 372 439 439 395 395 461 511 583 590
## [25] 590 578 578 600 600 516 516 516 467 457 457 467 493 493 412 412 412 416 422 459 467 512 534 545
## [49] 545
## 3R Tukey smoother resulting from smooth(x = s3_coal, kind = "3R")
## used 0 iterations
## [1] 422 422 422 484 520 520 520 518 505 501 468 382 334 334 359 372 439 439 395 395 461 511 583 590
## [25] 590 578 578 600 600 516 516 516 467 457 457 467 493 493 412 412 412 416 422 459 467 512 534 545
## [49] 545
# suspended_deposits
depo <- read.csv('https://filipezabala.com/data/deposits.csv')
(s3_depo <- smooth(depo$suspended_deposits, '3')) # suavizado por mediana de 3
## 3 Tukey smoother resulting from smooth(x = depo$suspended_deposits, kind = "3")
## used 1 iterations
## [1] 189.00 189.00 189.00 189.00 213.00 194.00 194.00 194.00 230.00 853.00 853.00 1691.00
## [13] 716.00 37.00 11.00 11.00 11.00 13.00 19.00 13.00 5.90 3.70 3.70 1.70
## [25] 0.40 0.00 0.00 0.00 0.04 0.04 1.40 3.10 2.90 6.50 6.50 11.90
## [37] 11.90 6.30 6.30 7.50 7.50 7.50 22.00 23.30 22.00 11.80 11.80
## 3R Tukey smoother resulting from smooth(x = s3_depo, kind = "3R")
## used 1 iterations
## [1] 189.00 189.00 189.00 189.00 194.00 194.00 194.00 194.00 230.00 853.00 853.00 853.00 716.00 37.00
## [15] 11.00 11.00 11.00 13.00 13.00 13.00 5.90 3.70 3.70 1.70 0.40 0.00 0.00 0.00
## [29] 0.04 0.04 1.40 2.90 3.10 6.50 6.50 11.90 11.90 6.30 6.30 7.50 7.50 7.50
## [43] 22.00 22.00 22.00 11.80 11.80
# gráficos
par(mfrow=c(2,1))
plot(coal$coal_production)
points(s3_coal, type = 'l', col = 'red')
points(s3r_coal, type = 'l', col = 'blue')
plot(depo$suspended_deposits)
points(s3_depo, type = 'l', col = 'red')
points(s3r_depo, type = 'l', col = 'blue')
# função para checar convergências
check_conv <- function(x){
i <- 0
dif <- FALSE
while(!dif){
i <- i+1
conv <- smooth(x,'3R')
x <- smooth(x,'3')
dif <- sum(conv-x) == 0
}
return(i)
}
check_conv(coal$coal_production)
## [1] 1
## [1] 2
## [1] 2
## [1] 6
Solução. 12.18
Seja \(c\) uma constante, \(\phi(B)(1-B)^d y_t = c + \theta(B)a_t\) e \(a_t \sim WN(0,\sigma^2_a)\).
ARIMA(0,0,0) \[y_t = c + a_t\]
ARIMA(1,0,0) \[(1-\phi_1 B) y_t = c + a_t\]
ARIMA(0,0,1) \[y_t = c + (1-\theta_1)a_{t}\]
ARIMA(0,1,0) \[(1-B) y_{t} = c + a_t\]
ARIMA(1,0,1) \[(1-\phi_1 B) y_{t} = c +(1-\theta_1 B) a_t\]
ARIMA(1,1,1) \[(1-\phi_1 B)(1-B)y_t = c + (1-\theta_1 B)a_t\] \[\therefore\] \[[1-(1+\phi_1)B+\phi_1 B^2]y_t = c + (1-\theta_1 B)a_t\]
ARIMA(2,2,2) \[(1-\phi_1 B-\phi_2 B^2)(1-B)^2 y_t = c + (1-\theta_1 B-\theta_2 B^2)a_t\] \[\therefore\] \[[1-(2+\phi_1)B+(1+2\phi_1-\phi_2)B^2-(\phi_1-2\phi_2)B^3-\phi_2 B^4]y_t = c + (1-\theta_1 B-\theta_2 B^2)a_t\]
Solução. 12.19
# ARIMA(1,0,0), \phi_1 = 0.7
par(mfrow=c(1,2))
set.seed(1); ar1 <- arima.sim(list(ar = 0.7), n = 200)
forecast::auto.arima(ar1)
## Series: ar1
## ARIMA(1,0,0) with zero mean
##
## Coefficients:
## ar1
## 0.6916
## s.e. 0.0508
##
## sigma^2 = 0.9153: log likelihood = -274.76
## AIC=553.52 AICc=553.59 BIC=560.12
Expandido \[y_t = 0.6916 y_{t-1} + a_t\] \[a_t \sim N(0,0.9153)\]
Backshift \[(1-0.6916B)y_t = a_t\] \[a_t \sim N(0,0.9153)\]
# ARIMA(1,0,0), \phi_1 = -0.7
par(mfrow=c(1,2))
set.seed(2); ar1n <- arima.sim(list(ar = -0.7), n = 200)
forecast::auto.arima(ar1n)
## Series: ar1n
## ARIMA(1,0,0) with zero mean
##
## Coefficients:
## ar1
## -0.7604
## s.e. 0.0468
##
## sigma^2 = 1.159: log likelihood = -298.48
## AIC=600.95 AICc=601.01 BIC=607.55
Expandido \[y_t = -0.7604 y_{t-1} + a_t\] \[a_t \sim N(0,1.159)\]
Backshift \[(1+0.7604B)y_t = a_t\] \[a_t \sim N(0,1.159)\]
# ARIMA(0,0,1), \theta_1 = 0.7
par(mfrow=c(1,2))
set.seed(3); ma1n <- arima.sim(list(ma = 0.7), n = 200)
forecast::auto.arima(ma1n)
## Series: ma1n
## ARIMA(0,0,1) with zero mean
##
## Coefficients:
## ma1
## 0.7234
## s.e. 0.0500
##
## sigma^2 = 0.9724: log likelihood = -280.86
## AIC=565.72 AICc=565.78 BIC=572.32
Expandido \[y_t = a_t -0.7234 a_{t-1}\] \[a_t \sim N(0,0.9724)\]
Backshift \[y_t = (1-0.7234B)a_t\] \[a_t \sim N(0,0.9724)\]
# ARIMA(2,0,0), \phi_1 = 0.7, \phi_2 = -0.49
par(mfrow=c(1,2))
set.seed(4); ar2 <- arima.sim(list(ar = c(0.7,-0.49)), n = 200)
forecast::auto.arima(ar2)
## Series: ar2
## ARIMA(2,0,0) with zero mean
##
## Coefficients:
## ar1 ar2
## 0.5957 -0.5126
## s.e. 0.0609 0.0612
##
## sigma^2 = 0.9687: log likelihood = -280
## AIC=565.99 AICc=566.12 BIC=575.89
Expandido \[y_t = 0.5957 y_{t-1} -0.5126 y_{t-2} + a_t\] \[a_t \sim N(0,0.9687)\]
Backshift \[(1-0.5957B+0.5126B^2)y_t = a_t\] \[a_t \sim N(0,0.9687)\]
Solução. 12.23
\[y_t = \text{ARIMA}(p,d,q) + \sum_{i=1}^{n} \beta_i X_{t}^i\]