Como primer punto se carga las librerias.

library(vars)
## Warning: package 'vars' was built under R version 4.2.2
## Loading required package: MASS
## Loading required package: strucchange
## Warning: package 'strucchange' was built under R version 4.2.2
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: sandwich
## Warning: package 'sandwich' was built under R version 4.2.2
## Loading required package: urca
## Warning: package 'urca' was built under R version 4.2.2
## Loading required package: lmtest
library(fpp2)
## Warning: package 'fpp2' was built under R version 4.2.2
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## ── Attaching packages ────────────────────────────────────────────── fpp2 2.5 ──
## āœ” ggplot2   3.3.6     āœ” fma       2.5  
## āœ” forecast  8.20      āœ” expsmooth 2.3
## Warning: package 'ggplot2' was built under R version 4.2.1
## Warning: package 'forecast' was built under R version 4.2.2
## Warning: package 'fma' was built under R version 4.2.2
## Warning: package 'expsmooth' was built under R version 4.2.2
## 
library(TSA)
## Warning: package 'TSA' was built under R version 4.2.2
## Registered S3 methods overwritten by 'TSA':
##   method       from    
##   fitted.Arima forecast
##   plot.Arima   forecast
## 
## Attaching package: 'TSA'
## The following objects are masked from 'package:stats':
## 
##     acf, arima
## The following object is masked from 'package:utils':
## 
##     tar
#Cargar datos
series<-uschange
autoplot(uschange[,c(2,5)])

autoplot(uschange)

