library(WDI)
library(forecast)
library(tseries)
datos <- WDI(indicator = "NY.GDP.MKTP.KD", # NY.GDP.MKTP.KD para PIB US$ a
# precios constantes del 2025,
# NY.GDP.MKTP.CD para PIB a US$
# precios actuales
country = "1W",
start = 1960,
end = 2024)
datos <- datos[order(datos$year), ]
pib_log <- ts(log(datos$NY.GDP.MKTP.KD), start = 1960, frequency = 1)
adf.test(pib_log) # nivel: raíz unitaria esperada
##
## Augmented Dickey-Fuller Test
##
## data: pib_log
## Dickey-Fuller = -3.9815, Lag order = 3, p-value = 0.0161
## alternative hypothesis: stationary
adf.test(diff(pib_log)) # diferencia: debe ser estacionaria
##
## Augmented Dickey-Fuller Test
##
## data: diff(pib_log)
## Dickey-Fuller = -3.6868, Lag order = 3, p-value = 0.03305
## alternative hypothesis: stationary
years <- 1960:2024
D_covid <- as.numeric(years %in% c(2020))
modelo_v2<- auto.arima(pib_log,
d = 1,
xreg = matrix(D_covid, ncol = 1, dimnames = list(NULL, "D_covid")),
stepwise = FALSE,
approximation = FALSE)
summary(modelo_v2)
## Series: pib_log
## Regression with ARIMA(0,1,1) errors
##
## Coefficients:
## ma1 drift D_covid
## 0.4555 0.0338 -0.0442
## s.e. 0.1105 0.0023 0.0067
##
## sigma^2 = 0.0001871: log likelihood = 187.91
## AIC=-367.83 AICc=-367.15 BIC=-359.19
##
## Training set error measures:
## ME RMSE MAE MPE MAPE
## Training set 0.0004684369 0.01325229 0.01003865 0.001823168 0.03231952
## MASE ACF1
## Training set 0.2854608 0.02841539
checkresiduals(modelo_v2)
##
## Ljung-Box test
##
## data: Residuals from Regression with ARIMA(0,1,1) errors
## Q* = 11.204, df = 9, p-value = 0.262
##
## Model df: 1. Total lags used: 10
Conclusón:
Como Ljung-Box test: \(p > \alpha = 0.05\) – No se rechaza \(H_0\), los residuos son ruido blanco. No tienen autocorrelación sistemática.
# Proyección 2025
xreg_2025 <- matrix(0, nrow = 1, ncol = 1,
dimnames = list(NULL, "D_covid"))
fc <- forecast(modelo_v2, h = 1, xreg = xreg_2025)
# Resultado en niveles
pib_2025 <- exp(fc$mean)
pib_2025_lo <- exp(fc$lower[, 2]) # límite inferior 95%
pib_2025_hi <- exp(fc$upper[, 2]) # límite superior 95%
# Tasa de crecimiento implícita
pib_2024 <- tail(datos$NY.GDP.MKTP.KD, 1)
tasa <- (pib_2025 / pib_2024 - 1) * 100
cat("PIB mundial proyectado 2025 (USD 2015):\n")
## PIB mundial proyectado 2025 (USD 2015):
cat(" Puntual: $", formatC(pib_2025, format = "f", digits = 0, big.mark = ","), "\n")
## Puntual: $ 99,691,702,969,227
cat(" IC inf: $", formatC(pib_2025_lo, format = "f", digits = 0, big.mark = ","), "\n")
## IC inf: $ 97,054,275,735,914
cat(" IC sup: $", formatC(pib_2025_hi, format = "f", digits = 0, big.mark = ","), "\n")
## IC sup: $ 102,400,801,670,471
cat(" Crecimiento proyectado: ", round(tasa, 2), "%\n")
## Crecimiento proyectado: 3.32 %
El modelo estima un PIB mundial de $99,691,702,969,227 de dólares constantes del 2015 para 2025. Con una tasa de crecimiento implícita de 3.32 %.
Con un intervalo de \(\pm2.7 \%\), o sea, una amplitud de $5,346,525,934,557 entre el Intervalo de Confianza inferior y el superior.