data <- read.table(file.choose(),head=TRUE,sep=";")
data <- data.frame(data)
data
## Year PIBG
## 1 1960 0.0000000
## 2 1961 8.1375295
## 3 1962 7.5534442
## 4 1963 10.0401733
## 5 1964 -3.1031682
## 6 1965 7.8342605
## 7 1966 10.1800953
## 8 1967 12.5086127
## 9 1968 13.5269942
## 10 1969 13.8338251
## 11 1970 13.9420030
## 12 1971 12.4134372
## 13 1972 13.3155626
## 14 1973 10.6030030
## 15 1974 6.1174044
## 16 1975 3.9887386
## 17 1976 7.4371668
## 18 1977 6.8524424
## 19 1978 7.7771820
## 20 1979 9.5544487
## 21 1980 10.1133721
## 22 1981 10.8159233
## 23 1982 7.1021448
## 24 1983 8.5544821
## 25 1984 8.7922862
## 26 1985 -0.6227016
## 27 1986 1.3428104
## 28 1987 10.7979325
## 29 1988 11.2635921
## 30 1989 10.1588286
## 31 1990 9.8208996
## 32 1991 6.6883975
## 33 1992 6.6398056
## 34 1993 11.4596509
## 35 1994 11.0956893
## 36 1995 7.1754011
## 37 1996 7.4713909
## 38 1997 8.3162091
## 39 1998 -2.1910150
## 40 1999 5.7183718
## 41 2000 9.0383163
## 42 2001 -1.0708628
## 43 2002 3.9233608
## 44 2003 4.5482554
## 45 2004 9.9399827
## 46 2005 7.3663224
## 47 2006 9.0067661
## 48 2007 9.0215195
## 49 2008 1.8634835
## 50 2009 0.1279534
## 51 2010 14.5197497
## 52 2011 6.2149342
## 53 2012 4.4354976
## 54 2013 4.8176310
## 55 2014 3.9355403
## 56 2015 2.9767993
## 57 2016 3.5616980
## 58 2017 4.6614350
## 59 2018 3.6613050
## 60 2019 1.0956726
## 61 2020 -4.1431056
## 62 2021 7.6139626
datos_ts<-ts(data$PIBG, frequency = 1)
datos_ts
## Time Series:
## Start = 1
## End = 62
## Frequency = 1
## [1] 0.0000000 8.1375295 7.5534442 10.0401733 -3.1031682 7.8342605
## [7] 10.1800953 12.5086127 13.5269942 13.8338251 13.9420030 12.4134372
## [13] 13.3155626 10.6030030 6.1174044 3.9887386 7.4371668 6.8524424
## [19] 7.7771820 9.5544487 10.1133721 10.8159233 7.1021448 8.5544821
## [25] 8.7922862 -0.6227016 1.3428104 10.7979325 11.2635921 10.1588286
## [31] 9.8208996 6.6883975 6.6398056 11.4596509 11.0956893 7.1754011
## [37] 7.4713909 8.3162091 -2.1910150 5.7183718 9.0383163 -1.0708628
## [43] 3.9233608 4.5482554 9.9399827 7.3663224 9.0067661 9.0215195
## [49] 1.8634835 0.1279534 14.5197497 6.2149342 4.4354976 4.8176310
## [55] 3.9355403 2.9767993 3.5616980 4.6614350 3.6613050 1.0956726
## [61] -4.1431056 7.6139626
plot(datos_ts,main="Crecimiento PIB Singapur",ylab="Crecimiento del PIB",xlab="Años")
tseries::adf.test(datos_ts)
##
## Augmented Dickey-Fuller Test
##
## data: datos_ts
## Dickey-Fuller = -3.4234, Lag order = 3, p-value = 0.06039
## alternative hypothesis: stationary
diff_ts<-diff(datos_ts)
tseries::adf.test(diff_ts)
## Warning in tseries::adf.test(diff_ts): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: diff_ts
## Dickey-Fuller = -5.2713, Lag order = 3, p-value = 0.01
## alternative hypothesis: stationary
plot(diff_ts,main="Crecimiento PIB Singapur",ylab="Crecimiento del PIB",xlab="Años")
acf(diff_ts)
pacf(diff_ts)
modelo1 = arima(datos_ts, order=c(0,0,1))
summary(modelo1)
##
## Call:
## arima(x = datos_ts, order = c(0, 0, 1))
##
## Coefficients:
## ma1 intercept
## 0.3506 6.9176
## s.e. 0.1212 0.7050
##
## sigma^2 estimated as 17.03: log likelihood = -175.93, aic = 357.86
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 0.03457414 4.127089 3.275732 -Inf Inf 0.9622945 0.00380046
modelo1$aic
## [1] 357.8585
modelo2 = arima(datos_ts, order=c(0,0,2))
summary(modelo2)
##
## Call:
## arima(x = datos_ts, order = c(0, 0, 2))
##
## Coefficients:
## ma1 ma2 intercept
## 0.3592 0.0366 6.9128
## s.e. 0.1299 0.1157 0.7275
##
## sigma^2 estimated as 17.01: log likelihood = -175.88, aic = 359.76
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 0.03696409 4.123798 3.2678 -Inf Inf 0.9599643 -0.008378025
modelo2$aic
## [1] 359.759
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.00093954, df = 1, p-value = 0.9755
A partir de ‘Ljung-Box test’ se obtuvo un resultado de p-value de 0.9755, lo cual confirma la presencia de ruido blanco en el modelo encontrado.
a<-forecast::forecast(modelo1)
plot(a)