series
##         Consumption      Income  Production      Savings Unemployment
## 1970 Q1  0.61598622  0.97226104 -2.45270031   4.81031150          0.9
## 1970 Q2  0.46037569  1.16908472 -0.55152509   7.28799234          0.5
## 1970 Q3  0.87679142  1.55327055 -0.35870786   7.28901306          0.5
## 1970 Q4 -0.27424514 -0.25527238 -2.18545486   0.98522964          0.7
## 1971 Q1  1.89737076  1.98715363  1.90973412   3.65777061         -0.1
## 1971 Q2  0.91199291  1.44733417  0.90153584   6.05134180         -0.1
## 1971 Q3  0.79453885  0.53181193  0.30801942  -0.44583221          0.1
## 1971 Q4  1.64858747  1.16012514  2.29130441  -1.53087186          0.0
## 1972 Q1  1.31372218  0.45701150  4.14957387  -4.35859438         -0.2
## 1972 Q2  1.89147495  1.01662441  1.89062398  -5.05452579         -0.1
## 1972 Q3  1.53071400  1.90410126  1.27335290   5.80995904         -0.2
## 1972 Q4  2.31829471  3.89025866  3.43689207  16.04471706         -0.3
## 1973 Q1  1.81073916  0.70825266  2.79907636  -5.34886849         -0.3
## 1973 Q2 -0.04173996  0.79430954  0.81768862   8.42603436          0.0
## 1973 Q3  0.35423556  0.43381827  0.86899693   2.75879565         -0.1
## 1973 Q4 -0.29163216  1.09380979  1.47296187  11.14642986          0.1
## 1974 Q1 -0.87702794 -1.66168482 -0.88248358  -2.53351449          0.2
## 1974 Q2  0.35113555 -0.93835321  0.07427919  -6.59264464          0.3
## 1974 Q3  0.40959770  0.09448779 -0.41314971   0.51717884          0.5
## 1974 Q4 -1.47580863 -0.12259599 -4.06411893  11.34339540          1.3
## 1975 Q1  0.83225762 -0.16369546 -6.85103912  -5.47619069          1.4
## 1975 Q2  1.65583461  4.53650956 -1.33129558  24.30960536          0.2
## 1975 Q3  1.41942029 -1.46376532  2.42435972 -17.65616104         -0.4
## 1975 Q4  1.05437932  0.76166351  2.16904208   0.64809041         -0.2
## 1976 Q1  1.97998024  1.16825761  3.02720471  -2.95006644         -0.6
## 1976 Q2  0.91391607  0.51729906  1.27881101  -1.47455755          0.0
## 1976 Q3  1.05532326  0.73370026  1.30386487  -0.06754475          0.0
## 1976 Q4  1.29889825  0.59458339  1.77537765  -3.57672239          0.2
## 1977 Q1  1.13637586 -0.03108003  2.05516067  -9.16055658         -0.4
## 1977 Q2  0.54994073  1.23808955  3.05838507   9.09050404         -0.2
## 1977 Q3  0.94985262  1.51880293  1.10308888   7.94495719         -0.4
## 1977 Q4  1.49599724  1.91456240  0.63346850   6.69627648         -0.4
## 1978 Q1  0.57549599  0.70266687 -0.29339056   2.92296383         -0.1
## 1978 Q2  2.11120960  0.98314132  3.94815264  -6.81114259         -0.4
## 1978 Q3  0.41796279  0.71992620  0.87114701   4.79207162          0.1
## 1978 Q4  0.79792710  0.78553605  1.78447991   2.37118400          0.0
## 1979 Q1  0.50584598  1.05755946  0.42594327   7.77418337         -0.2
## 1979 Q2 -0.05775339 -0.86765105 -0.20491944  -5.28634896         -0.1
## 1979 Q3  0.97730010  0.47100340 -0.29723637  -1.84549644          0.2
## 1979 Q4  0.26826982  0.44037974  0.33560928   4.04959810          0.1
## 1980 Q1 -0.15391875  0.33827686  0.41056141   5.86168864          0.3
## 1980 Q2 -2.27411019 -1.46388507 -4.30076832   8.24322919          1.3
## 1980 Q3  1.07188123  1.21301507 -1.64181977   5.70775044         -0.1
## 1980 Q4  1.31644941  1.94243865  3.78045520   9.15098787         -0.3
## 1981 Q1  0.52472770 -0.26813406  0.24627687  -5.68139002          0.2
## 1981 Q2 -0.01728203 -0.02363025  0.30977573   0.88183993          0.1
## 1981 Q3  0.40165150  2.02680183  0.91707444  15.99035721          0.1
## 1981 Q4 -0.75287620  0.19560628 -2.25457797   7.80550650          0.9
## 1982 Q1  0.65938376  0.11969888 -2.07131293  -3.34243955          0.5
## 1982 Q2  0.36854173  0.57548997 -1.24766384   2.19400166          0.6
## 1982 Q3  0.76954464  0.53484410 -1.40050430   0.03499563          0.5
## 1982 Q4  1.80876006  0.44938311 -1.90375664  -9.57651468          0.7
## 1983 Q1  0.96802954  0.85588425  1.14655720   0.34595460         -0.5
## 1983 Q2  1.95946831  0.70632719  2.17942248 -10.17004699         -0.2
## 1983 Q3  1.73949442  1.49810999  3.36771897   0.21217916         -0.9
## 1983 Q4  1.56389332  2.13138911  2.58168445   8.21600068         -0.9
## 1984 Q1  0.84526442  2.02348788  2.89709545  13.86918150         -0.5
## 1984 Q2  1.41504495  1.64921136  1.53821324   4.38900229         -0.6
## 1984 Q3  0.76546608  1.36163845  0.72128740   6.51686089          0.1
## 1984 Q4  1.31380062  0.81927319  0.04115557  -2.87544931          0.0
## 1985 Q1  1.68655320 -0.23895759  0.32353159 -18.71008389         -0.1
## 1985 Q2  0.93436990  1.90677905  0.07020996  11.82871950          0.2
## 1985 Q3  1.90256675 -0.33536283 -0.14046924 -23.57393474         -0.3
## 1985 Q4  0.25656565  1.14181151  0.57978813  11.36628338         -0.1
## 1986 Q1  0.84304279  1.23951110  0.58132135   5.86126836          0.2
## 1986 Q2  1.11177390  1.31938549 -0.57641778   3.27551734          0.0
## 1986 Q3  1.79499406  0.70477150  0.37249329 -10.09044542         -0.2
## 1986 Q4  0.63768446  0.17977925  1.13734778  -4.82920131         -0.4
## 1987 Q1  0.01569397  0.81973366  1.30758228  12.46424452          0.0
## 1987 Q2  1.37731686 -0.97505791  1.75000563 -29.52866718         -0.4
## 1987 Q3  1.15225712  1.80185055  1.84366200  12.32810406         -0.3
## 1987 Q4  0.21016439  1.32743427  2.40645058  16.63076101         -0.2
## 1988 Q1  1.76316026  1.44861875  0.92013121  -0.96896505          0.0
## 1988 Q2  0.73053714  1.02084894  0.87316353   5.67776867         -0.3
## 1988 Q3  0.85083233  0.95820336  0.38103668   3.64649867          0.0
## 1988 Q4  1.13789838  0.96207024  0.70292025  -0.19730358         -0.1
## 1989 Q1  0.46064152  1.22693023  0.43372685  10.01461545         -0.3
## 1989 Q2  0.46937808 -0.29489091 -0.36675732  -8.15576525          0.3
## 1989 Q3  0.98950145  0.67822897 -0.62142121  -2.48622554          0.0
## 1989 Q4  0.43942767  0.80025832  0.42443392   5.44681102          0.1
## 1990 Q1  0.85543417  0.83939484  0.68265169   2.87544931         -0.2
## 1990 Q2  0.31230451  0.59572848  0.77446547   5.10951644          0.0
## 1990 Q3  0.40261313  0.03740765  0.41944800  -3.17767248          0.7
## 1990 Q4 -0.75910716 -0.79479735 -1.57345296  -0.17953326          0.4
## 1991 Q1 -0.34535008  0.21183290 -1.91422028   6.49315257          0.5
## 1991 Q2  0.83564224  0.69043356  0.59131506  -0.30920615          0.1
## 1991 Q3  0.48439843  0.36205181  1.36255645  -0.14086493          0.0
## 1991 Q4 -0.02626579  0.85100324  0.21710308  11.34193010          0.4
## 1992 Q1  1.85996999  2.12421067 -0.13365365   7.23265150          0.1
## 1992 Q2  0.68354371  1.04095059  1.76874773   5.46708666          0.4
## 1992 Q3  1.07661214  0.43562041  0.76167388  -5.93646090         -0.2
## 1992 Q4  1.18372396  0.34210852  1.05024577  -5.88618856         -0.2
## 1993 Q1  0.37817936  0.55877186  0.87901471   2.63464703         -0.4
## 1993 Q2  0.89392729  0.17627103  0.21755108  -6.91664675          0.0
## 1993 Q3  1.09813766  0.05868803  0.40135891 -11.99337844         -0.3
## 1993 Q4  0.88122025  0.65496353  1.49618275  -1.83708870         -0.2
## 1994 Q1  1.14064791  0.69846579  1.22213656  -5.18600629          0.0
## 1994 Q2  0.77176225  1.05367166  1.78250275   5.15609751         -0.4
## 1994 Q3  0.77214364  0.59247377  1.26718100  -2.42215898         -0.2
## 1994 Q4  1.07014805  1.38110661  2.04370404   6.32351898         -0.4
## 1995 Q1  0.26420505  0.94873528  1.02552601  10.11514398         -0.1
## 1995 Q2  0.89311141  0.22780635  0.33785685 -10.60541172          0.2
## 1995 Q3  0.91264702  0.88957006  0.90043887  -0.11570727          0.0
## 1995 Q4  0.70025425  0.57591998  0.87467273  -2.90726686          0.0
## 1996 Q1  0.92360967  0.95255663  0.69285195   2.55933958         -0.1
## 1996 Q2  1.07997887  0.95161791  2.11134752  -0.75802112         -0.2
## 1996 Q3  0.60055799  0.79369738  1.24418680   3.33843952         -0.1
## 1996 Q4  0.78298122  0.52035746  1.35396890  -3.33843952          0.2
## 1997 Q1  1.04949253  0.99858552  1.86714700   0.61269338         -0.2
## 1997 Q2  0.45219855  0.85103564  1.48763922   6.17532322         -0.2
## 1997 Q3  1.69654264  1.18352222  2.28632066  -7.22796452         -0.1
## 1997 Q4  1.18062797  1.42325742  2.48091341   5.43456565         -0.2
## 1998 Q1  1.02693626  2.10753052  1.10343775  19.35335228          0.0
## 1998 Q2  1.75069399  1.38767133  0.65122238  -4.81709478         -0.2
## 1998 Q3  1.30596977  1.01464427  0.72551955  -3.12983982          0.1
## 1998 Q4  1.45888615  0.80893032  1.44421674  -9.14923404         -0.2
## 1999 Q1  0.94821191  0.89173174  1.10341663   1.88735718         -0.2
## 1999 Q2  1.46971415  0.24722185  0.98574261 -23.49652903          0.1
## 1999 Q3  1.12921436  0.66729226  0.90279881  -9.86264835         -0.1
## 1999 Q4  1.45748895  1.46092242  1.75533234   2.35825225         -0.2
## 2000 Q1  1.51106759  1.95061335  0.99682019  12.28684080          0.0
## 2000 Q2  0.95508878  1.03174349  1.23293805   1.28001748          0.0
## 2000 Q3  0.96797647  1.16178668 -0.10225268   2.57390229         -0.1
## 2000 Q4  0.88629738  0.33725343 -0.20388383 -13.16296208          0.0
## 2001 Q1  0.42159086  0.84865826 -1.35143911  13.22491995          0.4
## 2001 Q2  0.25689982 -0.08818148 -1.25954437  -6.89043916          0.2
## 2001 Q3  0.36381084  2.33678920 -1.44101744  41.66826457          0.5
## 2001 Q4  1.51630321 -1.24443353 -1.06013675 -56.75209674          0.7
## 2002 Q1  0.29958257  2.40331419  0.70916406  50.75796205          0.0
## 2002 Q2  0.50899032  0.50559877  1.54280957   0.87861837          0.1
## 2002 Q3  0.69667241 -0.12828194  0.59478143 -14.70397426         -0.1
## 2002 Q4  0.53634306  0.47941927 -0.05776556   1.58733492          0.3
## 2003 Q1  0.43826169  0.27834026  0.53922789   0.49744834         -0.1
## 2003 Q2  1.10719086  1.43729445 -0.69876172   7.00891625          0.4
## 2003 Q3  1.46377882  1.62544947  0.60727351   6.18413150         -0.2
## 2003 Q4  0.77334046  0.40353864  1.00599126  -6.89274778         -0.4
## 2004 Q1  0.96768535  0.72653162  0.65792806  -2.96152040          0.1
## 2004 Q2  0.64760607  0.98056746  0.57461780   8.30885627         -0.2
## 2004 Q3  0.95117167  0.52450113  0.56330030  -8.99318286         -0.2
## 2004 Q4  1.02041702  1.24238706  1.38522763   6.23585017          0.0
## 2005 Q1  0.76172556 -0.96827007  1.39435718 -42.28191228         -0.2
## 2005 Q2  1.08136588  0.78835467  0.50586367 -18.27592893         -0.2
## 2005 Q3  0.77186494  0.51136949 -0.50305848  -7.87665229          0.0
## 2005 Q4  0.37591485  0.82191843  0.93365010  20.37236078         -0.1
## 2006 Q1  1.11522822  2.25904474  0.95057853  37.40653542         -0.2
## 2006 Q2  0.53100554  0.14987813  0.59636010 -12.34810568         -0.1
## 2006 Q3  0.58208747  0.28490722  0.33552773 -10.55276140         -0.1
## 2006 Q4  1.01434389  1.30059162  0.25603401   6.03100080         -0.1
## 2007 Q1  0.52486184  0.65373993  0.91794957   6.60516929          0.0
## 2007 Q2  0.33874119  0.19260870  1.19594247  -7.23648452          0.2
## 2007 Q3  0.44391875  0.26238732  0.22356909  -9.00674555          0.1
## 2007 Q4  0.12505584  0.08392938  0.16424632   2.32887238          0.3
## 2008 Q1 -0.20652548  0.71926565 -0.42872571  29.83728599          0.1
## 2008 Q2  0.16783443  2.08693775 -1.41297022  46.43989041          0.5
## 2008 Q3 -0.72499446 -2.32611860 -3.26349945 -32.53252494          0.5
## 2008 Q4 -1.21068558  0.64019534 -4.35417741  36.31240490          1.2
## 2009 Q1 -0.34354370 -0.18888849 -5.75045075   0.92306020          1.4
## 2009 Q2 -0.45174364  0.70899368 -3.00372447  16.09059408          0.8
## 2009 Q3  0.60491332 -1.10343180  1.39880419 -24.49229966          0.3
## 2009 Q4 -0.01115014 -0.13213193  1.54400617   0.84829220          0.1
## 2010 Q1  0.53481740  0.10094986  1.88006931  -5.54399051          0.0
## 2010 Q2  0.81040406  1.29229259  2.05402479  11.65612884         -0.5
## 2010 Q3  0.64501881  0.49678098  1.42683671  -0.35208609          0.1
## 2010 Q4  1.01833874  0.69495229  0.37927209  -3.27335958         -0.2
## 2011 Q1  0.50041315  1.21571502  0.50174040  14.33860193         -0.3
## 2011 Q2  0.20141978 -0.15658108  0.21878696  -4.07705131          0.1
## 2011 Q3  0.43372599  0.52891255  1.01113866   2.72250400         -0.1
## 2011 Q4  0.33593895  0.06074719  0.85151692  -3.45447712         -0.5
## 2012 Q1  0.60108995  1.62204885  0.88651817  17.62530510         -0.3
## 2012 Q2  0.16942956  0.76689543  0.62923586   8.96949710          0.0
## 2012 Q3  0.26416034 -0.05071452  0.07880166  -3.04922177         -0.4
## 2012 Q4  0.27877186  2.59106697  0.63305509  29.04670355          0.1
## 2013 Q1  0.46861292 -4.26525047  0.67713243 -68.78826698         -0.4
## 2013 Q2  0.20545802  0.58146541  0.30744961   7.81647729          0.0
## 2013 Q3  0.46641787  0.58328912  0.23440888   3.49400682         -0.3
## 2013 Q4  0.83917367  0.21494896  0.79208722 -11.27661450         -0.5
## 2014 Q1  0.47345118  1.10369487  0.54709166  13.52020248          0.0
## 2014 Q2  0.93375698  1.29390492  1.33801074   8.24404770         -0.6
## 2014 Q3  0.91687178  0.99853396  0.62352731   2.46195256         -0.2
## 2014 Q4  1.12533250  1.04641801  0.90355427  -1.51305022         -0.3
## 2015 Q1  0.59624005  0.49040680 -0.46710878  -0.75840017         -0.2
## 2015 Q2  0.70814389  0.95495949 -0.69702162   5.02391773         -0.1
## 2015 Q3  0.66496956  0.80166267  0.38060610   3.18092976         -0.3
## 2015 Q4  0.56167978  0.74006260 -0.84554638   3.48278601          0.0
## 2016 Q1  0.40468216  0.51902540 -0.41793048   2.23653405          0.0
## 2016 Q2  1.04770741  0.72372078 -0.20331883  -2.72150106         -0.1
## 2016 Q3  0.72959779  0.64470081  0.47491844  -0.57285793          0.0
#plot de serie de datos
ts.plot(series[,c(2,5)], xlab="Tiempo",col=c(2,5))

