R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

library(highcharter)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(bvartools)
## Cargando paquete requerido: coda
## Cargando paquete requerido: Matrix
library(forecast)
library(vars)
## Cargando paquete requerido: MASS
## Cargando paquete requerido: strucchange
## Cargando paquete requerido: zoo
## 
## Adjuntando el paquete: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Cargando paquete requerido: sandwich
## Cargando paquete requerido: urca
## Cargando paquete requerido: lmtest
## 
## Adjuntando el paquete: 'lmtest'
## The following object is masked from 'package:highcharter':
## 
##     unemployment
## 
## Adjuntando el paquete: 'vars'
## The following objects are masked from 'package:bvartools':
## 
##     fevd, irf
library(tseries)
library(urca)
library(readxl)
library(dplyr)
## 
## Adjuntando el paquete: 'dplyr'
## The following object is masked from 'package:MASS':
## 
##     select
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(colorspace)
# Configuración del directorio de trabajo
setwd("C:/Users/luisg/OneDrive/Escritorio/Tesis Cap 1 scrip")
df <- read_xlsx("BASE_VEC.xlsx", sheet = 2, col_names = TRUE)

# Estructura del dataframe
str(df)
## tibble [342 × 4] (S3: tbl_df/tbl/data.frame)
##  $ periodo    : POSIXct[1:342], format: "1996-01-01" "1996-02-01" ...
##  $ base_mon   : num [1:342] 57 57 57 57 57 ...
##  $ act_int_net: num [1:342] 57 57.9 58.5 57.8 58.6 ...
##  $ cin        : num [1:342] 57 56.9 56.9 56.9 56.9 ...
colnames(df)
## [1] "periodo"     "base_mon"    "act_int_net" "cin"
summary(df)
##     periodo                          base_mon       act_int_net   
##  Min.   :1996-01-01 00:00:00.00   Min.   : 56.99   Min.   : 57.0  
##  1st Qu.:2003-02-08 00:00:00.00   1st Qu.: 60.15   1st Qu.:164.4  
##  Median :2010-03-16 12:00:00.00   Median : 66.08   Median :309.4  
##  Mean   :2010-03-17 06:31:34.74   Mean   : 71.08   Mean   :407.2  
##  3rd Qu.:2017-04-23 12:00:00.00   3rd Qu.: 79.66   3rd Qu.:691.8  
##  Max.   :2024-06-01 00:00:00.00   Max.   :108.53   Max.   :950.8  
##       cin         
##  Min.   : 0.9193  
##  1st Qu.:22.8496  
##  Median :42.4308  
##  Mean   :37.6154  
##  3rd Qu.:49.8259  
##  Max.   :57.0000
head(df)
## # A tibble: 6 × 4
##   periodo             base_mon act_int_net   cin
##   <dttm>                 <dbl>       <dbl> <dbl>
## 1 1996-01-01 00:00:00     57          57    57  
## 2 1996-02-01 00:00:00     57.0        57.9  56.9
## 3 1996-03-01 00:00:00     57.0        58.5  56.9
## 4 1996-04-01 00:00:00     57.0        57.8  56.9
## 5 1996-05-01 00:00:00     57.0        58.6  56.9
## 6 1996-06-01 00:00:00     57.1        58.3  56.9
tail(df)
## # A tibble: 6 × 4
##   periodo             base_mon act_int_net   cin
##   <dttm>                 <dbl>       <dbl> <dbl>
## 1 2024-01-01 00:00:00     107.        782.  39.9
## 2 2024-02-01 00:00:00     108.        770.  42.1
## 3 2024-03-01 00:00:00     109.        747.  44.9
## 4 2024-04-01 00:00:00     107.        777.  40.8
## 5 2024-05-01 00:00:00     108.        778.  40.8
## 6 2024-06-01 00:00:00     108.        841.  34.7
valores <- df %>% dplyr::select(base_mon, act_int_net, cin)
plot(valores)

df_ts <- ts(df[c("act_int_net", "cin")], start = c(1996, 1), frequency = 12)
png("AIN_CIN.png", width = 800, height = 600)
plot(df_ts)
dev.off()
## png 
##   2
plot(df_ts)

