PIB de Portugal periodo (1961 - 2021)
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(seasonal)
library(tseries)
library(readxl)
PIBPORTUGAL <- read_excel(file.choose(), sheet = 1)
data <- PIBPORTUGAL
BDPORTUGAL <- ts(data$PIB, frequency = 1);data
## # A tibble: 61 x 2
## AÑOS PIB
## <dbl> <dbl>
## 1 1961 5.53
## 2 1962 6.61
## 3 1963 5.87
## 4 1964 6.31
## 5 1965 7.47
## 6 1966 4.08
## 7 1967 7.54
## 8 1968 8.88
## 9 1969 2.12
## 10 1970 12.6
## # ... with 51 more rows
head(BDPORTUGAL)
## Time Series:
## Start = 1
## End = 6
## Frequency = 1
## [1] 5.534903 6.614448 5.873702 6.310747 7.468989 4.077909
plot(data)

tseries::adf.test(BDPORTUGAL)
## Warning in tseries::adf.test(BDPORTUGAL): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: BDPORTUGAL
## Dickey-Fuller = -4.4509, Lag order = 3, p-value = 0.01
## alternative hypothesis: stationary
No hay estacionariedad en la serie de tiempo de la Base de Datos de
el país Portugal debido a que el “valor P” es menor a 0.05 y tambien por
ello no se necesita hacer diferenciación.
Las 2 caen gradualmente, se deben usar las 2 variables.


modelo1 = arima(BDPORTUGAL, order=c(3,0,1))
modelo2 = arima(BDPORTUGAL, order=c(2,1,2))
summary(modelo1)
##
## Call:
## arima(x = BDPORTUGAL, order = c(3, 0, 1))
##
## Coefficients:
## ar1 ar2 ar3 ma1 intercept
## -0.0120 0.1111 0.3551 0.3430 3.1438
## s.e. 0.2609 0.1597 0.1364 0.2585 0.9742
##
## sigma^2 estimated as 10.36: log likelihood = -158.13, aic = 328.26
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.06120416 3.218035 2.385375 43.79423 118.989 0.8397781
## ACF1
## Training set 0.01988492
summary(modelo2)
##
## Call:
## arima(x = BDPORTUGAL, order = c(2, 1, 2))
##
## Coefficients:
## ar1 ar2 ma1 ma2
## -0.8032 0.0735 0.1399 -0.8601
## s.e. 0.1545 0.1592 0.0979 0.0922
##
## sigma^2 estimated as 10.45: log likelihood = -156.87, aic = 323.73
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.508139 3.206344 2.314262 53.73025 140.0557 0.8147426
## ACF1
## Training set -0.04690275
modelo1$aic
## [1] 328.2559
modelo2$aic
## [1] 323.7348
checkresiduals(modelo1$residuals)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

Box.test(modelo1$residuals, type="Ljung-Box")
##
## Box-Ljung test
##
## data: modelo1$residuals
## X-squared = 0.025326, df = 1, p-value = 0.8736
a<-forecast::forecast(modelo1)
plot(a)