Se seleccionan las variables que representar mayor causalidad, en este caso ingreso y desempleo.

#Búsqueda de parÔmetros
a <- VARselect(uschange[,c(2:5)], lag.max=15,type="const")
a$selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      3      1      1      3

La función VARselect sugiere que el modelo es de 3 lags, sin embago, utilizar 3 lags el modelo presenta que existe autocorrelación de igual manera muestra variables significativas para el modelo. Es por eso que se utilizo 5 lags.

#Creación de modelo
modelo1<-VAR(uschange[,c(2,5)],p=5,type=c("const"))#cambio

modelo_s<-summary(modelo1)

#si no pasan de 1, el modelo es estacionario
modelo_s$roots
##  [1] 0.7775660 0.7775660 0.7660914 0.7660914 0.7488061 0.7488061 0.6720236
##  [8] 0.6720236 0.6364359 0.5646411
summary(modelo1,equation="Income")
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: Income, Unemployment 
## Deterministic variables: const 
## Sample size: 182 
## Log Likelihood: -262.292 
## Roots of the characteristic polynomial:
## 0.7776 0.7776 0.7661 0.7661 0.7488 0.7488 0.672 0.672 0.6364 0.5646
## Call:
## VAR(y = uschange[, c(2, 5)], p = 5, type = c("const"))
## 
## 
## Estimation results for equation Income: 
## ======================================= 
## Income = Income.l1 + Unemployment.l1 + Income.l2 + Unemployment.l2 + Income.l3 + Unemployment.l3 + Income.l4 + Unemployment.l4 + Income.l5 + Unemployment.l5 + const 
## 
##                 Estimate Std. Error t value Pr(>|t|)    
## Income.l1       -0.13069    0.07628  -1.713  0.08848 .  
## Unemployment.l1 -0.47812    0.22736  -2.103  0.03693 *  
## Income.l2        0.08289    0.07790   1.064  0.28883    
## Unemployment.l2  0.39251    0.23868   1.644  0.10191    
## Income.l3        0.03524    0.07602   0.464  0.64351    
## Unemployment.l3 -0.65814    0.24414  -2.696  0.00773 ** 
## Income.l4       -0.09359    0.07556  -1.239  0.21717    
## Unemployment.l4 -0.14117    0.24531  -0.575  0.56571    
## Income.l5       -0.12761    0.07471  -1.708  0.08944 .  
## Unemployment.l5  0.39764    0.22214   1.790  0.07522 .  
## const            0.87038    0.14889   5.846 2.49e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.8936 on 171 degrees of freedom
## Multiple R-Squared: 0.1347,  Adjusted R-squared: 0.08413 
## F-statistic: 2.663 on 10 and 171 DF,  p-value: 0.004781 
## 
## 
## 
## Covariance matrix of residuals:
##               Income Unemployment
## Income        0.7985     -0.05280
## Unemployment -0.0528      0.09033
## 
## Correlation matrix of residuals:
##               Income Unemployment
## Income        1.0000      -0.1966
## Unemployment -0.1966       1.0000
summary(modelo1,equation="Unemployment")
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: Income, Unemployment 
## Deterministic variables: const 
## Sample size: 182 
## Log Likelihood: -262.292 
## Roots of the characteristic polynomial:
## 0.7776 0.7776 0.7661 0.7661 0.7488 0.7488 0.672 0.672 0.6364 0.5646
## Call:
## VAR(y = uschange[, c(2, 5)], p = 5, type = c("const"))
## 
## 
## Estimation results for equation Unemployment: 
## ============================================= 
## Unemployment = Income.l1 + Unemployment.l1 + Income.l2 + Unemployment.l2 + Income.l3 + Unemployment.l3 + Income.l4 + Unemployment.l4 + Income.l5 + Unemployment.l5 + const 
## 
##                  Estimate Std. Error t value Pr(>|t|)    
## Income.l1       -0.050174   0.025657  -1.956  0.05215 .  
## Unemployment.l1  0.436087   0.076472   5.703 5.08e-08 ***
## Income.l2       -0.004766   0.026202  -0.182  0.85589    
## Unemployment.l2  0.156143   0.080280   1.945  0.05342 .  
## Income.l3       -0.023081   0.025569  -0.903  0.36796    
## Unemployment.l3  0.067925   0.082118   0.827  0.40930    
## Income.l4       -0.012685   0.025414  -0.499  0.61833    
## Unemployment.l4 -0.183030   0.082510  -2.218  0.02785 *  
## Income.l5        0.068785   0.025128   2.737  0.00685 ** 
## Unemployment.l5  0.038701   0.074718   0.518  0.60516    
## const            0.012796   0.050080   0.256  0.79863    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.3006 on 171 degrees of freedom
## Multiple R-Squared: 0.3665,  Adjusted R-squared: 0.3295 
## F-statistic: 9.893 on 10 and 171 DF,  p-value: 5.479e-13 
## 
## 
## 
## Covariance matrix of residuals:
##               Income Unemployment
## Income        0.7985     -0.05280
## Unemployment -0.0528      0.09033
## 
## Correlation matrix of residuals:
##               Income Unemployment
## Income        1.0000      -0.1966
## Unemployment -0.1966       1.0000
#Validación del modelo
#>PortManteu Test > 0.05 Autocorrelación
serial.test(modelo1, lags.pt=8, type="PT.asymptotic")
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 24.488, df = 12, p-value = 0.01744
#RaĆ­z unitaria < 1
roots(modelo1)
##  [1] 0.7775660 0.7775660 0.7660914 0.7660914 0.7488061 0.7488061 0.6720236
##  [8] 0.6720236 0.6364359 0.5646411
#normalidad Jarque Bera < 0.05
normality.test(modelo1, multivariate.only=FALSE)
## $Income
## 
##  JB-Test (univariate)
## 
## data:  Residual of Income equation
## Chi-squared = 195.51, df = 2, p-value < 2.2e-16
## 
## 
## $Unemployment
## 
##  JB-Test (univariate)
## 
## data:  Residual of Unemployment equation
## Chi-squared = 33.197, df = 2, p-value = 6.184e-08
## 
## 
## $JB
## 
##  JB-Test (multivariate)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 216.79, df = 4, p-value < 2.2e-16
## 
## 
## $Skewness
## 
##  Skewness only (multivariate)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 7.8916, df = 2, p-value = 0.01934
## 
## 
## $Kurtosis
## 
##  Kurtosis only (multivariate)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 208.9, df = 2, p-value < 2.2e-16
#heteroscedasticity >0.05 NO HAY
arch<-arch.test(modelo1, lags.multi = 5, multivariate.only = FALSE)
arch
## $Income
## 
##  ARCH test (univariate)
## 
## data:  Residual of Income equation
## Chi-squared = 11.621, df = 16, p-value = 0.7697
## 
## 
## $Unemployment
## 
##  ARCH test (univariate)
## 
## data:  Residual of Unemployment equation
## Chi-squared = 21.391, df = 16, p-value = 0.164
## 
## 
## 
##  ARCH (multivariate)
## 
## data:  Residuals of VAR object modelo1
## Chi-squared = 63.738, df = 45, p-value = 0.03429
#Structural breaks
stab<-stability(modelo1, type = "OLS-CUSUM")
par(mar=c(1,1,1,1))
plot(stab)