colnames(df_ts)
## [1] "act_int_net" "cin"
print(df_ts)
##          act_int_net        cin
## Jan 1996    57.00000 57.0000000
## Feb 1996    57.87973 56.9102016
## Mar 1996    58.50433 56.8798450
## Apr 1996    57.80657 56.9051441
## May 1996    58.62242 56.8874379
## Jun 1996    58.31641 56.9382695
## Jul 1996    60.38088 56.7306504
## Aug 1996    61.34914 56.6248026
## Sep 1996    60.69349 56.7025293
## Oct 1996    62.83652 56.5373840
## Nov 1996    63.55730 56.5638294
## Dec 1996    64.74473 56.7233896
## Jan 1997    69.05787 56.1560341
## Feb 1997    71.91826 55.8569656
## Mar 1997    71.80941 55.9357797
## Apr 1997    74.84002 55.6038798
## May 1997    77.79477 55.3614595
## Jun 1997    77.60267 55.3740283
## Jul 1997    78.79332 55.3011371
## Aug 1997    80.55990 55.1195629
## Sep 1997    82.23247 54.9244216
## Oct 1997    85.91532 54.6308147
## Nov 1997    83.99663 54.9410137
## Dec 1997    86.48923 55.0312163
## Jan 1998    88.65374 54.6297387
## Feb 1998    88.60532 54.6130118
## Mar 1998    90.47672 54.3825645
## Apr 1998    91.94895 54.2939370
## May 1998    93.16251 54.2241942
## Jun 1998    93.36012 54.1629534
## Jul 1998    94.86885 54.0796985
## Aug 1998    96.27031 53.9146633
## Sep 1998    95.87470 53.9264749
## Oct 1998    98.19402 53.7919956
## Nov 1998    97.15113 53.9780258
## Dec 1998   100.29525 54.0863672
## Jan 1999   101.36669 53.7912517
## Feb 1999   101.24244 53.7501632
## Mar 1999    99.34353 54.0504938
## Apr 1999    98.82207 53.9811229
## May 1999   102.23268 53.7162464
## Jun 1999   101.79174 53.7559020
## Jul 1999   101.79673 53.8562330
## Aug 1999   103.70172 53.6333217
## Sep 1999   103.40036 53.6995461
## Oct 1999   104.64919 53.7006297
## Nov 1999   104.70363 53.8137497
## Dec 1999   105.57650 54.6459418
## Jan 2000   110.12469 53.5942809
## Feb 2000   110.21573 53.4517228
## Mar 2000   113.25828 53.2032543
## Apr 2000   111.52789 53.4876645
## May 2000   110.49312 53.5674351
## Jun 2000   111.44159 53.6219882
## Jul 2000   111.73985 53.5291857
## Aug 2000   113.87525 53.2309844
## Sep 2000   117.62482 52.9280482
## Oct 2000   120.50551 52.6682823
## Nov 2000   118.48372 53.1027829
## Dec 2000   121.26863 53.4675653
## Jan 2001   128.97337 52.1882563
## Feb 2001   128.54238 52.1234590
## Mar 2001   129.01123 52.0736731
## Apr 2001   127.29456 52.2153582
## May 2001   127.19017 52.2959543
## Jun 2001   126.66339 52.3951580
## Jul 2001   127.30992 52.2853629
## Aug 2001   128.38040 52.1906304
## Sep 2001   133.79345 51.7129310
## Oct 2001   132.68947 51.8077414
## Nov 2001   133.69669 51.9446859
## Dec 2001   134.40844 52.4751962
## Jan 2002   138.52854 51.7097978
## Feb 2002   138.10086 51.6651225
## Mar 2002   135.59348 52.1812630
## Apr 2002   136.74052 51.7820343
## May 2002   138.88404 51.7212242
## Jun 2002   142.60738 51.3992079
## Jul 2002   142.11264 51.4092186
## Aug 2002   144.03643 51.2260749
## Sep 2002   147.14244 50.9306671
## Oct 2002   145.42527 51.1575656
## Nov 2002   146.70878 51.2862701
## Dec 2002   156.93843 50.9601868
## Jan 2003   163.35123 49.9833092
## Feb 2003   165.52509 49.6789952
## Mar 2003   167.06556 49.4569265
## Apr 2003   164.28358 49.8454917
## May 2003   165.96807 49.7276216
## Jun 2003   166.05381 49.5987900
## Jul 2003   164.84062 49.7669508
## Aug 2003   169.84424 49.2673285
## Sep 2003   171.24951 49.0565875
## Oct 2003   174.57816 48.9002516
## Nov 2003   180.63822 48.5261341
## Dec 2003   182.51207 49.1672347
## Jan 2004   188.50379 48.0917284
## Feb 2004   189.20365 47.9308664
## Mar 2004   187.44672 47.9891865
## Apr 2004   187.40749 48.1006232
## May 2004   187.39054 48.1699030
## Jun 2004   188.96874 48.0544355
## Jul 2004   187.32470 48.2779313
## Aug 2004   188.65376 48.0533291
## Sep 2004   191.29138 47.8600646
## Oct 2004   190.20838 48.0519570
## Nov 2004   192.67549 47.9886419
## Dec 2004   192.52255 48.8645547
## Jan 2005   195.19145 48.1522936
## Feb 2005   191.58302 48.3330366
## Mar 2005   192.68786 48.3106146
## Apr 2005   188.74317 48.6110438
## May 2005   184.93240 49.0036380
## Jun 2005   190.82092 48.5399916
## Jul 2005   190.47718 48.5964690
## Aug 2005   196.53407 47.8172093
## Sep 2005   200.01834 47.5925881
## Oct 2005   202.44140 47.4271733
## Nov 2005   202.85682 47.5888875
## Dec 2005   206.24721 48.2545983
## Jan 2006   208.94407 47.5061184
## Feb 2006   206.80739 47.5611365
## Mar 2006   213.91870 46.9786748
## Apr 2006   221.91046 46.2733368
## May 2006   231.49729 45.3231835
## Jun 2006   238.60669 44.8250964
## Jul 2006   228.94742 45.7792787
## Aug 2006   230.00048 45.5748250
## Sep 2006   230.88433 45.5572062
## Oct 2006   215.25070 47.1350392
## Nov 2006   217.64246 47.4169178
## Dec 2006   213.26234 48.8806250
## Jan 2007   217.57055 47.6950256
## Feb 2007   219.29713 47.3268291
## Mar 2007   215.58485 47.8901669
## Apr 2007   217.66282 47.5093104
## May 2007   215.85627 47.8140799
## Jun 2007   216.36814 47.7915572
## Jul 2007   219.04705 47.5142332
## Aug 2007   223.31061 47.1401802
## Sep 2007   227.27708 46.7760316
## Oct 2007   226.87773 46.9024493
## Nov 2007   233.73291 46.5019224
## Dec 2007   237.52187 47.3180367
## Jan 2008   243.39794 46.0678052
## Feb 2008   240.77016 46.1043163
## Mar 2008   241.05221 46.0740204
## Apr 2008   241.97825 45.9399301
## May 2008   241.09774 46.1378555
## Jun 2008   240.84105 46.0932030
## Jul 2008   238.68352 46.6057244
## Aug 2008   246.33953 45.8339419
## Sep 2008   263.00803 44.0951975
## Oct 2008   261.97080 44.5606753
## Nov 2008   281.36763 43.1493028
## Dec 2008   307.11375 41.9612951
## Jan 2009   302.55984 41.9448814
## Feb 2009   314.94028 40.4550875
## Mar 2009   287.10877 43.1230833
## Apr 2009   278.29071 44.0676135
## May 2009   264.82014 45.3948867
## Jun 2009   260.67321 45.7132783
## Jul 2009   263.15111 45.6455850
## Aug 2009   270.92411 44.6522595
## Sep 2009   281.90499 43.4697079
## Oct 2009   278.12032 44.0312239
## Nov 2009   279.35070 44.1579585
## Dec 2009   304.74993 43.2307073
## Jan 2010   300.79561 43.0244887
## Feb 2010   299.58843 42.8362666
## Mar 2010   294.91214 43.5489471
## Apr 2010   298.73402 42.7351861
## May 2010   311.78501 41.5926906
## Jun 2010   314.54619 41.2265569
## Jul 2010   320.17681 40.9576419
## Aug 2010   336.09053 39.2013774
## Sep 2010   329.13998 39.9909496
## Oct 2010   329.54394 39.9652823
## Nov 2010   335.10479 39.7088793
## Dec 2010   339.96344 40.8901536
## Jan 2011   342.22311 39.8037617
## Feb 2011   347.90024 39.0535625
## Mar 2011   347.24012 39.0515452
## Apr 2011   344.52356 39.5282843
## May 2011   345.59047 39.2705281
## Jun 2011   355.28907 38.2618534
## Jul 2011   366.08910 37.3827675
## Aug 2011   393.64724 34.4427653
## Sep 2011   427.22881 31.2509242
## Oct 2011   422.27655 31.9006407
## Nov 2011   437.96048 30.7942141
## Dec 2011   452.80729 30.9859622
## Jan 2012   438.23358 31.7005196
## Feb 2012   433.96174 31.8743472
## Mar 2012   436.88225 31.8190065
## Apr 2012   450.78102 30.5946718
## May 2012   488.60029 27.0330154
## Jun 2012   472.00288 28.7965218
## Jul 2012   474.21638 28.5458367
## Aug 2012   473.97850 28.3959039
## Sep 2012   462.32422 29.3759963
## Oct 2012   473.81254 28.4532752
## Nov 2012   470.77883 29.1043485
## Dec 2012   468.96857 30.9432360
## Jan 2013   470.98671 29.6241403
## Feb 2013   474.46998 29.1116284
## Mar 2013   459.72376 31.0563541
## Apr 2013   455.92829 30.6968323
## May 2013   471.23932 29.3162471
## Jun 2013   475.54659 28.9072886
## Jul 2013   479.27980 28.4647509
## Aug 2013   497.39554 26.6562600
## Sep 2013   495.59625 26.8465981
## Oct 2013   495.34494 27.0642924
## Nov 2013   503.90936 27.0000664
## Dec 2013   505.54325 28.6657848
## Jan 2014   522.74715 26.0282653
## Feb 2014   519.81631 26.2297395
## Mar 2014   517.64061 26.3258764
## Apr 2014   527.30447 25.6506521
## May 2014   523.35461 26.0896674
## Jun 2014   532.16871 25.2174970
## Jul 2014   542.44645 24.4092129
## Aug 2014   538.10875 24.8243259
## Sep 2014   551.15012 23.4663090
## Oct 2014   562.27620 22.8420302
## Nov 2014   577.21322 22.0444380
## Dec 2014   605.98197 21.4189029
## Jan 2015   625.14335 18.7870045
## Feb 2015   621.20578 19.1924674
## Mar 2015   631.56790 18.8979516
## Apr 2015   637.21842 17.9958932
## May 2015   632.13552 18.7205657
## Jun 2015   637.08752 18.1609019
## Jul 2015   648.63552 17.3728403
## Aug 2015   654.90074 16.8670465
## Sep 2015   642.39714 17.9899115
## Oct 2015   614.05402 21.2361672
## Nov 2015   602.06327 22.8722160
## Dec 2015   640.06096 21.4193014
## Jan 2016   667.63016 17.9546757
## Feb 2016   671.76048 17.2953566
## Mar 2016   646.60033 20.2493699
## Apr 2016   652.42760 19.4122930
## May 2016   685.60363 16.5362701
## Jun 2016   685.57585 16.8055532
## Jul 2016   699.39965 15.7282725
## Aug 2016   695.52118 15.9739893
## Sep 2016   722.87047 13.3761918
## Oct 2016   692.91721 16.6394477
## Nov 2016   744.08615 12.3042703
## Dec 2016   755.87891 13.2783773
## Jan 2017   756.39411 12.5158520
## Feb 2017   741.27529 13.7376342
## Mar 2017   696.39929 18.2471325
## Apr 2017   694.91469 18.5627685
## May 2017   683.61821 19.6171793
## Jun 2017   660.03235 21.8892845
## Jul 2017   653.02011 22.5761573
## Aug 2017   649.39660 22.6306288
## Sep 2017   661.50644 21.4793542
## Oct 2017   700.13878 17.9129875
## Nov 2017   673.71097 21.2306049
## Dec 2017   713.74906 19.8573641
## Jan 2018   692.12145 20.8187750
## Feb 2018   693.77449 20.5714091
## Mar 2018   674.67526 23.2955957
## Apr 2018   690.78411 21.1948301
## May 2018   735.50705 17.0135197
## Jun 2018   724.29902 18.5870903
## Jul 2018   683.86971 22.5050613
## Aug 2018   701.42531 20.5932656
## Sep 2018   687.98406 21.7264525
## Oct 2018   740.03384 16.9139288
## Nov 2018   740.95303 17.5380578
## Dec 2018   716.85318 21.9827247
## Jan 2019   710.64137 21.2626960
## Feb 2019   720.71307 19.7924587
## Mar 2019   728.67067 18.6599758
## Apr 2019   725.26902 19.1988344
## May 2019   750.40362 16.7510931
## Jun 2019   737.95568 17.9915587
## Jul 2019   736.59608 17.8721230
## Aug 2019   780.55441 13.6504357
## Sep 2019   744.22845 17.0180743
## Oct 2019   728.33993 18.7267638
## Nov 2019   746.13352 18.0654539
## Dec 2019   714.28202 23.5341768
## Jan 2020   737.91121 20.3318543
## Feb 2020   766.38755 16.9780315
## Mar 2020   905.75924  5.0044503
## Apr 2020   950.84755  0.9192558
## May 2020   890.68773  8.0286866
## Jun 2020   923.32142  4.8988663
## Jul 2020   893.51047  8.9591734
## Aug 2020   884.81642  9.8299243
## Sep 2020   899.45810  8.0564737
## Oct 2020   861.00789 12.3046347
## Nov 2020   828.78041 16.8425710
## Dec 2020   811.43732 20.9932781
## Jan 2021   839.35346 17.9004661
## Feb 2021   855.17627 16.0689913
## Mar 2021   832.55519 20.0286221
## Apr 2021   832.75359 19.4434941
## May 2021   815.94906 21.0941405
## Jun 2021   812.86810 21.5682739
## Jul 2021   814.37365 21.8308220
## Aug 2021   865.44001 16.6789420
## Sep 2021   886.97791 15.0042681
## Oct 2021   884.04710 15.8016609
## Nov 2021   925.75952 12.8108765
## Dec 2021   866.52110 21.6305339
## Jan 2022   880.97793 20.0562497
## Feb 2022   873.67646 20.8757857
## Mar 2022   851.44155 24.4786008
## Apr 2022   860.26719 22.8914498
## May 2022   829.47646 25.7569230
## Jun 2022   837.28627 24.8138560
## Jul 2022   845.43618 24.6512688
## Aug 2022   841.64633 24.4713874
## Sep 2022   830.01395 26.0274986
## Oct 2022   816.26863 27.6182591
## Nov 2022   803.64711 29.8910608
## Dec 2022   802.32222 32.9418715
## Jan 2023   794.86913 32.9864139
## Feb 2023   771.64678 34.8614595
## Mar 2023   765.22397 36.2766579
## Apr 2023   768.21808 35.6334469
## May 2023   757.46576 37.1023331
## Jun 2023   743.04058 38.5563427
## Jul 2023   729.23924 40.4285378
## Aug 2023   734.25823 39.3433757
## Sep 2023   751.43206 38.0607683
## Oct 2023   774.09661 36.1021338
## Nov 2023   753.94228 39.2761113
## Dec 2023   747.17050 43.3744686
## Jan 2024   781.83431 39.8696616
## Feb 2024   769.90480 42.1264897
## Mar 2024   747.45627 44.9186030
## Apr 2024   777.26696 40.7562588
## May 2024   778.48315 40.8139565
## Jun 2024   841.33920 34.6593856
#PRUEBA DE ESTACIONARIEDAD
#R>ain
#DP>cin
#ain = act_int_net
#cin = cin
adf.ain<- ur.df(df_ts[,1], type = "trend", selectlags = "BIC")
summary(adf.ain) 
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression trend 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -57.441  -5.730  -0.738   3.824 137.834 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -0.337330   1.992808  -0.169   0.8657  
## z.lag.1     -0.033571   0.013330  -2.518   0.0123 *
## tt           0.095044   0.037201   2.555   0.0111 *
## z.diff.lag   0.001445   0.055443   0.026   0.9792  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 16.82 on 336 degrees of freedom
## Multiple R-squared:  0.01934,    Adjusted R-squared:  0.01059 
## F-statistic: 2.209 on 3 and 336 DF,  p-value: 0.08687
## 
## 
## Value of test-statistic is: -2.5184 4.3346 3.2796 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau3 -3.98 -3.42 -3.13
## phi2  6.15  4.71  4.05
## phi3  8.34  6.30  5.36
png("residuales_ain.png", width = 800, height = 600)
plot(adf.ain)
dev.off()
## png 
##   2
adf.test(df_ts[,1])
## 
##  Augmented Dickey-Fuller Test
## 
## data:  df_ts[, 1]
## Dickey-Fuller = -2.2063, Lag order = 6, p-value = 0.4897
## alternative hypothesis: stationary
pp.test(df_ts[,1])
## 
##  Phillips-Perron Unit Root Test
## 
## data:  df_ts[, 1]
## Dickey-Fuller Z(alpha) = -10.807, Truncation lag parameter = 5, p-value
## = 0.5049
## alternative hypothesis: stationary
adf.cin <- ur.df(df_ts[,2], type = "trend", selectlags = "BIC")
summary(adf.cin)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression trend 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -12.2981  -0.5910   0.0505   0.4751   8.4693 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.829975   0.825767   1.005    0.316
## z.lag.1     -0.017780   0.013459  -1.321    0.187
## tt          -0.001342   0.001991  -0.674    0.501
## z.diff.lag  -0.055323   0.056311  -0.982    0.327
## 
## Residual standard error: 1.795 on 336 degrees of freedom
## Multiple R-squared:  0.01196,    Adjusted R-squared:  0.00314 
## F-statistic: 1.356 on 3 and 336 DF,  p-value: 0.2562
## 
## 
## Value of test-statistic is: -1.3211 1.0442 1.3181 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau3 -3.98 -3.42 -3.13
## phi2  6.15  4.71  4.05
## phi3  8.34  6.30  5.36
adf.test(df_ts[,2])
## 
##  Augmented Dickey-Fuller Test
## 
## data:  df_ts[, 2]
## Dickey-Fuller = -0.57528, Lag order = 6, p-value = 0.9781
## alternative hypothesis: stationary
png("residuales_cin.png", width = 800, height = 600)
plot(adf.cin)
dev.off()
## png 
##   2
pp.test(df_ts[,2])
## 
##  Phillips-Perron Unit Root Test
## 
## data:  df_ts[, 2]
## Dickey-Fuller Z(alpha) = -5.4415, Truncation lag parameter = 5, p-value
## = 0.8055
## alternative hypothesis: stationary
diff.adf.ain <- ur.df(diff(df_ts[,1]), type = "trend", selectlags = "BIC")
summary(diff.adf.ain) 
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression trend 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -61.712  -4.722  -0.809   3.759 137.609 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.668205   1.864624   0.895    0.372    
## z.lag.1     -1.045744   0.079256 -13.195   <2e-16 ***
## tt           0.004317   0.009433   0.458    0.647    
## z.diff.lag   0.030811   0.055660   0.554    0.580    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 17 on 335 degrees of freedom
## Multiple R-squared:  0.4983, Adjusted R-squared:  0.4938 
## F-statistic: 110.9 on 3 and 335 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -13.1945 58.0793 87.0991 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau3 -3.98 -3.42 -3.13
## phi2  6.15  4.71  4.05
## phi3  8.34  6.30  5.36
png("residuales_ain_dif.png", width = 800, height = 600)
plot(diff.adf.ain)
dev.off()
## png 
##   2
diff.adf.cin <- ur.df(diff(df_ts[,2]), type = "trend", selectlags = "BIC")
summary(diff.adf.cin) 
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression trend 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -12.4085  -0.5749   0.0559   0.4713   8.5699 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.242976   0.197880  -1.228    0.220    
## z.lag.1     -1.117582   0.081332 -13.741   <2e-16 ***
## tt           0.001005   0.001004   1.001    0.317    
## z.diff.lag   0.044980   0.055598   0.809    0.419    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.8 on 335 degrees of freedom
## Multiple R-squared:  0.5266, Adjusted R-squared:  0.5223 
## F-statistic: 124.2 on 3 and 335 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -13.7409 62.9821 94.4565 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau3 -3.98 -3.42 -3.13
## phi2  6.15  4.71  4.05
## phi3  8.34  6.30  5.36
png("residuales_cin_dif.png", width = 800, height = 600)
plot(diff.adf.cin)
dev.off()
## png 
##   2
acf(df_ts[,2])

