library(forecast)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(seasonal)
library(tseries)
library(readxl)
datos <- read_excel(file.choose(), sheet = 1)
str(datos)
## tibble [61 × 2] (S3: tbl_df/tbl/data.frame)
##  $ Años: num [1:61] 1961 1962 1963 1964 1965 ...
##  $ PIB : num [1:61] 6.27 2.81 3.79 5.01 5.29 ...
head(datos)
## # A tibble: 6 × 2
##    Años   PIB
##   <dbl> <dbl>
## 1  1961  6.27
## 2  1962  2.81
## 3  1963  3.79
## 4  1964  5.01
## 5  1965  5.29
## 6  1966  3.79
## Con una base de datos del PIB anual para Noruega desde el año 1961 hasta 2021 se debe determinar que modelo utilizar para predecir los datos de los siguientes años

datos_ts<-ts(datos$PIB, frequency = 1)
plot(datos_ts)

tseries::adf.test(datos_ts)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  datos_ts
## Dickey-Fuller = -4.0204, Lag order = 3, p-value = 0.01472
## alternative hypothesis: stationary
## La serie de datos muestra un p-valor menor a 0.05 en la prueba de Dickey-Fuller por lo cual no es necesario realizar ningún cambio en los datos.

acf(datos_ts)

pacf(datos_ts)

modelo1 = arima(datos_ts, order=c(0,0,3))

summary(modelo1)
## 
## Call:
## arima(x = datos_ts, order = c(0, 0, 3))
## 
## Coefficients:
##          ma1     ma2      ma3  intercept
##       0.5609  0.3299  -0.0493     3.1054
## s.e.  0.1370  0.1332   0.1354     0.3679
## 
## sigma^2 estimated as 2.469:  log likelihood = -114.36,  aic = 238.72
## 
## Training set error measures:
##                       ME     RMSE      MAE       MPE    MAPE     MASE
## Training set -0.03069834 1.571195 1.307971 -12.44073 92.0824 0.896767
##                     ACF1
## Training set -0.03505753
modelo1$aic
## [1] 238.717
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.078719, df = 1, p-value = 0.779
a<-forecast::forecast(modelo1)
plot(a)

## Como se muestra los residuales están bien, la prueba Box-Ljung muestra un p-valor mayor a 0.05 y estos son los valores predecidos.