Se puede obserca mediante la grafica que el modelo no prsenta cambios estructurales, ya que ambas gaficas se mantien dentro de los parametros.

#BoxCox.ar(abs(uschange[,2]))

#Causalidad de granger
#granger < 0.05 para que exista causalidad
 
#correr esto
GrangerIncome <-causality(modelo1, cause = 'Income')
GrangerIncome
## $Granger
## 
##  Granger causality H0: Income do not Granger-cause Unemployment
## 
## data:  VAR object modelo1
## F-Test = 2.8057, df1 = 5, df2 = 342, p-value = 0.01687
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: Income and Unemployment
## 
## data:  VAR object modelo1
## Chi-squared = 6.7734, df = 1, p-value = 0.009253
GrangerUnemployment <-causality(modelo1, cause = 'Unemployment')
GrangerUnemployment
## $Granger
## 
##  Granger causality H0: Unemployment do not Granger-cause Income
## 
## data:  VAR object modelo1
## F-Test = 3.7264, df1 = 5, df2 = 342, p-value = 0.002681
## 
## 
## $Instant
## 
##  H0: No instantaneous causality between: Unemployment and Income
## 
## data:  VAR object modelo1
## Chi-squared = 6.7734, df = 1, p-value = 0.009253

Es importante mencionar que antes de correr el script por completo es necesario utilizar granger ya que por medio de este obtendremos el p-value que nos demostrara si existia causalidad entre las variables lo cual ambas presentan.