acf(df_ts[,1])

adf.test(diff(df_ts[,1]))
## Warning in adf.test(diff(df_ts[, 1])): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff(df_ts[, 1])
## Dickey-Fuller = -7.4897, Lag order = 6, p-value = 0.01
## alternative hypothesis: stationary
adf.test(diff(df_ts[,2]))
## Warning in adf.test(diff(df_ts[, 2])): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  diff(df_ts[, 2])
## Dickey-Fuller = -7.1785, Lag order = 6, p-value = 0.01
## alternative hypothesis: stationary
#Una vez las series son estacionarias, se procede a realiza la estimacion

var_aic <- VARselect(df_ts,lag.max=10, type = "both")
VARselect(df_ts)
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      9      1      1      9 
## 
## $criteria
##                 1          2          3          4          5          6
## AIC(n)   4.732936   4.737250   4.723125   4.740606   4.678385   4.682729
## HQ(n)    4.760360   4.782957   4.787115   4.822879   4.778942   4.801568
## SC(n)    4.801704   4.851862   4.883582   4.946909   4.930533   4.980722
## FPE(n) 113.628804 114.120421 112.520694 114.506626 107.601420 108.073250
##                 7          8          9         10
## AIC(n)   4.666599   4.675922   4.646450   4.653435
## HQ(n)    4.803721   4.831327   4.820138   4.845406
## SC(n)    5.010437   5.065605   5.081978   5.134807
## FPE(n) 106.348598 107.350752 104.240483 104.980328
var_aic
## $selection
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      9      1      1      9 
## 
## $criteria
##                 1          2          3          4          5          6
## AIC(n)   4.722757   4.725431   4.711860   4.730710   4.668572   4.670862
## HQ(n)    4.759323   4.780279   4.784992   4.822124   4.778270   4.798843
## SC(n)    4.814447   4.862966   4.895240   4.959935   4.943642   4.991777
## FPE(n) 112.478233 112.779931 111.261014 113.380108 106.552206 106.800488
##                 7          8          9         10
## AIC(n)   4.652956   4.665148   4.631101   4.637564
## HQ(n)    4.799220   4.829694   4.813931   4.838677
## SC(n)    5.019716   5.077753   5.089551   5.141859
## FPE(n) 104.910320 106.203862 102.656976 103.332641
#SI USAMOS 1 REZAGO NOS ENFOCAMOS EN CORTO PLAZO
p1ctCcp <- VAR(df_ts, p = 1, type = "both")
p1ctCcp
## 
## VAR Estimation Results:
## ======================= 
## 
## Estimated coefficients for equation act_int_net: 
## ================================================ 
## Call:
## act_int_net = act_int_net.l1 + cin.l1 + const + trend 
## 
## act_int_net.l1         cin.l1          const          trend 
##      0.9583741     -0.1144743      5.9498751      0.1020572 
## 
## 
## Estimated coefficients for equation cin: 
## ======================================== 
## Call:
## cin = act_int_net.l1 + cin.l1 + const + trend 
## 
## act_int_net.l1         cin.l1          const          trend 
##     0.00487331     1.01083420    -0.57376472    -0.01091586
#SI USAMOS 9 REZAGO NOS ENFOCAMOS EN LARGO PLAZO
p1ct <- VAR(df_ts, p = 9, type = "both")
p1ct
## 
## VAR Estimation Results:
## ======================= 
## 
## Estimated coefficients for equation act_int_net: 
## ================================================ 
## Call:
## act_int_net = act_int_net.l1 + cin.l1 + act_int_net.l2 + cin.l2 + act_int_net.l3 + cin.l3 + act_int_net.l4 + cin.l4 + act_int_net.l5 + cin.l5 + act_int_net.l6 + cin.l6 + act_int_net.l7 + cin.l7 + act_int_net.l8 + cin.l8 + act_int_net.l9 + cin.l9 + const + trend 
## 
## act_int_net.l1         cin.l1 act_int_net.l2         cin.l2 act_int_net.l3 
##     1.10467196     1.00680789    -0.24833570    -1.63360847    -0.01834409 
##         cin.l3 act_int_net.l4         cin.l4 act_int_net.l5         cin.l5 
##    -0.89383967     0.04972487     2.58659754     0.26370768    -0.62599779 
## act_int_net.l6         cin.l6 act_int_net.l7         cin.l7 act_int_net.l8 
##    -0.23926824     0.02284574    -0.23913372    -3.40174775     0.34222311 
##         cin.l8 act_int_net.l9         cin.l9          const          trend 
##     4.13188424    -0.06438929    -1.49328166    16.98466332     0.09824562 
## 
## 
## Estimated coefficients for equation cin: 
## ======================================== 
## Call:
## cin = act_int_net.l1 + cin.l1 + act_int_net.l2 + cin.l2 + act_int_net.l3 + cin.l3 + act_int_net.l4 + cin.l4 + act_int_net.l5 + cin.l5 + act_int_net.l6 + cin.l6 + act_int_net.l7 + cin.l7 + act_int_net.l8 + cin.l8 + act_int_net.l9 + cin.l9 + const + trend 
## 
## act_int_net.l1         cin.l1 act_int_net.l2         cin.l2 act_int_net.l3 
##    -0.02292881     0.74372183     0.01126177     0.02209318     0.02297041 
##         cin.l3 act_int_net.l4         cin.l4 act_int_net.l5         cin.l5 
##     0.30427220    -0.02167284    -0.46344765    -0.01286079     0.25920581 
## act_int_net.l6         cin.l6 act_int_net.l7         cin.l7 act_int_net.l8 
##     0.01215320    -0.13304440     0.04130381     0.51830187    -0.04621288 
##         cin.l8 act_int_net.l9         cin.l9          const          trend 
##    -0.55779646     0.02418871     0.36284119    -3.24500856    -0.01211276
summary(p1ct, equation = "act_int_net")
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: act_int_net, cin 
## Deterministic variables: both 
## Sample size: 333 
## Log Likelihood: -1675.012 
## Roots of the characteristic polynomial:
## 1.007 0.9873 0.8786 0.8786 0.8576 0.8576 0.8289 0.8289 0.8012 0.8012 0.7717 0.7717 0.7715 0.7715 0.741 0.741 0.5132 0.5132
## Call:
## VAR(y = df_ts, p = 9, type = "both")
## 
## 
## Estimation results for equation act_int_net: 
## ============================================ 
## act_int_net = act_int_net.l1 + cin.l1 + act_int_net.l2 + cin.l2 + act_int_net.l3 + cin.l3 + act_int_net.l4 + cin.l4 + act_int_net.l5 + cin.l5 + act_int_net.l6 + cin.l6 + act_int_net.l7 + cin.l7 + act_int_net.l8 + cin.l8 + act_int_net.l9 + cin.l9 + const + trend 
## 
##                Estimate Std. Error t value Pr(>|t|)    
## act_int_net.l1  1.10467    0.16746   6.597 1.79e-10 ***
## cin.l1          1.00681    1.60668   0.627   0.5314    
## act_int_net.l2 -0.24834    0.22669  -1.095   0.2742    
## cin.l2         -1.63361    2.10431  -0.776   0.4381    
## act_int_net.l3 -0.01834    0.22722  -0.081   0.9357    
## cin.l3         -0.89384    2.10367  -0.425   0.6712    
## act_int_net.l4  0.04972    0.22859   0.218   0.8279    
## cin.l4          2.58660    2.13043   1.214   0.2256    
## act_int_net.l5  0.26371    0.22834   1.155   0.2490    
## cin.l5         -0.62600    2.11999  -0.295   0.7680    
## act_int_net.l6 -0.23927    0.22859  -1.047   0.2960    
## cin.l6          0.02285    2.12451   0.011   0.9914    
## act_int_net.l7 -0.23913    0.23135  -1.034   0.3021    
## cin.l7         -3.40175    2.15443  -1.579   0.1154    
## act_int_net.l8  0.34222    0.23434   1.460   0.1452    
## cin.l8          4.13188    2.18511   1.891   0.0596 .  
## act_int_net.l9 -0.06439    0.17496  -0.368   0.7131    
## cin.l9         -1.49328    1.69947  -0.879   0.3803    
## const          16.98466   12.85538   1.321   0.1874    
## trend           0.09825    0.04182   2.349   0.0194 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 16.66 on 313 degrees of freedom
## Multiple R-Squared: 0.9965,  Adjusted R-squared: 0.9963 
## F-statistic:  4674 on 19 and 313 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##             act_int_net     cin
## act_int_net      277.49 -27.072
## cin              -27.07   2.968
## 
## Correlation matrix of residuals:
##             act_int_net     cin
## act_int_net      1.0000 -0.9433
## cin             -0.9433  1.0000
#LOS RESULTADOS MUESTRAN QUE EL AJUSTE ES BUENO PERO PUEDE ESTAR SOBREESTIMADO
png("adf_plot5.png", width = 800, height = 600)
plot(p1ct, names = "act_int_net")
dev.off()
## png 
##   2
summary(p1ct, equation = "cin")
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: act_int_net, cin 
## Deterministic variables: both 
## Sample size: 333 
## Log Likelihood: -1675.012 
## Roots of the characteristic polynomial:
## 1.007 0.9873 0.8786 0.8786 0.8576 0.8576 0.8289 0.8289 0.8012 0.8012 0.7717 0.7717 0.7715 0.7715 0.741 0.741 0.5132 0.5132
## Call:
## VAR(y = df_ts, p = 9, type = "both")
## 
## 
## Estimation results for equation cin: 
## ==================================== 
## cin = act_int_net.l1 + cin.l1 + act_int_net.l2 + cin.l2 + act_int_net.l3 + cin.l3 + act_int_net.l4 + cin.l4 + act_int_net.l5 + cin.l5 + act_int_net.l6 + cin.l6 + act_int_net.l7 + cin.l7 + act_int_net.l8 + cin.l8 + act_int_net.l9 + cin.l9 + const + trend 
## 
##                 Estimate Std. Error t value Pr(>|t|)    
## act_int_net.l1 -0.022929   0.017320  -1.324  0.18653    
## cin.l1          0.743722   0.166174   4.476 1.07e-05 ***
## act_int_net.l2  0.011262   0.023446   0.480  0.63134    
## cin.l2          0.022093   0.217643   0.102  0.91921    
## act_int_net.l3  0.022970   0.023501   0.977  0.32912    
## cin.l3          0.304272   0.217577   1.398  0.16297    
## act_int_net.l4 -0.021673   0.023642  -0.917  0.36000    
## cin.l4         -0.463448   0.220345  -2.103  0.03624 *  
## act_int_net.l5 -0.012861   0.023616  -0.545  0.58643    
## cin.l5          0.259206   0.219265   1.182  0.23804    
## act_int_net.l6  0.012153   0.023642   0.514  0.60758    
## cin.l6         -0.133044   0.219733  -0.605  0.54530    
## act_int_net.l7  0.041304   0.023928   1.726  0.08531 .  
## cin.l7          0.518302   0.222827   2.326  0.02066 *  
## act_int_net.l8 -0.046213   0.024237  -1.907  0.05748 .  
## cin.l8         -0.557796   0.226000  -2.468  0.01412 *  
## act_int_net.l9  0.024189   0.018095   1.337  0.18228    
## cin.l9          0.362841   0.175772   2.064  0.03982 *  
## const          -3.245009   1.329598  -2.441  0.01522 *  
## trend          -0.012113   0.004325  -2.801  0.00542 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 1.723 on 313 degrees of freedom
## Multiple R-Squared: 0.9864,  Adjusted R-squared: 0.9856 
## F-statistic:  1198 on 19 and 313 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##             act_int_net     cin
## act_int_net      277.49 -27.072
## cin              -27.07   2.968
## 
## Correlation matrix of residuals:
##             act_int_net     cin
## act_int_net      1.0000 -0.9433
## cin             -0.9433  1.0000
png("adf_plot6.png", width = 800, height = 600)
plot(p1ct , name="cin")
dev.off()
## png 
##   2
names(p1ct$varresult)
## [1] "act_int_net" "cin"
ser11 <- serial.test(p1ct, lags.pt = 10, type = "PT.asymptotic")
ser11$serial
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object p1ct
## Chi-squared = 33.732, df = 4, p-value = 8.456e-07
norm1 <-normality.test(p1ct)
norm1$jb.mul
## $JB
## 
##  JB-Test (multivariate)
## 
## data:  Residuals of VAR object p1ct
## Chi-squared = 5319.5, df = 4, p-value < 2.2e-16
## 
## 
## $Skewness
## 
##  Skewness only (multivariate)
## 
## data:  Residuals of VAR object p1ct
## Chi-squared = 387.37, df = 2, p-value < 2.2e-16
## 
## 
## $Kurtosis
## 
##  Kurtosis only (multivariate)
## 
## data:  Residuals of VAR object p1ct
## Chi-squared = 4932.2, df = 2, p-value < 2.2e-16
arch1 <- arch.test(p1ct, lags.multi = 9)
arch1$arch.mul
## 
##  ARCH (multivariate)
## 
## data:  Residuals of VAR object p1ct
## Chi-squared = 210.06, df = 81, p-value = 2.091e-13
plot(arch1, names = "act_int_net")

