Los modelos de autorregresión, también conocidos como modelos AR, se utilizan para realizar pronósticos sobre variables ex-post (observaciones que conocemos completamente su valor) en determinados momentos del tiempo normalmente ordenados cronológicamente.
Los modelos autorregresivos, como bien dice su nombre, son modelos que se regresan en sí mismos. Es decir, la variable dependiente y la variable explicativa son la misma con la diferencia que la variable dependiente estará en un momento del tiempo posterior (t) al de la variable independiente (t-1). Decimos ordenados cronológicamente porque actualmente nos encontramos en el momento (t) del tiempo. Si avanzamos un período nos trasladamos a (t+1) y si retrocedemos un período nos vamos a (t-1).
En esta ocasión utilizaremos como base el Producto Interno Bruto de Estados Unidos que la FRED ofrece dentro de su página oficial como base de datos que se puede encontrar dentro del siguiente link:
[Gross Domestic Product] (https://fred.stlouisfed.org/series/GDP)
Cargaamos las librerías que se utilizarán dentro de nuestro modelo Autorregresivo:
library(ggplot2)
library(ggfortify)
library(timeSeries)
## Loading required package: timeDate
library(tidyverse)
## -- Attaching packages --------------------------------------------------------------------- tidyverse 1.3.0 --
## v tibble 3.0.1 v dplyr 1.0.2
## v tidyr 1.1.0 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## v purrr 0.3.4
## -- Conflicts ------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks timeSeries::filter(), stats::filter()
## x dplyr::lag() masks timeSeries::lag(), stats::lag()
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
## The following object is masked from 'package:purrr':
##
## some
library(urca)
library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(astsa)
library(forecast)
## Registered S3 methods overwritten by 'forecast':
## method from
## autoplot.Arima ggfortify
## autoplot.acf ggfortify
## autoplot.ar ggfortify
## autoplot.bats ggfortify
## autoplot.decomposed.ts ggfortify
## autoplot.ets ggfortify
## autoplot.forecast ggfortify
## autoplot.stl ggfortify
## autoplot.ts ggfortify
## fitted.ar ggfortify
## fortify.ts ggfortify
## residuals.ar ggfortify
##
## Attaching package: 'forecast'
## The following object is masked from 'package:astsa':
##
## gas
library(foreign)
library(vars)
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
## Loading required package: strucchange
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following object is masked from 'package:timeSeries':
##
## time<-
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: sandwich
##
## Attaching package: 'strucchange'
## The following object is masked from 'package:stringr':
##
## boundary
## Loading required package: lmtest
library(lmtest)
library(mFilter)
library(dynlm)
library(nlme)
##
## Attaching package: 'nlme'
## The following object is masked from 'package:forecast':
##
## getResponse
## The following object is masked from 'package:dplyr':
##
## collapse
library(quantmod)
## Loading required package: xts
##
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
##
## first, last
## Loading required package: TTR
## Version 0.4-0 included new data defaults. See ?getSymbols.
library(NTS)
library(broom)
library(rugarch)
## Loading required package: parallel
##
## Attaching package: 'rugarch'
## The following object is masked from 'package:purrr':
##
## reduce
## The following object is masked from 'package:stats':
##
## sigma
library(rmgarch)
##
## Attaching package: 'rmgarch'
## The following objects are masked from 'package:xts':
##
## first, last
## The following objects are masked from 'package:dplyr':
##
## first, last
library(kableExtra)
##
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
##
## group_rows
library(knitr)
library(MASS)
library(FinTS)
##
## Attaching package: 'FinTS'
## The following object is masked from 'package:forecast':
##
## Acf
library(fGarch)
## Loading required package: fBasics
##
## Attaching package: 'fBasics'
## The following object is masked from 'package:TTR':
##
## volatility
## The following object is masked from 'package:astsa':
##
## nyse
## The following object is masked from 'package:car':
##
## densityPlot
library(parallel)
library(openxlsx)
library(readxl)
Cargamos los datos que empiezan desde 1947 de manera Trimestral tal y como se muestran a continuación:
ProductoInternoBruto = read.xlsx("C:\\Users\\Brook\\Desktop\\GDP 1947.xlsx")
Generamos ahora nuestra serie de tiempo de nuestra variable, observamos los datos y visualizamos la gráfica:
PIB = ts(ProductoInternoBruto$GDP, start = c(1947, 1), frequency = 4)
PIB
## Qtr1 Qtr2 Qtr3 Qtr4
## 1947 243.164 245.968 249.585 259.745
## 1948 265.742 272.567 279.196 280.366
## 1949 275.034 271.351 272.889 270.627
## 1950 280.828 290.383 308.153 319.945
## 1951 336.000 344.090 351.385 356.178
## 1952 359.820 361.030 367.701 380.812
## 1953 387.980 391.749 391.171 385.970
## 1954 385.345 386.121 390.996 399.734
## 1955 413.073 421.532 430.221 437.092
## 1956 439.746 446.010 451.191 460.463
## 1957 469.779 472.025 479.490 474.864
## 1958 467.540 471.978 485.841 499.555
## 1959 510.330 522.653 525.034 528.600
## 1960 542.648 541.080 545.604 540.197
## 1961 545.018 555.545 567.664 580.612
## 1962 594.013 600.366 609.027 612.280
## 1963 621.672 629.752 644.444 653.938
## 1964 669.822 678.674 692.031 697.319
## 1965 717.790 730.191 749.323 771.857
## 1966 795.734 804.981 819.638 833.302
## 1967 844.170 848.983 865.233 881.439
## 1968 909.387 934.344 950.825 968.030
## 1969 993.337 1009.020 1029.956 1038.147
## 1970 1051.200 1067.375 1086.059 1088.608
## 1971 1135.156 1156.271 1177.675 1190.297
## 1972 1230.609 1266.369 1290.566 1328.904
## 1973 1377.490 1413.887 1433.838 1476.289
## 1974 1491.209 1530.056 1560.026 1599.679
## 1975 1616.116 1651.853 1709.820 1761.831
## 1976 1820.487 1852.332 1886.558 1934.273
## 1977 1988.648 2055.909 2118.473 2164.270
## 1978 2202.760 2331.633 2395.053 2476.949
## 1979 2526.610 2591.247 2667.565 2723.883
## 1980 2789.842 2797.352 2856.483 2985.557
## 1981 3124.206 3162.532 3260.609 3280.818
## 1982 3274.302 3331.972 3366.322 3402.561
## 1983 3473.413 3578.848 3689.179 3794.706
## 1984 3908.054 4009.601 4084.250 4148.551
## 1985 4230.168 4294.887 4386.773 4444.094
## 1986 4507.894 4545.340 4607.669 4657.627
## 1987 4722.156 4806.160 4884.555 5007.994
## 1988 5073.372 5190.036 5282.835 5399.509
## 1989 5511.253 5612.463 5695.365 5747.237
## 1990 5872.701 5960.028 6015.116 6004.733
## 1991 6035.178 6126.862 6205.937 6264.540
## 1992 6363.102 6470.763 6566.641 6680.803
## 1993 6729.459 6808.939 6882.098 7013.738
## 1994 7115.652 7246.931 7331.075 7455.288
## 1995 7522.289 7580.997 7683.125 7772.586
## 1996 7868.468 8032.840 8131.408 8259.771
## 1997 8362.655 8518.825 8662.823 8765.907
## 1998 8866.480 8969.699 9121.097 9293.991
## 1999 9417.264 9524.152 9681.856 9899.378
## 2000 10002.857 10247.679 10319.825 10439.025
## 2001 10472.879 10597.822 10596.294 10660.294
## 2002 10788.952 10893.207 10992.051 11071.463
## 2003 11183.507 11312.875 11567.326 11769.275
## 2004 11920.169 12108.987 12303.340 12522.425
## 2005 12761.337 12910.022 13142.873 13332.316
## 2006 13603.933 13749.806 13867.469 14037.228
## 2007 14208.569 14382.363 14535.003 14681.501
## 2008 14651.039 14805.611 14835.187 14559.543
## 2009 14394.547 14352.850 14420.312 14628.021
## 2010 14721.350 14926.098 15079.917 15240.843
## 2011 15285.828 15496.189 15591.850 15796.460
## 2012 16019.758 16152.257 16257.151 16358.863
## 2013 16569.591 16637.926 16848.748 17083.137
## 2014 17104.555 17432.909 17721.657 17849.912
## 2015 18003.399 18223.577 18347.425 18378.803
## 2016 18470.156 18656.207 18821.359 19032.580
## 2017 19237.435 19379.232 19617.288 19937.963
## 2018 20242.215 20552.653 20742.723 20909.853
## 2019 21115.309 21329.877 21540.325 21747.394
## 2020 21561.139 19520.114 21157.635
autoplot(PIB, col = "Blue") + labs(title = "Producto Interno Bruto de Estados Unidos (1947/T1 - 2020/T3)", subtitle = "Fuente: FRED", caption = "En línea: https://fred.stlouisfed.org/series/GDP [23/11/20]") + geom_point(pch = 20) + theme_gray() + ylab("Producto Interno Bruto") + xlab("")
Observamos a primera vista que:
Nuestros datos no son estacionarios.
Tiene una tendencia creciente
Pasaremos a logaritmo nuestra variable.
Frecuentemente las regresiones simples y/o múltiples incorporan logaritmos en la ecuación con el objetivo de aportar estabilidad en los regresores, reducir las observaciones atípicas y establecer distintas visiones de la estimación, entre otras aplicaciones.
logpib = log(PIB)
logpib
## Qtr1 Qtr2 Qtr3 Qtr4
## 1947 5.493736 5.505201 5.519800 5.559700
## 1948 5.582526 5.607884 5.631914 5.636096
## 1949 5.616895 5.603413 5.609065 5.600741
## 1950 5.637742 5.671201 5.730596 5.768149
## 1951 5.817111 5.840903 5.861882 5.875431
## 1952 5.885604 5.888961 5.907270 5.942306
## 1953 5.960954 5.970621 5.969145 5.955760
## 1954 5.954139 5.956151 5.968697 5.990799
## 1955 6.023624 6.043896 6.064299 6.080144
## 1956 6.086197 6.100341 6.111891 6.132233
## 1957 6.152262 6.157032 6.172723 6.163028
## 1958 6.147485 6.156932 6.185881 6.213718
## 1959 6.235058 6.258918 6.263463 6.270232
## 1960 6.296461 6.293567 6.301893 6.291934
## 1961 6.300819 6.319950 6.341530 6.364083
## 1962 6.386901 6.397539 6.411863 6.417190
## 1963 6.432413 6.445326 6.468388 6.483013
## 1964 6.507012 6.520141 6.539631 6.547243
## 1965 6.576177 6.593306 6.619170 6.648799
## 1966 6.679265 6.690819 6.708863 6.725396
## 1967 6.738354 6.744039 6.762999 6.781556
## 1968 6.812771 6.839845 6.857330 6.875263
## 1969 6.901070 6.916735 6.937271 6.945193
## 1970 6.957688 6.972958 6.990311 6.992655
## 1971 7.034525 7.052955 7.071297 7.081958
## 1972 7.115264 7.143909 7.162836 7.192110
## 1973 7.228018 7.254098 7.268110 7.297287
## 1974 7.307342 7.333060 7.352458 7.377558
## 1975 7.387781 7.409653 7.444143 7.474109
## 1976 7.506859 7.524201 7.542509 7.567487
## 1977 7.595210 7.628473 7.658451 7.679838
## 1978 7.697466 7.754324 7.781161 7.814783
## 1979 7.834634 7.859895 7.888921 7.909814
## 1980 7.933740 7.936429 7.957346 8.001542
## 1981 8.046935 8.059128 8.089669 8.095848
## 1982 8.093860 8.111320 8.121576 8.132284
## 1983 8.152893 8.182796 8.213159 8.241362
## 1984 8.270795 8.296447 8.314893 8.330514
## 1985 8.349997 8.365181 8.386349 8.399331
## 1986 8.413585 8.421858 8.435477 8.446261
## 1987 8.460021 8.477654 8.493833 8.518791
## 1988 8.531761 8.554496 8.572218 8.594063
## 1989 8.614547 8.632745 8.647408 8.656474
## 1990 8.678070 8.692830 8.702031 8.700303
## 1991 8.705361 8.720438 8.733262 8.742660
## 1992 8.758271 8.775049 8.789758 8.806993
## 1993 8.814250 8.825992 8.836679 8.855626
## 1994 8.870052 8.888333 8.899877 8.916679
## 1995 8.925626 8.933400 8.946782 8.958358
## 1996 8.970619 8.991293 9.003489 9.019152
## 1997 9.031531 9.050034 9.066796 9.078625
## 1998 9.090033 9.101607 9.118345 9.137123
## 1999 9.150300 9.161586 9.178009 9.200227
## 2000 9.210626 9.234807 9.241822 9.253306
## 2001 9.256544 9.268404 9.268260 9.274281
## 2002 9.286278 9.295895 9.304928 9.312126
## 2003 9.322195 9.333697 9.355940 9.373248
## 2004 9.385987 9.401703 9.417626 9.435276
## 2005 9.454175 9.465759 9.483635 9.497946
## 2006 9.518114 9.528780 9.537301 9.549468
## 2007 9.561601 9.573758 9.584315 9.594344
## 2008 9.592267 9.602762 9.604757 9.586002
## 2009 9.574605 9.571704 9.576393 9.590694
## 2010 9.597054 9.610867 9.621119 9.631734
## 2011 9.634681 9.648349 9.654504 9.667541
## 2012 9.681578 9.689815 9.696288 9.702525
## 2013 9.715324 9.719440 9.732032 9.745847
## 2014 9.747100 9.766115 9.782543 9.789754
## 2015 9.798316 9.810471 9.817245 9.818953
## 2016 9.823912 9.833934 9.842748 9.853908
## 2017 9.864613 9.871957 9.884166 9.900381
## 2018 9.915526 9.930745 9.939951 9.947976
## 2019 9.957754 9.967864 9.977682 9.987249
## 2020 9.978648 9.879201 9.959756
autoplot(logpib, col = "blue") + labs(title = "Logaritmo del Producto Interno Bruto de Estados Unidos (1947/T1 - 2020/T3)", subtitle = "Fuente: FRED", caption = "En línea: https://fred.stlouisfed.org/series/GDP [23/11/20]") + geom_point(pch = 20) + theme_gray() + ylab("Logaritmo") + xlab("")
Lo que toca ahora es estacionalizar la serie a través de obtener el primer diferencial:
dlogpib = diff(logpib)
dlogpib
## Qtr1 Qtr2 Qtr3 Qtr4
## 1947 0.011465333 0.014598092 0.039900842
## 1948 0.022825533 0.025358542 0.024029589 0.004181848
## 1949 -0.019201166 -0.013481541 0.005651933 -0.008323630
## 1950 0.037000893 0.033458359 0.059395672 0.037552693
## 1951 0.048962054 0.023792091 0.020979237 0.013548117
## 1952 0.010173301 0.003357151 0.018309051 0.035035707
## 1953 0.018647977 0.009667537 -0.001476524 -0.013385158
## 1954 -0.001620609 0.002011755 0.012546538 0.022101996
## 1955 0.032825007 0.020271361 0.020403336 0.015844669
## 1956 0.006053588 0.014144086 0.011549380 0.020341752
## 1957 0.020029866 0.004769579 0.015691089 -0.009694592
## 1958 -0.015543541 0.009447468 0.028949036 0.027836292
## 1959 0.021339873 0.023860189 0.004545258 0.006768980
## 1960 0.026228857 -0.002893717 0.008326296 -0.009959550
## 1961 0.008884934 0.019130792 0.021580080 0.022553025
## 1962 0.022818485 0.010638265 0.014323132 0.005327093
## 1963 0.015222928 0.012913469 0.023061838 0.014624616
## 1964 0.023999460 0.013128889 0.019489858 0.007612230
## 1965 0.028934065 0.017129097 0.025863988 0.029629167
## 1966 0.030465659 0.011553716 0.018044105 0.016533342
## 1967 0.012957775 0.005685266 0.018959672 0.018556964
## 1968 0.031214947 0.027073933 0.017485350 0.017933050
## 1969 0.025806904 0.015664860 0.020536520 0.007921310
## 1970 0.012494976 0.015269994 0.017353185 0.002344268
## 1971 0.041870271 0.018430085 0.018341984 0.010660700
## 1972 0.033306313 0.028644582 0.018927131 0.029273661
## 1973 0.035908460 0.026079647 0.014012116 0.029176741
## 1974 0.010055694 0.025717136 0.019398152 0.025100496
## 1975 0.010222756 0.021871948 0.034490414 0.029965507
## 1976 0.032750439 0.017341338 0.018308619 0.024977541
## 1977 0.027723466 0.033263075 0.029977460 0.021387576
## 1978 0.017627997 0.056857761 0.026836480 0.033622201
## 1979 0.019850922 0.025260744 0.029026844 0.020892365
## 1980 0.023926528 0.002688292 0.020917892 0.044195181
## 1981 0.045393842 0.012192802 0.030541015 0.006178794
## 1982 -0.001988065 0.017459604 0.010256433 0.010707630
## 1983 0.020609301 0.029903277 0.030362979 0.028202997
## 1984 0.029432614 0.025652183 0.018446378 0.015621004
## 1985 0.019482592 0.015183537 0.021168632 0.012982147
## 1986 0.014254058 0.008272450 0.013619557 0.010784002
## 1987 0.013759384 0.017632954 0.016179758 0.024957250
## 1988 0.012970250 0.022734948 0.017722252 0.021845138
## 1989 0.020483979 0.018197659 0.014663026 0.009066531
## 1990 0.021595447 0.014760515 0.009200455 -0.001727643
## 1991 0.005057357 0.015077362 0.012823704 0.009398747
## 1992 0.015610832 0.016778036 0.014708408 0.017235751
## 1993 0.007256564 0.011741554 0.010687240 0.018947250
## 1994 0.014426068 0.018281204 0.011544094 0.016801417
## 1995 0.008946901 0.007774241 0.013381644 0.011576562
## 1996 0.012260453 0.020674759 0.012195955 0.015662769
## 1997 0.012379097 0.018502460 0.016762230 0.011829342
## 1998 0.011407881 0.011574245 0.016737963 0.018777980
## 1999 0.013176538 0.011286288 0.016422730 0.022218308
## 2000 0.010398825 0.024180489 0.007015562 0.011484385
## 2001 0.003237776 0.011859545 -0.000144191 0.006021681
## 2002 0.011996649 0.009616736 0.009032991 0.007198522
## 2003 0.010069207 0.011501354 0.022242942 0.017307923
## 2004 0.012739517 0.015716065 0.015922866 0.017650267
## 2005 0.018899016 0.011583856 0.017875726 0.014311228
## 2006 0.020168080 0.010665773 0.008521023 0.012167206
## 2007 0.012132290 0.012157431 0.010557076 0.010028526
## 2008 -0.002077011 0.010494976 0.001995628 -0.018755204
## 2009 -0.011397201 -0.002900926 0.004689239 0.014301168
## 2010 0.006359885 0.013812403 0.010252634 0.010615005
## 2011 0.002947261 0.013667998 0.006154219 0.013037522
## 2012 0.014036971 0.008236957 0.006473081 0.006236956
## 2013 0.012799318 0.004115640 0.012591563 0.013815485
## 2014 0.001252966 0.019014939 0.016427709 0.007211127
## 2015 0.008561995 0.012155622 0.006773042 0.001708752
## 2016 0.004958251 0.010022665 0.008813436 0.011159906
## 2017 0.010705873 0.007343857 0.012209241 0.016214385
## 2018 0.015144672 0.015219757 0.009205454 0.008024997
## 2019 0.009777839 0.010110444 0.009817994 0.009567174
## 2020 -0.008601360 -0.099447153 0.080555412
autoplot(dlogpib, col = "blue") + labs(title = "Primer diferencial del Logaritmo del PIB de Estadis Unidos (1947/T1 - 2020/T3)", subtitle = "Fuente: FRED", caption = "En línea: https://fred.stlouisfed.org/series/GDP [23/11/20]") + geom_point(pch = 20) + theme_gray() + ylab("Logaritmo") + xlab("")
Lo que ahora debemos de comprobar es que la serie de tiempo sea estacionaria, lo que significa es que el tiempo no depende de los datos obsenidos. Para eso lo comprobaremos a través de la prueba de Dickey - Fuller Aumentada y la prueba Phillips - Perron.
Dickey - Fuller Aumentada:
adf.test(dlogpib)
## Warning in adf.test(dlogpib): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: dlogpib
## Dickey-Fuller = -5.3898, Lag order = 6, p-value = 0.01
## alternative hypothesis: stationary
Phillips - Perron:
pp.test(dlogpib)
## Warning in pp.test(dlogpib): p-value smaller than printed p-value
##
## Phillips-Perron Unit Root Test
##
## data: dlogpib
## Dickey-Fuller Z(alpha) = -251.69, Truncation lag parameter = 5, p-value
## = 0.01
## alternative hypothesis: stationary
Observamos que el p-value en ambos casos es menor que 0.01, por lo que aseguramos entonces que nuestra serie de tiempo es Estacionaria. Podemos proceder a correr el modelo Autorregresivo (AR).
Empezando por un modelo de autorregresivo a un rezago (t-1) para empezar a comprobar los datos que se pueden obtener a través del resumen estadístico.
AR1 = dynlm(dlogpib ~ L(dlogpib))
summary(AR1)
##
## Time series regression with "ts" data:
## Start = 1947(3), End = 2020(3)
##
## Call:
## dynlm(formula = dlogpib ~ L(dlogpib))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.108553 -0.005110 -0.000309 0.005458 0.094954
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.011331 0.001166 9.714 < 2e-16 ***
## L(dlogpib) 0.258727 0.059274 4.365 1.77e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01296 on 291 degrees of freedom
## Multiple R-squared: 0.06145, Adjusted R-squared: 0.05822
## F-statistic: 19.05 on 1 and 291 DF, p-value: 1.769e-05
Observamos que:
*Los estimadores \((\beta_0, \beta_1)\) son significativas, teniendo sus respectivos valores de 0.011331 y de 0.258727, con un valor significativo t de Student junto con una probabilidad de p-value menor que 0.05. Por último, podemos notar una \(R^{2}\) demasiado baja porque debemos de recordar que estamos aplicando una regresión a una serie de tiempo Estacionaria a través de la misma variable dependiente como independiente.
Podemos generar distintas pruebas de dicho modelo y ver si existe algún otro modelo que se llegue a ajustar a diferentes rezagos. En este caso lo haremos a 2 rezagos para ver el comportamiento de dicha serie de tiempo:
AR2 = dynlm(dlogpib ~ L(dlogpib, 1:2))
summary(AR2)
##
## Time series regression with "ts" data:
## Start = 1947(4), End = 2020(3)
##
## Call:
## dynlm(formula = dlogpib ~ L(dlogpib, 1:2))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.109615 -0.005058 -0.000474 0.004838 0.088695
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.008906 0.001355 6.575 2.27e-10 ***
## L(dlogpib, 1:2)1 0.148450 0.066843 2.221 0.027134 *
## L(dlogpib, 1:2)2 0.265341 0.078472 3.381 0.000821 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01276 on 289 degrees of freedom
## Multiple R-squared: 0.09716, Adjusted R-squared: 0.09092
## F-statistic: 15.55 on 2 and 289 DF, p-value: 3.85e-07
Podemos generar otro a 3 rezagos:
AR3 = dynlm(dlogpib ~ L(dlogpib, 1:3))
summary(AR3)
##
## Time series regression with "ts" data:
## Start = 1948(1), End = 2020(3)
##
## Call:
## dynlm(formula = dlogpib ~ L(dlogpib, 1:3))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.109563 -0.005157 -0.000549 0.004829 0.089502
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.009116 0.001467 6.212 1.83e-09 ***
## L(dlogpib, 1:3)1 0.152136 0.067113 2.267 0.024143 *
## L(dlogpib, 1:3)2 0.289120 0.085460 3.383 0.000816 ***
## L(dlogpib, 1:3)3 -0.046548 0.079960 -0.582 0.560932
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.0127 on 287 degrees of freedom
## Multiple R-squared: 0.1005, Adjusted R-squared: 0.09106
## F-statistic: 10.68 on 3 and 287 DF, p-value: 1.116e-06
Por último podemos generar otro modelo a 4 rezagos:
AR4 = dynlm(dlogpib ~ L(dlogpib, 1:4))
summary(AR4)
##
## Time series regression with "ts" data:
## Start = 1948(2), End = 2020(3)
##
## Call:
## dynlm(formula = dlogpib ~ L(dlogpib, 1:4))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.109771 -0.005211 -0.000496 0.004841 0.088849
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.009406 0.001575 5.972 6.97e-09 ***
## L(dlogpib, 1:4)1 0.145196 0.068373 2.124 0.034566 *
## L(dlogpib, 1:4)2 0.299812 0.087645 3.421 0.000716 ***
## L(dlogpib, 1:4)3 -0.027310 0.087399 -0.312 0.754911
## L(dlogpib, 1:4)4 -0.042828 0.081340 -0.527 0.598930
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01274 on 285 degrees of freedom
## Multiple R-squared: 0.1006, Adjusted R-squared: 0.08798
## F-statistic: 7.97 on 4 and 285 DF, p-value: 4.205e-06
Podemos resumir que los mejores modelos de la serie de tiempo del Producto Interno Bruto de Estados Unidos se explica a través de la Autorregresión a 1 o 2 rezagos.
Tendencia = seq_along(dlogpib)
Tendencia = ts(Tendencia, start = c(1974, 01), frequency = 4)
Tendencia
## Qtr1 Qtr2 Qtr3 Qtr4
## 1974 1 2 3 4
## 1975 5 6 7 8
## 1976 9 10 11 12
## 1977 13 14 15 16
## 1978 17 18 19 20
## 1979 21 22 23 24
## 1980 25 26 27 28
## 1981 29 30 31 32
## 1982 33 34 35 36
## 1983 37 38 39 40
## 1984 41 42 43 44
## 1985 45 46 47 48
## 1986 49 50 51 52
## 1987 53 54 55 56
## 1988 57 58 59 60
## 1989 61 62 63 64
## 1990 65 66 67 68
## 1991 69 70 71 72
## 1992 73 74 75 76
## 1993 77 78 79 80
## 1994 81 82 83 84
## 1995 85 86 87 88
## 1996 89 90 91 92
## 1997 93 94 95 96
## 1998 97 98 99 100
## 1999 101 102 103 104
## 2000 105 106 107 108
## 2001 109 110 111 112
## 2002 113 114 115 116
## 2003 117 118 119 120
## 2004 121 122 123 124
## 2005 125 126 127 128
## 2006 129 130 131 132
## 2007 133 134 135 136
## 2008 137 138 139 140
## 2009 141 142 143 144
## 2010 145 146 147 148
## 2011 149 150 151 152
## 2012 153 154 155 156
## 2013 157 158 159 160
## 2014 161 162 163 164
## 2015 165 166 167 168
## 2016 169 170 171 172
## 2017 173 174 175 176
## 2018 177 178 179 180
## 2019 181 182 183 184
## 2020 185 186 187 188
## 2021 189 190 191 192
## 2022 193 194 195 196
## 2023 197 198 199 200
## 2024 201 202 203 204
## 2025 205 206 207 208
## 2026 209 210 211 212
## 2027 213 214 215 216
## 2028 217 218 219 220
## 2029 221 222 223 224
## 2030 225 226 227 228
## 2031 229 230 231 232
## 2032 233 234 235 236
## 2033 237 238 239 240
## 2034 241 242 243 244
## 2035 245 246 247 248
## 2036 249 250 251 252
## 2037 253 254 255 256
## 2038 257 258 259 260
## 2039 261 262 263 264
## 2040 265 266 267 268
## 2041 269 270 271 272
## 2042 273 274 275 276
## 2043 277 278 279 280
## 2044 281 282 283 284
## 2045 285 286 287 288
## 2046 289 290 291 292
## 2047 293 294
autoplot(Tendencia, col = "blue") + labs(title = "Tendencia del Primer Diferencial del Logaritmo del Producto Interno Bruto de Estados Unidos", subtitle = "(1947/T1 - 2020/T3)") + ylab("") + xlab("")
Podemos agregar ahora la tendencia a nuestro modelo autorregresivo:
AR5 = dynlm(dlogpib ~ Tendencia + L(dlogpib, 1))
summary(AR5)
##
## Time series regression with "ts" data:
## Start = 1974(1), End = 2020(3)
##
## Call:
## dynlm(formula = dlogpib ~ Tendencia + L(dlogpib, 1))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.106017 -0.003945 0.000459 0.004959 0.061081
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.0273791 0.0027140 10.088 < 2e-16 ***
## Tendencia -0.0001185 0.0000190 -6.238 2.97e-09 ***
## L(dlogpib, 1) -0.1433563 0.0824139 -1.739 0.0836 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.01212 on 184 degrees of freedom
## Multiple R-squared: 0.1841, Adjusted R-squared: 0.1752
## F-statistic: 20.76 on 2 and 184 DF, p-value: 7.425e-09
Observamos que: Al incluir la tendencia a nuestro modelo Autorregresivo, a penas es valido el primer rezago del primer diferencial del logaritmo del PIB de Estados Unidos. Por lo que podemos decir que nuestro segundo modelo, AR2 fue el mejor que explicaba en sí el modelo de Autorregresión. Resultado por el cual lo tomaremos y obtaremos por manejarlo.
Podemos ahora utilizar el modelo AR2 para estimar nuestra serie de tiempo:
Pronostico = predict(AR2)
Pronostico
## 1947 Q4 1948 Q1 1948 Q2 1948 Q3 1948 Q4 1949 Q1
## 0.014115492 0.018702947 0.022881973 0.018727215 0.019202043 0.015903011
## 1949 Q2 1949 Q3 1949 Q4 1950 Q1 1950 Q2 1950 Q3
## 0.007165366 0.001809969 0.006167995 0.009170216 0.012190369 0.023690945
## 1950 Q4 1951 Q1 1951 Q2 1951 Q3 1951 Q4 1952 Q1
## 0.026601371 0.030241010 0.026138891 0.025429772 0.018333573 0.016484054
## 1952 Q2 1952 Q3 1952 Q4 1953 Q1 1953 Q2 1953 Q3
## 0.014011278 0.012103939 0.012514950 0.018965386 0.020970892 0.015289400
## 1953 Q4 1954 Q1 1954 Q2 1954 Q3 1954 Q4 1955 Q1
## 0.011252177 0.006527356 0.005113957 0.008774803 0.011302513 0.015516338
## 1955 Q2 1955 Q3 1955 Q4 1956 Q1 1956 Q2 1956 Q3
## 0.019643631 0.020625294 0.017313885 0.016672167 0.014009074 0.012612135
## 1956 Q4 1957 Q1 1957 Q2 1957 Q3 1957 Q4 1958 Q1
## 0.014373692 0.014990442 0.017277121 0.014928968 0.012501087 0.011630498
## 1958 Q2 1958 Q3 1958 Q4 1959 Q1 1959 Q2 1959 Q3
## 0.004026350 0.006184310 0.015710473 0.020719856 0.019460203 0.018110577
## 1959 Q4 1960 Q1 1960 Q2 1960 Q3 1960 Q4 1961 Q1
## 0.015912010 0.011117075 0.014595948 0.015436196 0.009374392 0.009636982
## 1961 Q2 1961 Q3 1961 Q4 1962 Q1 1962 Q2 1962 Q3
## 0.007582465 0.014103686 0.017185934 0.017980265 0.018277835 0.016540113
## 1962 Q4 1963 Q1 1963 Q2 1963 Q3 1963 Q4 1964 Q1
## 0.013855218 0.013497499 0.012579520 0.014862453 0.015756189 0.017196460
## 1964 Q2 1964 Q3 1964 Q4 1965 Q1 1965 Q2 1965 Q3
## 0.016349417 0.017223209 0.015283086 0.015207674 0.015221286 0.019126396
## 1965 Q4 1966 Q1 1966 Q2 1966 Q3 1966 Q4 1967 Q1
## 0.017290749 0.020167419 0.021290654 0.018705123 0.014650505 0.016148400
## 1967 Q2 1967 Q3 1967 Q4 1968 Q1 1968 Q2 1968 Q3
## 0.015216737 0.013188385 0.013229280 0.016691745 0.018463974 0.021207923
## 1968 Q4 1969 Q1 1969 Q2 1969 Q3 1969 Q4 1970 Q1
## 0.018685712 0.016207926 0.017495597 0.018079264 0.016111362 0.015531280
## 1970 Q2 1970 Q3 1970 Q4 1971 Q1 1971 Q2 1971 Q3
## 0.012862907 0.014488442 0.015534020 0.013858695 0.015743864 0.022752037
## 1971 Q4 1972 Q1 1972 Q2 1972 Q3 1972 Q4 1973 Q1
## 0.016519310 0.015355643 0.016679233 0.021996013 0.019316503 0.018274010
## 1973 Q2 1973 Q3 1973 Q4 1974 Q1 1974 Q2 1974 Q3
## 0.022004310 0.022305704 0.017906284 0.016955465 0.018140738 0.015392083
## 1974 Q4 1975 Q1 1975 Q2 1975 Q3 1975 Q4 1976 Q1
## 0.018609654 0.017779482 0.017083942 0.014865592 0.019829821 0.022506296
## 1976 Q2 1976 Q3 1976 Q4 1977 Q1 1977 Q2 1977 Q3
## 0.021719076 0.020170544 0.016225468 0.017472132 0.019649306 0.021200271
## 1977 Q4 1978 Q1 1978 Q2 1978 Q3 1978 Q4 1979 Q1
## 0.022182406 0.020035425 0.017198063 0.022024169 0.027976770 0.021018229
## 1979 Q2 1979 Q3 1979 Q4 1980 Q1 1980 Q2 1980 Q3
## 0.020774408 0.017923410 0.019917938 0.019709673 0.018001683 0.015653945
## 1980 Q4 1981 Q1 1981 Q2 1981 Q3 1981 Q4 1982 Q1
## 0.012724758 0.021017347 0.027371715 0.022761058 0.016675253 0.017927208
## 1982 Q2 1982 Q3 1982 Q4 1983 Q1 1983 Q2 1983 Q3
## 0.010250531 0.010970543 0.015061498 0.013217179 0.014806808 0.018813825
## 1983 Q4 1984 Q1 1984 Q2 1984 Q3 1984 Q4 1985 Q1
## 0.021348144 0.021149471 0.020758876 0.020523938 0.018451128 0.016119702
## 1985 Q2 1985 Q3 1985 Q4 1986 Q1 1986 Q2 1986 Q3
## 0.015943269 0.016329711 0.016077484 0.016450289 0.014466893 0.013916411
## 1986 Q4 1987 Q1 1987 Q2 1987 Q3 1987 Q4 1988 Q1
## 0.013123024 0.014120892 0.013810199 0.015174724 0.015986815 0.016904245
## 1988 Q2 1988 Q3 1988 Q4 1989 Q1 1989 Q2 1989 Q3
## 0.017453800 0.015722728 0.017569568 0.016851538 0.017743445 0.017042868
## 1989 Q4 1990 Q1 1990 Q2 1990 Q3 1990 Q4 1991 Q1
## 0.015911495 0.014142808 0.014517751 0.016827540 0.014188557 0.011090963
## 1991 Q2 1991 Q3 1991 Q4 1992 Q1 1992 Q2 1992 Q3
## 0.009198524 0.012486339 0.014810503 0.013704078 0.013717483 0.015539077
## 1992 Q4 1993 Q1 1993 Q2 1993 Q3 1993 Q4 1994 Q1
## 0.015541547 0.015367575 0.014556768 0.012574677 0.013608216 0.014554666
## 1994 Q2 1994 Q3 1994 Q4 1995 Q1 1995 Q2 1995 Q3
## 0.016075216 0.015447856 0.015470656 0.014463474 0.014692453 0.012434244
## 1995 Q4 1996 Q1 1996 Q2 1996 Q3 1996 Q4 1997 Q1
## 0.012955510 0.014175420 0.013797981 0.015228554 0.016202534 0.014467407
## 1997 Q2 1997 Q3 1997 Q4 1998 Q1 1998 Q2 1998 Q3
## 0.014899834 0.014937556 0.016303999 0.015109955 0.013738490 0.013651356
## 1998 Q4 1999 Q1 1999 Q2 1999 Q3 1999 Q4 2000 Q1
## 0.014462055 0.016135044 0.015844808 0.014077906 0.014338852 0.016562118
## 2000 Q2 2000 Q3 2000 Q4 2001 Q1 2001 Q2 2001 Q3
## 0.016345316 0.015255014 0.016363717 0.012472552 0.012434102 0.011525842
## 2001 Q4 2002 Q1 2002 Q2 2002 Q3 2002 Q4 2003 Q1
## 0.012031593 0.009761833 0.012284880 0.013516987 0.012798841 0.012371621
## 2003 Q2 2003 Q3 2003 Q4 2004 Q1 2004 Q2 2004 Q3
## 0.012311015 0.013285329 0.015259931 0.017377511 0.015389865 0.014619549
## 2004 Q4 2005 Q1 2005 Q2 2005 Q3 2005 Q4 2006 Q1
## 0.015440049 0.015751356 0.016395084 0.015640489 0.014633507 0.015773848
## 2006 Q2 2006 Q3 2006 Q4 2007 Q1 2007 Q2 2007 Q3
## 0.015697492 0.015840935 0.013001191 0.012973378 0.013935678 0.013930145
## 2007 Q4 2008 Q1 2008 Q2 2008 Q3 2008 Q4 2009 Q1
## 0.013699243 0.013196139 0.011258820 0.009913039 0.011987174 0.006651475
## 2009 Q2 2009 Q3 2009 Q4 2010 Q1 2010 Q2 2010 Q3
## 0.002237722 0.005451380 0.008832556 0.012273436 0.013644990 0.012644170
## 2010 Q4 2011 Q1 2011 Q2 2011 Q3 2011 Q4 2012 Q1
## 0.014093181 0.013202421 0.012160293 0.011717222 0.013446452 0.012474566
## 2012 Q2 2012 Q3 2012 Q4 2013 Q1 2013 Q2 2013 Q3
## 0.014449359 0.013853540 0.012052708 0.011549626 0.012461158 0.012913328
## 2013 Q4 2014 Q1 2014 Q2 2014 Q3 2014 Q4 2015 Q1
## 0.011867444 0.014298148 0.012757993 0.012061412 0.016390321 0.014335616
## 2015 Q2 2015 Q3 2015 Q4 2016 Q1 2016 Q2 2016 Q3
## 0.012090614 0.012982530 0.013137021 0.010957004 0.010095629 0.011709670
## 2016 Q4 2017 Q1 2017 Q2 2017 Q3 2017 Q4 2018 Q1
## 0.012873957 0.012901433 0.013456647 0.012837081 0.012667268 0.014552820
## 2018 Q2 2018 Q3 2018 Q4 2019 Q1 2019 Q2 2019 Q3
## 0.015456751 0.015184058 0.014311155 0.012540073 0.012487059 0.013001536
## 2019 Q4 2020 Q1 2020 Q2 2020 Q3
## 0.013046375 0.012931542 0.010167862 -0.008139101
Pronostico = ts(Pronostico, start = c(1947, 1), frequency = 4)
autoplot(Pronostico, col = "Red", ts.linetype = "dashed") + labs(title = "Estimación del primer diferencial del logaritmo del PIB de Estados UNidos (1947/T1 - 2020/T3)", subtitle = "Fuente: FRED", caption = "https://fred.stlouisfed.org/series/GDP") + ylab("") + xlab("")
## Warning: Ignoring unknown parameters: ts.linetype
Podemos ahora graficar ambas series de tiempo para ver cómo es el comportamiento entre la variable observada y la variable estimada del Primer Diferencial del Producto Interno Bruto de Estados Unidos.
autoplot(dlogpib, series = "dlogpib") + autolayer(Pronostico, series = "dlogpib Estimado") + labs(title = "Primer diferencial del logaritmo del PIB (Observado y Estimado)", subtitle = "Fuente: Calculos propios a partir de datos de FRED") + ylab("") + xlab("")
Por último podemos definir si existe o no autocorrelación dentro del modelo dentro de la Prueba Durbin - Watson:
dwtest(AR2)
##
## Durbin-Watson test
##
## data: AR2
## DW = 1.8058, p-value = 0.04463
## alternative hypothesis: true autocorrelation is greater than 0
Observamos que nuestro valor del Durbin-Watson es de 1.8058, por lo cual entra dentro de la zona de no rechazar \(H_0\), lo que significa que no existe problema de autocorrelación positiva o negativa dentro del modelo AR(2). Siendo un excelente modelo para Estimar la variable del PIB de Estados Unidos.
https://economipedia.com/definiciones/modelo-autorregresivo-ar.html
https://economipedia.com/definiciones/logaritmos-en-econometria.html#:~:text=La%20principal%20utilidad%20de%20los,las%20variables%20sobre%20los%20coeficientes.&text=Por%20ejemplo%2C%20si%20trat%C3%A1semos%20los,como%20variable%20independiente%20(X)
https://www.academia.edu/31001823/_damodar_gujarati_econometrics_by_example_manzoor_ahmad