#Respuesta de impulso
#Como se comporta una variable si la otra variable recibe un "shock"
IncomeIRF <- irf(modelo1,  impulse = "Income", response="Income", n.ahead = 20, boot = T )
plot(IncomeIRF, ylab = "Income", main = "Shock desde Savings")

ConsumptionIRF <- irf(modelo1,  impulse = "Unemployment", response="Unemployment", n.ahead = 20, boot = T )
plot(ConsumptionIRF, ylab = "Unemployment", main = "Shock desde Income")

#Descomposición de la varianza
FEVD1 <- fevd(modelo1, n.ahead = 10)
plot(FEVD1)

Se puede observar que el ingreso tiene relación con el desempleo.

#prediccion

fore<-predict(modelo1, n.ahead = 10, ci=0.95)
fanchart(fore)

autoplot(forecast(modelo1))

#Formula
modelo1$varresult$Income$coefficients
##       Income.l1 Unemployment.l1       Income.l2 Unemployment.l2       Income.l3 
##     -0.13068647     -0.47812026      0.08288524      0.39250556      0.03524393 
## Unemployment.l3       Income.l4 Unemployment.l4       Income.l5 Unemployment.l5 
##     -0.65813631     -0.09359142     -0.14117449     -0.12760511      0.39764021 
##           const 
##      0.87038486
modelo1$varresult$Unemployment$coefficients
##       Income.l1 Unemployment.l1       Income.l2 Unemployment.l2       Income.l3 
##    -0.050173536     0.436086896    -0.004765779     0.156142861    -0.023081051 
## Unemployment.l3       Income.l4 Unemployment.l4       Income.l5 Unemployment.l5 
##     0.067925032    -0.012685006    -0.183030356     0.068785222     0.038700766 
##           const 
##     0.012796215

En conclusión se puede observar en la ultima grafica las prediciones entre ambas variables las cuales se puede observar que apesar de tener tendencias disfrentes tiene predicciones relacionadas.