plot(stability(p1ct), nc = 2)

vec <- ca.jo(df_ts, ecdet = "none", type = "trace",
             K = 4, spec = "transitory", season = 4)
summary(vec)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 5.622967e-02 2.834612e-05
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 1 |  0.01  6.50  8.18 11.65
## r = 0  | 19.57 15.66 17.95 23.52
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##                act_int_net.l1   cin.l1
## act_int_net.l1       1.000000  1.00000
## cin.l1               5.526244 21.25998
## 
## Weights W:
## (This is the loading matrix)
## 
##               act_int_net.l1        cin.l1
## act_int_net.d   0.0006946586  7.931634e-04
## cin.d           0.0006741948 -7.984191e-05
class(vec)
## [1] "ca.jo"
## attr(,"package")
## [1] "urca"
var <- vec2var(vec, r = 1)
var
## 
## Coefficient matrix of lagged endogenous variables:
## 
## A1:
##             act_int_net.l1    cin.l1
## act_int_net     1.06838034 0.8261167
## cin            -0.01258539 0.8074789
## 
## 
## A2:
##             act_int_net.l2     cin.l2
## act_int_net    -0.28112513 -2.7472436
## cin             0.03126265  0.3314435
## 
## 
## A3:
##             act_int_net.l3      cin.l3
## act_int_net    0.123704835 0.932865766
## cin           -0.004561111 0.009600664
## 
## 
## A4:
##             act_int_net.l4     cin.l4
## act_int_net     0.08973462  0.9921000
## cin            -0.01344195 -0.1447972
## 
## 
## Coefficient matrix of deterministic regressor(s).
## 
##               constant        sd1        sd2        sd3
## act_int_net  2.2932971 -0.6346339 -2.1840369 -4.1586653
## cin         -0.5148073 -0.5282285 -0.2761127  0.2232081
class(var)
## [1] "vec2var"
var1<-cajorls(vec, r=1)
var1
## $rlm
## 
## Call:
## lm(formula = substitute(form1), data = data.mat)
## 
## Coefficients:
##                  act_int_net.d  cin.d     
## ect1              0.0006947      0.0006742
## constant          2.2932971     -0.5148073
## sd1              -0.6346339     -0.5282285
## sd2              -2.1840369     -0.2761127
## sd3              -4.1586653      0.2232081
## act_int_net.dl1   0.0676857     -0.0132596
## cin.dl1           0.8222778     -0.1962469
## act_int_net.dl2  -0.2134395      0.0180031
## cin.dl2          -1.9249658      0.1351966
## act_int_net.dl3  -0.0897346      0.0134420
## cin.dl3          -0.9921000      0.1447972
## 
## 
## $beta
##                    ect1
## act_int_net.l1 1.000000
## cin.l1         5.526244
ser11 <- serial.test(var, lags.pt = 9, type = "PT.asymptotic")
ser11$serial
## 
##  Portmanteau Test (asymptotic)
## 
## data:  Residuals of VAR object var
## Chi-squared = 107.68, df = 22, p-value = 2.855e-13
norm1 <-normality.test(var)
norm1$jb.mul
## $JB
## 
##  JB-Test (multivariate)
## 
## data:  Residuals of VAR object var
## Chi-squared = 4187.3, df = 4, p-value < 2.2e-16
## 
## 
## $Skewness
## 
##  Skewness only (multivariate)
## 
## data:  Residuals of VAR object var
## Chi-squared = 296.66, df = 2, p-value < 2.2e-16
## 
## 
## $Kurtosis
## 
##  Kurtosis only (multivariate)
## 
## data:  Residuals of VAR object var
## Chi-squared = 3890.7, df = 2, p-value < 2.2e-16
arch1 <- arch.test(var, lags.multi = 9)
arch1$arch.mul
## 
##  ARCH (multivariate)
## 
## data:  Residuals of VAR object var
## Chi-squared = 195.65, df = 81, p-value = 1.77e-11
plot(arch1, names = "act_int_net")
## Warning in plot.varcheck(arch1, names = "act_int_net"): 
## Invalid residual name(s) supplied, using residuals of first variable.

#plot(vars::stability(var), nc = 2)
ir <- vars::irf(var, n.ahead = 20, impulse = "act_int_net", response = "cin")

plot(ir)

ir1 <- vars::irf(var, n.ahead = 20, impulse = "cin", response = "act_int_net")

plot(ir1)

fevd.R <- vars::fevd(var, n.ahead =9)
plot(fevd.R)

predictions <- predict(var, n.ahead = 9, ci = 0.95)
plot(predictions)

rt=df_ts[,1] -3.9619*df_ts[,2]
plot(rt)

adf.test(rt)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  rt
## Dickey-Fuller = -1.9946, Lag order = 6, p-value = 0.579
## alternative hypothesis: stationary
pp.test(rt)
## 
##  Phillips-Perron Unit Root Test
## 
## data:  rt
## Dickey-Fuller Z(alpha) = -10.943, Truncation lag parameter = 5, p-value
## = 0.4973
## alternative hypothesis: stationary
summary(ur.df(rt))
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression none 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -95.105  -4.201   1.218   7.794 186.048 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## z.lag.1     0.002422   0.003113   0.778    0.437
## z.diff.lag -0.022306   0.055622  -0.401    0.689
## 
## Residual standard error: 23.87 on 338 degrees of freedom
## Multiple R-squared:  0.002126,   Adjusted R-squared:  -0.003779 
## F-statistic:  0.36 on 2 and 338 DF,  p-value: 0.6979
## 
## 
## Value of test-statistic is: 0.7779 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62

Normalizacion de los errores

# Instalar y cargar el paquete 'rugarch' si aún no lo has hecho

library(rugarch)
## Cargando paquete requerido: parallel
## 
## Adjuntando el paquete: 'rugarch'
## The following object is masked from 'package:stats':
## 
##     sigma
# Extraer residuos del modelo VAR
residuos <- residuals(var)

# Ajustar un modelo GARCH(1,1) para los residuos
garch_spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 1)),
                         mean.model = list(armaOrder = c(0, 0)),
                         distribution.model = "norm")

# Ajustar el modelo a los residuos
garch_fit <- ugarchfit(spec = garch_spec, data = residuos[,1])
summary(garch_fit)
##    Length     Class      Mode 
##         1 uGARCHfit        S4
# Para la variable 'cin', ajustar otro modelo GARCH si es necesario
garch_fit_cin <- ugarchfit(spec = garch_spec, data = residuos[,2])
summary(garch_fit_cin)
##    Length     Class      Mode 
##         1 uGARCHfit        S4
# Diagnósticos del modelo GARCH para 'act_int_net'
plot(garch_fit, which = "all")
## 
## please wait...calculating quantiles...

#Diagnósticos del modelo GARCH para 'cin'
plot(garch_fit_cin, which = "all")
## 
## please wait...calculating quantiles...

# Predicciones para 'act_int_net'
forecast_garch_fit <- ugarchforecast(garch_fit, n.ahead = 10)
plot(forecast_garch_fit, which = 1)

# Predicciones para 'cin'
forecast_garch_fit_cin <- ugarchforecast(garch_fit_cin, n.ahead = 10)
plot(forecast_garch_fit_cin, which = 1)

# Guardar el resumen del modelo GARCH para 'act_int_net'
sink("garch_fit_act_int_net_summary.txt")
print(summary(garch_fit))
##    Length     Class      Mode 
##         1 uGARCHfit        S4
sink()

# Guardar el resumen del modelo GARCH para 'cin'
sink("garch_fit_cin_summary.txt")
print(summary(garch_fit_cin))
##    Length     Class      Mode 
##         1 uGARCHfit        S4
sink()
# Guardar gráficos
png("garch_fit_act_int_net_plot.png", width = 800, height = 600)
plot(garch_fit, which = "all")
## 
## please wait...calculating quantiles...
dev.off()
## png 
##   2
png("garch_fit_cin_plot.png", width = 800, height = 600)
plot(garch_fit_cin, which = "all")
## 
## please wait...calculating quantiles...
dev.off()
## png 
##   2
summary(garch_fit)
##    Length     Class      Mode 
##         1 uGARCHfit        S4
summary(garch_fit_cin)
##    Length     Class      Mode 
##         1 uGARCHfit        S4
#Solo nos arroja la clasificacion de los datos
# Parámetros del modelo para act_int_net
coef(garch_fit)
##            mu         omega        alpha1         beta1 
## -1.243529e-11  1.358603e+00  2.768494e-01  7.221497e-01
# Parámetros del modelo para cin
coef(garch_fit_cin)
##           mu        omega       alpha1        beta1 
## 1.140483e-13 1.581597e-02 2.372203e-01 7.607179e-01
# Para act_int_net
info_garch_fit <- infocriteria(garch_fit)
cat("Log-Likelihood para act_int_net:", info_garch_fit["LogLikelihood"], "\n")
## Log-Likelihood para act_int_net: NA
cat("AIC para act_int_net:", info_garch_fit["Akaike"], "\n")
## AIC para act_int_net: NA
cat("BIC para act_int_net:", info_garch_fit["Bayesian"], "\n")
## BIC para act_int_net: NA
# Para cin
info_garch_fit_cin <- infocriteria(garch_fit_cin)
cat("Log-Likelihood para cin:", info_garch_fit_cin["LogLikelihood"], "\n")
## Log-Likelihood para cin: NA
cat("AIC para cin:", info_garch_fit_cin["Akaike"], "\n")
## AIC para cin: NA
cat("BIC para cin:", info_garch_fit_cin["Bayesian"], "\n")
## BIC para cin: NA
# Log-Likelihood
#logLik(garch_fit)
#logLik(garch_fit_cin)

# Akaike Information Criterion (AIC)
#AIC(garch_fit)
#AIC(garch_fit_cin)

# Bayesian Information Criterion (BIC)
#BIC(garch_fit)
#BIC(garch_fit_cin)
# Verificar los métodos disponibles para el objeto garch_fit
methods(class = "uGARCHfit")
##  [1] coef               confint            convergence        fitted            
##  [5] getspec            gof                halflife           infocriteria      
##  [9] likelihood         newsimpact         nyblom             persistence       
## [13] pit                plot               quantile           reduce            
## [17] residuals          show               sigma              signbias          
## [21] ugarchboot         ugarchdistribution ugarchforecast     ugarchsim         
## [25] uncmean            uncvariance        vcov              
## see '?methods' for accessing help and source code
# Obtener detalles completos del modelo GARCH para act_int_net
summary(garch_fit)
##    Length     Class      Mode 
##         1 uGARCHfit        S4
# Obtener detalles completos del modelo GARCH para cin
summary(garch_fit_cin)
##    Length     Class      Mode 
##         1 uGARCHfit        S4
info_garch_fit <- infocriteria(garch_fit)
print(info_garch_fit)
##                      
## Akaike       7.361618
## Bayes        7.406861
## Shibata      7.361342
## Hannan-Quinn 7.379649
info_garch_fit_cin <- infocriteria(garch_fit_cin)
print(info_garch_fit_cin)
##                      
## Akaike       2.980786
## Bayes        3.026029
## Shibata      2.980510
## Hannan-Quinn 2.998817
# Revisión de Cointegración
summary(vec)  # Resumen de la prueba de cointegración
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 5.622967e-02 2.834612e-05
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 1 |  0.01  6.50  8.18 11.65
## r = 0  | 19.57 15.66 17.95 23.52
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##                act_int_net.l1   cin.l1
## act_int_net.l1       1.000000  1.00000
## cin.l1               5.526244 21.25998
## 
## Weights W:
## (This is the loading matrix)
## 
##               act_int_net.l1        cin.l1
## act_int_net.d   0.0006946586  7.931634e-04
## cin.d           0.0006741948 -7.984191e-05
# Mostrar la estructura del modelo VAR
str(var)
## List of 12
##  $ deterministic: num [1:2, 1:4] 2.293 -0.515 -0.635 -0.528 -2.184 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : chr [1:2] "act_int_net" "cin"
##   .. ..$ : chr [1:4] "constant" "sd1" "sd2" "sd3"
##  $ A            :List of 4
##   ..$ A1: num [1:2, 1:2] 1.0684 -0.0126 0.8261 0.8075
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr [1:2] "act_int_net" "cin"
##   .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   ..$ A2: num [1:2, 1:2] -0.2811 0.0313 -2.7472 0.3314
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr [1:2] "act_int_net" "cin"
##   .. .. ..$ : chr [1:2] "act_int_net.l2" "cin.l2"
##   ..$ A3: num [1:2, 1:2] 0.1237 -0.00456 0.93287 0.0096
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr [1:2] "act_int_net" "cin"
##   .. .. ..$ : chr [1:2] "act_int_net.l3" "cin.l3"
##   ..$ A4: num [1:2, 1:2] 0.0897 -0.0134 0.9921 -0.1448
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr [1:2] "act_int_net" "cin"
##   .. .. ..$ : chr [1:2] "act_int_net.l4" "cin.l4"
##  $ p            : int 4
##  $ K            : int 2
##  $ y            : Time-Series [1:342, 1:2] from 1996 to 2024: 57 57.9 58.5 57.8 58.6 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : NULL
##   .. ..$ : chr [1:2] "act_int_net" "cin"
##  $ obs          : int 338
##  $ totobs       : int 342
##  $ call         : language vec2var(z = vec, r = 1)
##  $ vecm         :Formal class 'ca.jo' [package "urca"] with 26 slots
##   .. ..@ x        : Time-Series [1:342, 1:2] from 1996 to 2024: 57 57.9 58.5 57.8 58.6 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:2] "act_int_net" "cin"
##   .. ..@ Z0       : num [1:338, 1:2] 0.816 -0.306 2.064 0.968 -0.656 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:2] "act_int_net.d" "cin.d"
##   .. ..@ Z1       : num [1:338, 1:10] 1 1 1 1 1 1 1 1 1 1 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:10] "constant" "sd1" "sd2" "sd3" ...
##   .. ..@ ZK       : num [1:338, 1:2] 57.8 58.6 58.3 60.4 61.3 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. ..@ type     : chr "trace statistic"
##   .. ..@ model    : chr "with linear trend"
##   .. ..@ ecdet    : chr "none"
##   .. ..@ lag      : int 4
##   .. ..@ P        : int 2
##   .. ..@ season   : num 4
##   .. ..@ dumvar   : NULL
##   .. ..@ cval     : num [1:2, 1:3] 6.5 15.66 8.18 17.95 11.65 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "r <= 1 |" "r = 0  |"
##   .. .. .. ..$ : chr [1:3] "10pct" "5pct" "1pct"
##   .. ..@ teststat : num [1:2] 0.00958 19.57046
##   .. ..@ lambda   : num [1:2] 5.62e-02 2.83e-05
##   .. ..@ Vorg     : num [1:2, 1:2] 0.00554 0.03064 0.00889 0.18894
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. ..@ V        : num [1:2, 1:2] 1 5.53 1 21.26
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. ..@ W        : num [1:2, 1:2] 6.95e-04 6.74e-04 7.93e-04 -7.98e-05
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "act_int_net.d" "cin.d"
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. ..@ PI       : num [1:2, 1:2] 0.001488 0.000594 0.020701 0.002028
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "act_int_net.d" "cin.d"
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. ..@ DELTA    : num [1:2, 1:2] 281.3 -28 -28 3.1
##   .. ..@ GAMMA    : num [1:2, 1:10] 1.339 -0.419 -0.63 -0.529 -2.182 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "act_int_net.d" "cin.d"
##   .. .. .. ..$ : chr [1:10] "constant" "sd1" "sd2" "sd3" ...
##   .. ..@ R0       : num [1:338, 1:2] -2.87 -2.67 1.86 -3.37 -4.35 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:2] "R0.act_int_net.d" "R0.cin.d"
##   .. ..@ RK       : num [1:338, 1:2] -250 -280 -313 -335 -251 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:2] "RK.act_int_net.l1" "RK.cin.l1"
##   .. ..@ bp       : logi NA
##   .. ..@ spec     : chr "transitory"
##   .. ..@ call     : language ca.jo(x = df_ts, type = "trace", ecdet = "none", K = 4, spec = "transitory",      season = 4)
##   .. ..@ test.name: chr "Johansen-Procedure"
##  $ datamat      : num [1:338, 1:14] 58.6 58.3 60.4 61.3 60.7 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : NULL
##   .. ..$ : chr [1:14] "act_int_net" "cin" "constant" "sd1" ...
##  $ resid        : num [1:338, 1:2] -2.75 -2.53 2.01 -3.21 -4.23 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : NULL
##   .. ..$ : chr [1:2] "resids of act_int_net" "resids of cin"
##  $ r            : int 1
##  - attr(*, "class")= chr "vec2var"
# Mostrar las matrices de coeficientes
coef_var <- coef(var)
print(coef_var)
## NULL
# Verificar la estructura del objeto
str(var)
## List of 12
##  $ deterministic: num [1:2, 1:4] 2.293 -0.515 -0.635 -0.528 -2.184 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : chr [1:2] "act_int_net" "cin"
##   .. ..$ : chr [1:4] "constant" "sd1" "sd2" "sd3"
##  $ A            :List of 4
##   ..$ A1: num [1:2, 1:2] 1.0684 -0.0126 0.8261 0.8075
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr [1:2] "act_int_net" "cin"
##   .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   ..$ A2: num [1:2, 1:2] -0.2811 0.0313 -2.7472 0.3314
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr [1:2] "act_int_net" "cin"
##   .. .. ..$ : chr [1:2] "act_int_net.l2" "cin.l2"
##   ..$ A3: num [1:2, 1:2] 0.1237 -0.00456 0.93287 0.0096
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr [1:2] "act_int_net" "cin"
##   .. .. ..$ : chr [1:2] "act_int_net.l3" "cin.l3"
##   ..$ A4: num [1:2, 1:2] 0.0897 -0.0134 0.9921 -0.1448
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr [1:2] "act_int_net" "cin"
##   .. .. ..$ : chr [1:2] "act_int_net.l4" "cin.l4"
##  $ p            : int 4
##  $ K            : int 2
##  $ y            : Time-Series [1:342, 1:2] from 1996 to 2024: 57 57.9 58.5 57.8 58.6 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : NULL
##   .. ..$ : chr [1:2] "act_int_net" "cin"
##  $ obs          : int 338
##  $ totobs       : int 342
##  $ call         : language vec2var(z = vec, r = 1)
##  $ vecm         :Formal class 'ca.jo' [package "urca"] with 26 slots
##   .. ..@ x        : Time-Series [1:342, 1:2] from 1996 to 2024: 57 57.9 58.5 57.8 58.6 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:2] "act_int_net" "cin"
##   .. ..@ Z0       : num [1:338, 1:2] 0.816 -0.306 2.064 0.968 -0.656 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:2] "act_int_net.d" "cin.d"
##   .. ..@ Z1       : num [1:338, 1:10] 1 1 1 1 1 1 1 1 1 1 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:10] "constant" "sd1" "sd2" "sd3" ...
##   .. ..@ ZK       : num [1:338, 1:2] 57.8 58.6 58.3 60.4 61.3 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. ..@ type     : chr "trace statistic"
##   .. ..@ model    : chr "with linear trend"
##   .. ..@ ecdet    : chr "none"
##   .. ..@ lag      : int 4
##   .. ..@ P        : int 2
##   .. ..@ season   : num 4
##   .. ..@ dumvar   : NULL
##   .. ..@ cval     : num [1:2, 1:3] 6.5 15.66 8.18 17.95 11.65 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "r <= 1 |" "r = 0  |"
##   .. .. .. ..$ : chr [1:3] "10pct" "5pct" "1pct"
##   .. ..@ teststat : num [1:2] 0.00958 19.57046
##   .. ..@ lambda   : num [1:2] 5.62e-02 2.83e-05
##   .. ..@ Vorg     : num [1:2, 1:2] 0.00554 0.03064 0.00889 0.18894
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. ..@ V        : num [1:2, 1:2] 1 5.53 1 21.26
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. ..@ W        : num [1:2, 1:2] 6.95e-04 6.74e-04 7.93e-04 -7.98e-05
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "act_int_net.d" "cin.d"
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. ..@ PI       : num [1:2, 1:2] 0.001488 0.000594 0.020701 0.002028
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "act_int_net.d" "cin.d"
##   .. .. .. ..$ : chr [1:2] "act_int_net.l1" "cin.l1"
##   .. ..@ DELTA    : num [1:2, 1:2] 281.3 -28 -28 3.1
##   .. ..@ GAMMA    : num [1:2, 1:10] 1.339 -0.419 -0.63 -0.529 -2.182 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : chr [1:2] "act_int_net.d" "cin.d"
##   .. .. .. ..$ : chr [1:10] "constant" "sd1" "sd2" "sd3" ...
##   .. ..@ R0       : num [1:338, 1:2] -2.87 -2.67 1.86 -3.37 -4.35 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:2] "R0.act_int_net.d" "R0.cin.d"
##   .. ..@ RK       : num [1:338, 1:2] -250 -280 -313 -335 -251 ...
##   .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. ..$ : NULL
##   .. .. .. ..$ : chr [1:2] "RK.act_int_net.l1" "RK.cin.l1"
##   .. ..@ bp       : logi NA
##   .. ..@ spec     : chr "transitory"
##   .. ..@ call     : language ca.jo(x = df_ts, type = "trace", ecdet = "none", K = 4, spec = "transitory",      season = 4)
##   .. ..@ test.name: chr "Johansen-Procedure"
##  $ datamat      : num [1:338, 1:14] 58.6 58.3 60.4 61.3 60.7 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : NULL
##   .. ..$ : chr [1:14] "act_int_net" "cin" "constant" "sd1" ...
##  $ resid        : num [1:338, 1:2] -2.75 -2.53 2.01 -3.21 -4.23 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : NULL
##   .. ..$ : chr [1:2] "resids of act_int_net" "resids of cin"
##  $ r            : int 1
##  - attr(*, "class")= chr "vec2var"
# Acceder a las matrices de coeficientes si están disponibles
if (!is.null(var$A)) {
  A1 <- var$A$A1
  A2 <- var$A$A2
  A3 <- var$A$A3
  A4 <- var$A$A4
  A5 <- var$A$A5
  A6 <- var$A$A6
  A7 <- var$A$A7
  A8 <- var$A$A8
  A9 <- var$A$A9
  
  # Imprimir las matrices de coeficientes
  print("Coeficientes A1:")
  print(A1)
  print("Coeficientes A2:")
  print(A2)
  print("Coeficientes A3:")
  print(A3)
  print("Coeficientes A4:")
  print(A4)
  print("Coeficientes A5:")
  print(A5)
  print("Coeficientes A6:")
  print(A6)
  print("Coeficientes A7:")
  print(A7)
  print("Coeficientes A8:")
  print(A8)
  print("Coeficientes A9:")
  print(A9)
} else {
  print("No se encontraron coeficientes en el objeto 'var'.")
}
## [1] "Coeficientes A1:"
##             act_int_net.l1    cin.l1
## act_int_net     1.06838034 0.8261167
## cin            -0.01258539 0.8074789
## [1] "Coeficientes A2:"
##             act_int_net.l2     cin.l2
## act_int_net    -0.28112513 -2.7472436
## cin             0.03126265  0.3314435
## [1] "Coeficientes A3:"
##             act_int_net.l3      cin.l3
## act_int_net    0.123704835 0.932865766
## cin           -0.004561111 0.009600664
## [1] "Coeficientes A4:"
##             act_int_net.l4     cin.l4
## act_int_net     0.08973462  0.9921000
## cin            -0.01344195 -0.1447972
## [1] "Coeficientes A5:"
## NULL
## [1] "Coeficientes A6:"
## NULL
## [1] "Coeficientes A7:"
## NULL
## [1] "Coeficientes A8:"
## NULL
## [1] "Coeficientes A9:"
## NULL
# Número de rezagos en el modelo VAR
lag_order <- 9

# Acceder a las matrices de coeficientes si están disponibles
if (!is.null(var$A)) {
  # Recorremos los rezagos y calculamos los polos para cada uno
  for (i in 1:lag_order) {
    A <- var$A[[paste0("A", i)]]
    if (!is.null(A)) {
      polos <- eigen(A)$values
      print(paste("Polos para el lag", i, ":"))
      print(polos)
    } else {
      print(paste("No se encontró coeficiente para el rezago", i))
    }
  }
} else {
  print("No se encontraron coeficientes en el objeto 'var'.")
}
## [1] "Polos para el lag 1 :"
## [1] 1.0192954 0.8565639
## [1] "Polos para el lag 2 :"
## [1]  0.11417572 -0.06385739
## [1] "Polos para el lag 3 :"
## [1] 0.06665275+0.03162221i 0.06665275-0.03162221i
## [1] "Polos para el lag 4 :"
## [1] -0.047916083 -0.007146542
## [1] "No se encontró coeficiente para el rezago 5"
## [1] "No se encontró coeficiente para el rezago 6"
## [1] "No se encontró coeficiente para el rezago 7"
## [1] "No se encontró coeficiente para el rezago 8"
## [1] "No se encontró coeficiente para el rezago 9"
# Número de rezagos en el modelo VAR
lag_order <- 4

# Acceder a las matrices de coeficientes si están disponibles
if (!is.null(var$A)) {
  # Recorremos los rezagos y calculamos los polos para cada uno
  for (i in 1:lag_order) {
    A <- var$A[[paste0("A", i)]]
    if (!is.null(A)) {
      polos <- eigen(A)$values
      print(paste("Polos para el lag", i, ":"))
      print(polos)
    } else {
      print(paste("No se encontró coeficiente para el rezago", i))
    }
  }
} else {
  print("No se encontraron coeficientes en el objeto 'var'.")
}
## [1] "Polos para el lag 1 :"
## [1] 1.0192954 0.8565639
## [1] "Polos para el lag 2 :"
## [1]  0.11417572 -0.06385739
## [1] "Polos para el lag 3 :"
## [1] 0.06665275+0.03162221i 0.06665275-0.03162221i
## [1] "Polos para el lag 4 :"
## [1] -0.047916083 -0.007146542
# Análisis de Residuos
# Residuos y modelos GARCH
residuos <- residuals(var)
garch_fit <- ugarchfit(spec = garch_spec, data = residuos[,1])
garch_fit_cin <- ugarchfit(spec = garch_spec, data = residuos[,2])

# Información de GARCH
info_garch_fit <- infocriteria(garch_fit)
info_garch_fit_cin <- infocriteria(garch_fit_cin)

# Funciones de Impulso-Respuesta
ir <- vars::irf(var, n.ahead = 20, impulse = "act_int_net", response = "cin")
plot(ir)

ir1 <- vars::irf(var, n.ahead = 20, impulse = "cin", response = "act_int_net")
plot(ir1)

# Decomposición de la Varianza
fevd.R <- vars::fevd(var, n.ahead = 9)
plot(fevd.R)

# Predicciones
predictions <- predict(var, n.ahead = 9, ci = 0.95)
plot(predictions)

# Revisión de residuos ajustados y pruebas unitarias
rt <- df_ts[,1] - 3.9619 * df_ts[,2]
adf.test(rt)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  rt
## Dickey-Fuller = -1.9946, Lag order = 6, p-value = 0.579
## alternative hypothesis: stationary
pp.test(rt)
## 
##  Phillips-Perron Unit Root Test
## 
## data:  rt
## Dickey-Fuller Z(alpha) = -10.943, Truncation lag parameter = 5, p-value
## = 0.4973
## alternative hypothesis: stationary
summary(ur.df(rt))
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression none 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -95.105  -4.201   1.218   7.794 186.048 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## z.lag.1     0.002422   0.003113   0.778    0.437
## z.diff.lag -0.022306   0.055622  -0.401    0.689
## 
## Residual standard error: 23.87 on 338 degrees of freedom
## Multiple R-squared:  0.002126,   Adjusted R-squared:  -0.003779 
## F-statistic:  0.36 on 2 and 338 DF,  p-value: 0.6979
## 
## 
## Value of test-statistic is: 0.7779 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
#############################333

# Diferenciar la serie
rt_diff <- diff(rt)



# Augmented Dickey-Fuller Test
adf_test_diff <- adf.test(rt_diff)
## Warning in adf.test(rt_diff): p-value smaller than printed p-value
print("Augmented Dickey-Fuller Test para la serie diferenciada:")
## [1] "Augmented Dickey-Fuller Test para la serie diferenciada:"
print(adf_test_diff)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  rt_diff
## Dickey-Fuller = -7.3747, Lag order = 6, p-value = 0.01
## alternative hypothesis: stationary
# Phillips-Perron Unit Root Test
pp_test_diff <- pp.test(rt_diff)
## Warning in pp.test(rt_diff): p-value smaller than printed p-value
print("Phillips-Perron Unit Root Test para la serie diferenciada:")
## [1] "Phillips-Perron Unit Root Test para la serie diferenciada:"
print(pp_test_diff)
## 
##  Phillips-Perron Unit Root Test
## 
## data:  rt_diff
## Dickey-Fuller Z(alpha) = -330.1, Truncation lag parameter = 5, p-value
## = 0.01
## alternative hypothesis: stationary
# Summary of ur.df
ur_df_diff <- ur.df(rt_diff, type = "none", lags = 1)
print("Resumen de la prueba ur.df para la serie diferenciada:")
## [1] "Resumen de la prueba ur.df para la serie diferenciada:"
print(summary(ur_df_diff))
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression none 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -93.273  -3.879   1.288   8.615 188.322 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## z.lag.1    -1.03875    0.07934 -13.092   <2e-16 ***
## z.diff.lag  0.01957    0.05557   0.352    0.725    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 23.92 on 337 degrees of freedom
## Multiple R-squared:  0.4995, Adjusted R-squared:  0.4966 
## F-statistic: 168.2 on 2 and 337 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: -13.0919 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
# Cargar librerías necesarias


# Supongamos que tu modelo VAR ya está ajustado y almacenado en 'var'
# Ajustar el modelo VECM con 4 rezagos
vecm_model <- ca.jo(df_ts, type = "trace", ecdet = "none", K = 4)

# Resumen del modelo VECM
summary(vecm_model)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 6.809512e-02 2.776331e-05
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 1 |  0.01  6.50  8.18 11.65
## r = 0  | 23.85 15.66 17.95 23.52
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##                act_int_net.l4   cin.l4
## act_int_net.l4       1.000000  1.00000
## cin.l4               6.096282 21.51085
## 
## Weights W:
## (This is the loading matrix)
## 
##               act_int_net.l4       cin.l4
## act_int_net.d   0.0006789021  7.75137e-04
## cin.d           0.0008458887 -7.79357e-05
# Pruebas de Cointegración
# Prueba de Johansen para la cointegración
johansen_test <- ca.jo(df_ts, type = "trace", K = 4, ecdet = "none")
summary(johansen_test)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 6.809512e-02 2.776331e-05
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 1 |  0.01  6.50  8.18 11.65
## r = 0  | 23.85 15.66 17.95 23.52
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##                act_int_net.l4   cin.l4
## act_int_net.l4       1.000000  1.00000
## cin.l4               6.096282 21.51085
## 
## Weights W:
## (This is the loading matrix)
## 
##               act_int_net.l4       cin.l4
## act_int_net.d   0.0006789021  7.75137e-04
## cin.d           0.0008458887 -7.79357e-05
#Hasta aqui vamos bien con la relacion de largo plazo, 4 rezagos fueron optimos
# Ajustar el modelo VAR al sistema de vectores cointegrados
var_model <- vec2var(vecm_model, r = 1) # Ajusta el modelo VAR con el número de relaciones de cointegración (r)

# Obtener residuos del modelo VAR
residuos_vecm <- residuals(var_model)

# Ver los primeros residuos para confirmación
head(residuos_vecm)
##      resids of act_int_net resids of cin
## [1,]            -1.6378506    0.23653596
## [2,]            -2.9925344    0.32580492
## [3,]            -0.4972903    0.07160549
## [4,]            -1.4368936    0.13850397
## [5,]            -3.1027195    0.32112942
## [6,]            -0.4499783    0.09804613
# Especificar el modelo GARCH (ejemplo: GARCH(1,1))
garch_spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 1)),
                         mean.model = list(armaOrder = c(0, 0)),
                         distribution.model = "std")

# Ajustar el modelo GARCH a los residuos
garch_fit <- ugarchfit(spec = garch_spec, data = residuos_vecm[, 1])
garch_fit_cin <- ugarchfit(spec = garch_spec, data = residuos_vecm[, 2])

# Información del ajuste GARCH
info_garch_fit <- infocriteria(garch_fit)
info_garch_fit_cin <- infocriteria(garch_fit_cin)

# Imprimir la información
print(info_garch_fit)
##                      
## Akaike       7.271013
## Bayes        7.327567
## Shibata      7.270584
## Hannan-Quinn 7.293552
print(info_garch_fit_cin)
##                      
## Akaike       2.947892
## Bayes        3.004446
## Shibata      2.947463
## Hannan-Quinn 2.970432
# Revisar los residuos estandarizados del GARCH
plot(garch_fit, which = "all")
## 
## please wait...calculating quantiles...

plot(garch_fit_cin, which = "all")
## 
## please wait...calculating quantiles...

# Predicciones de volatilidad
forecast_garch <- ugarchforecast(garch_fit, n.ahead = 10)
forecast_garch_cin <- ugarchforecast(garch_fit_cin, n.ahead = 10)

# Mostrar las predicciones
plot(forecast_garch, which = 1)

plot(forecast_garch_cin, which = 1)

# Predicciones de volatilidad
forecast_garch <- ugarchforecast(garch_fit, n.ahead = 10)
forecast_garch_cin <- ugarchforecast(garch_fit_cin, n.ahead = 10)

# Mostrar las predicciones
plot(forecast_garch, which = 1)

plot(forecast_garch_cin, which = 1)

# Funciones de Impulso-Respuesta
ir <- vars::irf(var_model, n.ahead = 20, impulse = "act_int_net", response = "cin")
plot(ir)

ir1 <- vars::irf(var_model, n.ahead = 20, impulse = "cin", response = "act_int_net")
plot(ir1)

# Decomposición de la Varianza
fevd.R <- vars::fevd(var_model, n.ahead = 9)
plot(fevd.R)

# Revisar la información de los residuos
#residuos_vecm <- residuals(vecm_model)

# Modelos GARCH para los residuos del modelo VECM
#library(rugarch)
#garch_spec <- ugarchspec()
#garch_fit_act_int_net <- ugarchfit(spec = garch_spec, data = residuos_vecm[,1])
#garch_fit_cin <- ugarchfit(spec = garch_spec, data = residuos_vecm[,2])

# Información de los modelos GARCH
#info_garch_fit_act_int_net <- infocriteria(garch_fit_act_int_net)
#info_garch_fit_cin <- infocriteria(garch_fit_cin)

# Funciones de Impulso-Respuesta
#ir_vecm <- vars::irf(vecm_model, n.ahead = 20, impulse = "act_int_net", response = "cin")
#plot(ir_vecm)

#ir_vecm1 <- vars::irf(vecm_model, n.ahead = 20, impulse = "cin", response = "act_int_net")
#plot(ir_vecm1)

# Decomposición de la Varianza
#fevd_vecm <- vars::fevd(vecm_model, n.ahead = 9)
#plot(fevd_vecm)

# Predicciones del modelo VECM
#predictions_vecm <- predict(vecm_model, n.ahead = 9, ci = 0.95)
#plot(predictions_vecm)

# Revisión de residuos ajustados y pruebas unitarias
# Crear serie diferenciada
#rt_diff <- diff(rt)

# Pruebas unitarias para la serie diferenciada
#adf_test_diff <- adf.test(rt_diff)
#pp_test_diff <- pp.test(rt_diff)
#ur_df_diff <- ur.df(rt_diff, type = "none", lags = 1)

# Imprimir resultados de pruebas unitarias
#print("Augmented Dickey-Fuller Test para la serie diferenciada:")
#print(adf_test_diff)

#print("Phillips-Perron Unit Root Test para la serie diferenciada:")
#print(pp_test_diff)

#print("Resumen de la prueba ur.df para la serie diferenciada:")
#print(summary(ur_df_diff))
# Ver los periodos de tiempo
time_periods <- time(df_ts)
print(time_periods)
##           Jan      Feb      Mar      Apr      May      Jun      Jul      Aug
## 1996 1996.000 1996.083 1996.167 1996.250 1996.333 1996.417 1996.500 1996.583
## 1997 1997.000 1997.083 1997.167 1997.250 1997.333 1997.417 1997.500 1997.583
## 1998 1998.000 1998.083 1998.167 1998.250 1998.333 1998.417 1998.500 1998.583
## 1999 1999.000 1999.083 1999.167 1999.250 1999.333 1999.417 1999.500 1999.583
## 2000 2000.000 2000.083 2000.167 2000.250 2000.333 2000.417 2000.500 2000.583
## 2001 2001.000 2001.083 2001.167 2001.250 2001.333 2001.417 2001.500 2001.583
## 2002 2002.000 2002.083 2002.167 2002.250 2002.333 2002.417 2002.500 2002.583
## 2003 2003.000 2003.083 2003.167 2003.250 2003.333 2003.417 2003.500 2003.583
## 2004 2004.000 2004.083 2004.167 2004.250 2004.333 2004.417 2004.500 2004.583
## 2005 2005.000 2005.083 2005.167 2005.250 2005.333 2005.417 2005.500 2005.583
## 2006 2006.000 2006.083 2006.167 2006.250 2006.333 2006.417 2006.500 2006.583
## 2007 2007.000 2007.083 2007.167 2007.250 2007.333 2007.417 2007.500 2007.583
## 2008 2008.000 2008.083 2008.167 2008.250 2008.333 2008.417 2008.500 2008.583
## 2009 2009.000 2009.083 2009.167 2009.250 2009.333 2009.417 2009.500 2009.583
## 2010 2010.000 2010.083 2010.167 2010.250 2010.333 2010.417 2010.500 2010.583
## 2011 2011.000 2011.083 2011.167 2011.250 2011.333 2011.417 2011.500 2011.583
## 2012 2012.000 2012.083 2012.167 2012.250 2012.333 2012.417 2012.500 2012.583
## 2013 2013.000 2013.083 2013.167 2013.250 2013.333 2013.417 2013.500 2013.583
## 2014 2014.000 2014.083 2014.167 2014.250 2014.333 2014.417 2014.500 2014.583
## 2015 2015.000 2015.083 2015.167 2015.250 2015.333 2015.417 2015.500 2015.583
## 2016 2016.000 2016.083 2016.167 2016.250 2016.333 2016.417 2016.500 2016.583
## 2017 2017.000 2017.083 2017.167 2017.250 2017.333 2017.417 2017.500 2017.583
## 2018 2018.000 2018.083 2018.167 2018.250 2018.333 2018.417 2018.500 2018.583
## 2019 2019.000 2019.083 2019.167 2019.250 2019.333 2019.417 2019.500 2019.583
## 2020 2020.000 2020.083 2020.167 2020.250 2020.333 2020.417 2020.500 2020.583
## 2021 2021.000 2021.083 2021.167 2021.250 2021.333 2021.417 2021.500 2021.583
## 2022 2022.000 2022.083 2022.167 2022.250 2022.333 2022.417 2022.500 2022.583
## 2023 2023.000 2023.083 2023.167 2023.250 2023.333 2023.417 2023.500 2023.583
## 2024 2024.000 2024.083 2024.167 2024.250 2024.333 2024.417                  
##           Sep      Oct      Nov      Dec
## 1996 1996.667 1996.750 1996.833 1996.917
## 1997 1997.667 1997.750 1997.833 1997.917
## 1998 1998.667 1998.750 1998.833 1998.917
## 1999 1999.667 1999.750 1999.833 1999.917
## 2000 2000.667 2000.750 2000.833 2000.917
## 2001 2001.667 2001.750 2001.833 2001.917
## 2002 2002.667 2002.750 2002.833 2002.917
## 2003 2003.667 2003.750 2003.833 2003.917
## 2004 2004.667 2004.750 2004.833 2004.917
## 2005 2005.667 2005.750 2005.833 2005.917
## 2006 2006.667 2006.750 2006.833 2006.917
## 2007 2007.667 2007.750 2007.833 2007.917
## 2008 2008.667 2008.750 2008.833 2008.917
## 2009 2009.667 2009.750 2009.833 2009.917
## 2010 2010.667 2010.750 2010.833 2010.917
## 2011 2011.667 2011.750 2011.833 2011.917
## 2012 2012.667 2012.750 2012.833 2012.917
## 2013 2013.667 2013.750 2013.833 2013.917
## 2014 2014.667 2014.750 2014.833 2014.917
## 2015 2015.667 2015.750 2015.833 2015.917
## 2016 2016.667 2016.750 2016.833 2016.917
## 2017 2017.667 2017.750 2017.833 2017.917
## 2018 2018.667 2018.750 2018.833 2018.917
## 2019 2019.667 2019.750 2019.833 2019.917
## 2020 2020.667 2020.750 2020.833 2020.917
## 2021 2021.667 2021.750 2021.833 2021.917
## 2022 2022.667 2022.750 2022.833 2022.917
## 2023 2023.667 2023.750 2023.833 2023.917
## 2024
# Definir los periodos específicos (ejemplo: del 2000 al 2010)
periodo1 <- window(df_ts, start = c(1996, 1), end = c(2009, 12))
periodo2 <- window(df_ts, start = c(2010, 1), end = c(2015, 12))
periodo3 <- window(df_ts, start = c(2016, 1), end = c(2024, 6))

# Verificar que los datos hayan sido filtrados correctamente
print(head(periodo1))
##          act_int_net      cin
## Jan 1996    57.00000 57.00000
## Feb 1996    57.87973 56.91020
## Mar 1996    58.50433 56.87984
## Apr 1996    57.80657 56.90514
## May 1996    58.62242 56.88744
## Jun 1996    58.31641 56.93827
print(head(periodo2))
##          act_int_net      cin
## Jan 2010    300.7956 43.02449
## Feb 2010    299.5884 42.83627
## Mar 2010    294.9121 43.54895
## Apr 2010    298.7340 42.73519
## May 2010    311.7850 41.59269
## Jun 2010    314.5462 41.22656
print(head(periodo3))
##          act_int_net      cin
## Jan 2016    667.6302 17.95468
## Feb 2016    671.7605 17.29536
## Mar 2016    646.6003 20.24937
## Apr 2016    652.4276 19.41229
## May 2016    685.6036 16.53627
## Jun 2016    685.5759 16.80555
# Ajustar VECM para el primer periodo
vecm_model1 <- ca.jo(periodo1, type = "trace", ecdet = "none", K = 4)
summary(vecm_model1)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 0.09705942 0.01131053
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 1 |  1.87  6.50  8.18 11.65
## r = 0  | 18.61 15.66 17.95 23.52
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##                act_int_net.l4   cin.l4
## act_int_net.l4        1.00000  1.00000
## cin.l4               17.64977 12.68518
## 
## Weights W:
## (This is the loading matrix)
## 
##               act_int_net.l4        cin.l4
## act_int_net.d      0.1618759  0.0208101216
## cin.d             -0.0209266 -0.0003853582
# Ajustar VECM para el segundo periodo
vecm_model2 <- ca.jo(periodo2, type = "trace", ecdet = "none", K = 4)
summary(vecm_model2)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 0.1089061021 0.0009570726
## 
## Values of teststatistic and critical values of test:
## 
##          test 10pct  5pct  1pct
## r <= 1 | 0.07  6.50  8.18 11.65
## r = 0  | 7.91 15.66 17.95 23.52
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##                act_int_net.l4   cin.l4
## act_int_net.l4        1.00000  1.00000
## cin.l4               15.28509 12.90504
## 
## Weights W:
## (This is the loading matrix)
## 
##               act_int_net.l4       cin.l4
## act_int_net.d      0.1420760  0.031080220
## cin.d             -0.0255352 -0.001764339
# Ajustar VECM para el tercer periodo
vecm_model3 <- ca.jo(periodo3, type = "trace", ecdet = "none", K = 4)
summary(vecm_model3)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 0.06884031 0.00451015
## 
## Values of teststatistic and critical values of test:
## 
##          test 10pct  5pct  1pct
## r <= 1 | 0.44  6.50  8.18 11.65
## r = 0  | 7.43 15.66 17.95 23.52
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##                act_int_net.l4   cin.l4
## act_int_net.l4       1.000000  1.00000
## cin.l4              -1.896856 18.96352
## 
## Weights W:
## (This is the loading matrix)
## 
##               act_int_net.l4        cin.l4
## act_int_net.d    -0.08444266  0.0067782223
## cin.d             0.01044712 -0.0003974512
# Supongamos que tienes tu modelo VECM ya ajustado y almacenado en un objeto llamado `vecm_model`.

# Extraer las matrices alpha y beta
alpha_matrix <- vecm_model@V
beta_matrix <- vecm_model@W

# Mostrar la matriz beta (relaciones de cointegración)
cat("Matriz Beta:\n")
## Matriz Beta:
print(beta_matrix)
##               act_int_net.l4       cin.l4
## act_int_net.d   0.0006789021  7.75137e-04
## cin.d           0.0008458887 -7.79357e-05
# Mostrar la matriz alpha (velocidades de ajuste)
cat("Matriz Alpha:\n")
## Matriz Alpha:
print(alpha_matrix)
##                act_int_net.l4   cin.l4
## act_int_net.l4       1.000000  1.00000
## cin.l4               6.096282 21.51085
######Matrices por periodo 
#################Ajustar VECM para el primer periodo
vecm_model1 <- ca.jo(periodo1, type = "trace", ecdet = "none", K = 4)
summary(vecm_model1)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 0.09705942 0.01131053
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 1 |  1.87  6.50  8.18 11.65
## r = 0  | 18.61 15.66 17.95 23.52
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##                act_int_net.l4   cin.l4
## act_int_net.l4        1.00000  1.00000
## cin.l4               17.64977 12.68518
## 
## Weights W:
## (This is the loading matrix)
## 
##               act_int_net.l4        cin.l4
## act_int_net.d      0.1618759  0.0208101216
## cin.d             -0.0209266 -0.0003853582
alpha1 <- vecm_model1@V
beta1 <- vecm_model1@W

# Ajustar VECM para el segundo periodo
vecm_model2 <- ca.jo(periodo2, type = "trace", ecdet = "none", K = 4)
summary(vecm_model2)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 0.1089061021 0.0009570726
## 
## Values of teststatistic and critical values of test:
## 
##          test 10pct  5pct  1pct
## r <= 1 | 0.07  6.50  8.18 11.65
## r = 0  | 7.91 15.66 17.95 23.52
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##                act_int_net.l4   cin.l4
## act_int_net.l4        1.00000  1.00000
## cin.l4               15.28509 12.90504
## 
## Weights W:
## (This is the loading matrix)
## 
##               act_int_net.l4       cin.l4
## act_int_net.d      0.1420760  0.031080220
## cin.d             -0.0255352 -0.001764339
alpha2 <- vecm_model2@V
beta2 <- vecm_model2@W

# Ajustar VECM para el tercer periodo
vecm_model3 <- ca.jo(periodo3, type = "trace", ecdet = "none", K = 4)
summary(vecm_model3)
## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , with linear trend 
## 
## Eigenvalues (lambda):
## [1] 0.06884031 0.00451015
## 
## Values of teststatistic and critical values of test:
## 
##          test 10pct  5pct  1pct
## r <= 1 | 0.44  6.50  8.18 11.65
## r = 0  | 7.43 15.66 17.95 23.52
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##                act_int_net.l4   cin.l4
## act_int_net.l4       1.000000  1.00000
## cin.l4              -1.896856 18.96352
## 
## Weights W:
## (This is the loading matrix)
## 
##               act_int_net.l4        cin.l4
## act_int_net.d    -0.08444266  0.0067782223
## cin.d             0.01044712 -0.0003974512
alpha3 <- vecm_model3@V
beta3 <- vecm_model3@W

# Mostrar las matrices alfa y beta para cada periodo

# Periodo 1
cat("Periodo 1 (2000-2010)\n")
## Periodo 1 (2000-2010)
cat("Matriz Beta:\n")
## Matriz Beta:
print(beta1)
##               act_int_net.l4        cin.l4
## act_int_net.d      0.1618759  0.0208101216
## cin.d             -0.0209266 -0.0003853582
cat("Matriz Alpha:\n")
## Matriz Alpha:
print(alpha1)
##                act_int_net.l4   cin.l4
## act_int_net.l4        1.00000  1.00000
## cin.l4               17.64977 12.68518
# Periodo 2
cat("Periodo 2 (2011-2020)\n")
## Periodo 2 (2011-2020)
cat("Matriz Beta:\n")
## Matriz Beta:
print(beta2)
##               act_int_net.l4       cin.l4
## act_int_net.d      0.1420760  0.031080220
## cin.d             -0.0255352 -0.001764339
cat("Matriz Alpha:\n")
## Matriz Alpha:
print(alpha2)
##                act_int_net.l4   cin.l4
## act_int_net.l4        1.00000  1.00000
## cin.l4               15.28509 12.90504
# Periodo 3
cat("Periodo 3 (2021-2023)\n")
## Periodo 3 (2021-2023)
cat("Matriz Beta:\n")
## Matriz Beta:
print(beta3)
##               act_int_net.l4        cin.l4
## act_int_net.d    -0.08444266  0.0067782223
## cin.d             0.01044712 -0.0003974512
cat("Matriz Alpha:\n")
## Matriz Alpha:
print(alpha3)
##                act_int_net.l4   cin.l4
## act_int_net.l4       1.000000  1.00000
## cin.l4              -1.896856 18.96352
# Periodo 1
cat("Periodo 1 (2000-2010)\n")
## Periodo 1 (2000-2010)
cat("Matriz Beta (Cointegration vectors):\n")
## Matriz Beta (Cointegration vectors):
print(vecm_model1@V)  # Cointegration vectors
##                act_int_net.l4   cin.l4
## act_int_net.l4        1.00000  1.00000
## cin.l4               17.64977 12.68518
cat("Matriz Alpha (Loading vectors):\n")
## Matriz Alpha (Loading vectors):
print(vecm_model1@W)  # Loading vectors
##               act_int_net.l4        cin.l4
## act_int_net.d      0.1618759  0.0208101216
## cin.d             -0.0209266 -0.0003853582
# Periodo 2
cat("Periodo 2 (2011-2020)\n")
## Periodo 2 (2011-2020)
cat("Matriz Beta (Cointegration vectors):\n")
## Matriz Beta (Cointegration vectors):
print(vecm_model2@V) 
##                act_int_net.l4   cin.l4
## act_int_net.l4        1.00000  1.00000
## cin.l4               15.28509 12.90504
cat("Matriz Alpha (Loading vectors):\n")
## Matriz Alpha (Loading vectors):
print(vecm_model2@W) 
##               act_int_net.l4       cin.l4
## act_int_net.d      0.1420760  0.031080220
## cin.d             -0.0255352 -0.001764339
# Periodo 3
cat("Periodo 3 (2021-2023)\n")
## Periodo 3 (2021-2023)
cat("Matriz Beta (Cointegration vectors):\n")
## Matriz Beta (Cointegration vectors):
print(vecm_model3@V)
##                act_int_net.l4   cin.l4
## act_int_net.l4       1.000000  1.00000
## cin.l4              -1.896856 18.96352
cat("Matriz Alpha (Loading vectors):\n")
## Matriz Alpha (Loading vectors):
print(vecm_model3@W)
##               act_int_net.l4        cin.l4
## act_int_net.d    -0.08444266  0.0067782223
## cin.d             0.01044712 -0.0003974512