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)
## Warning: package 'highcharter' was built under R version 4.4.1
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(bvartools)
## Warning: package 'bvartools' was built under R version 4.4.1
## Cargando paquete requerido: coda
## Warning: package 'coda' was built under R version 4.4.1
## Cargando paquete requerido: Matrix
library(forecast)
## Warning: package 'forecast' was built under R version 4.4.1
library(vars)
## Warning: package 'vars' was built under R version 4.4.1
## Cargando paquete requerido: MASS
## Cargando paquete requerido: strucchange
## Warning: package 'strucchange' was built under R version 4.4.1
## Cargando paquete requerido: zoo
## Warning: package 'zoo' was built under R version 4.4.1
##
## Adjuntando el paquete: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Cargando paquete requerido: sandwich
## Warning: package 'sandwich' was built under R version 4.4.1
## Cargando paquete requerido: urca
## Warning: package 'urca' was built under R version 4.4.1
## Cargando paquete requerido: lmtest
## Warning: package 'lmtest' was built under R version 4.4.1
##
## 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)
## Warning: package 'tseries' was built under R version 4.4.1
library(urca)
library(readxl)
## Warning: package 'readxl' was built under R version 4.4.1
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/famva/Desktop/Tesis Cap 1 scrip")
df <- read_xlsx("BASE_VEC.xlsx", sheet = 1, col_names = TRUE)
# Estructura del dataframe
str(df)
## tibble [342 × 10] (S3: tbl_df/tbl/data.frame)
## $ periodo : POSIXct[1:342], format: "1996-01-01" "1996-02-01" ...
## $ base_mon : num [1:342] 57939 57823 59499 57172 60519 ...
## $ act_int_net: num [1:342] 5246 9861 13137 9477 13757 ...
## $ cin : num [1:342] 52694 47962 46362 47695 46762 ...
## $ inf_gral : num [1:342] 51.7 49 43.8 36.9 33.8 ...
## $ Subyacente : num [1:342] 49.9 46.8 43.4 37 32.9 ...
## $ no_sub : num [1:342] 56.5 55.1 44.7 36.7 36.5 ...
## $ inpc : num [1:342] 23.3 23.9 24.4 25.1 25.6 ...
## $ inpc_sub : num [1:342] 25.3 25.9 26.5 27.3 27.8 ...
## $ tc : num [1:342] 7.48 7.52 7.57 7.46 7.43 ...
colnames(df)
## [1] "periodo" "base_mon" "act_int_net" "cin" "inf_gral"
## [6] "Subyacente" "no_sub" "inpc" "inpc_sub" "tc"
summary(df)
## periodo base_mon act_int_net
## Min. :1996-01-01 00:00:00.00 Min. : 57172 Min. : 5246
## 1st Qu.:2003-02-08 00:00:00.00 1st Qu.: 240381 1st Qu.: 568765
## Median :2010-03-16 12:00:00.00 Median : 584145 Median :1329545
## Mean :2010-03-17 06:31:34.74 Mean : 873513 Mean :1842264
## 3rd Qu.:2017-04-23 12:00:00.00 3rd Qu.:1371069 3rd Qu.:3335212
## Max. :2024-06-01 00:00:00.00 Max. :3043323 Max. :4694191
## cin inf_gral Subyacente no_sub
## Min. :-2902403 Min. : 2.130 Min. : 2.300 Min. :-1.960
## 1st Qu.:-1746815 1st Qu.: 3.783 1st Qu.: 3.533 1st Qu.: 4.213
## Median : -715008 Median : 4.635 Median : 3.935 Median : 6.605
## Mean : -968752 Mean : 7.204 Mean : 6.854 Mean : 8.366
## 3rd Qu.: -325338 3rd Qu.: 6.560 3rd Qu.: 6.415 3rd Qu.: 9.377
## Max. : 52694 Max. :51.720 Max. :49.940 Max. :56.500
## inpc inpc_sub tc
## Min. : 23.33 Min. : 25.33 Min. : 7.433
## 1st Qu.: 53.74 1st Qu.: 57.79 1st Qu.:10.236
## Median : 72.86 Median : 76.64 Median :12.709
## Mean : 74.72 Mean : 77.06 Mean :13.566
## 3rd Qu.: 94.81 3rd Qu.: 95.85 3rd Qu.:17.834
## Max. :134.59 Max. :134.33 Max. :24.266
head(df)
## # A tibble: 6 × 10
## periodo base_mon act_int_net cin inf_gral Subyacente no_sub
## <dttm> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1996-01-01 00:00:00 57939. 5246. 52694. 51.7 49.9 56.5
## 2 1996-02-01 00:00:00 57822. 9861. 47962. 49.0 46.8 55.1
## 3 1996-03-01 00:00:00 59499. 13137. 46362. 43.8 43.4 44.7
## 4 1996-04-01 00:00:00 57172. 9477. 47695. 36.9 37 36.7
## 5 1996-05-01 00:00:00 60519. 13757. 46762. 33.8 32.9 36.5
## 6 1996-06-01 00:00:00 61592. 12151. 49441. 31.8 30.7 35.0
## # ℹ 3 more variables: inpc <dbl>, inpc_sub <dbl>, tc <dbl>
tail(df)
## # A tibble: 6 × 10
## periodo base_mon act_int_net cin inf_gral Subyacente no_sub
## <dttm> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2024-01-01 00:00:00 2957616 3807582. -849966. 4.88 4.76 5.24
## 2 2024-02-01 00:00:00 3013957. 3745002. -731045. 4.4 4.64 3.67
## 3 2024-03-01 00:00:00 3043323. 3627241. -583919. 4.42 4.55 4.03
## 4 2024-04-01 00:00:00 2980375. 3783622. -803248. 4.65 4.37 5.54
## 5 2024-05-01 00:00:00 2989795. 3790002. -800207. 4.69 4.21 6.19
## 6 2024-06-01 00:00:00 2995218. 4119732. -1124514. 4.98 4.13 7.67
## # ℹ 3 more variables: inpc <dbl>, inpc_sub <dbl>, tc <dbl>
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)
plot(df_ts)
colnames(df_ts)
## [1] "act_int_net" "cin"
#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
## -301325 -30059 -3873 20060 723047
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.163e+04 1.249e+04 -0.931 0.3525
## z.lag.1 -3.357e-02 1.333e-02 -2.518 0.0123 *
## tt 4.986e+02 1.951e+02 2.555 0.0111 *
## z.diff.lag 1.445e-03 5.544e-02 0.026 0.9792
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 88240 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("adf_plot1.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
## -648033 -31140 2663 25034 446276
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -8.733e+03 1.066e+04 -0.819 0.413
## z.lag.1 -1.778e-02 1.346e-02 -1.321 0.187
## tt -7.070e+01 1.049e+02 -0.674 0.501
## z.diff.lag -5.532e-02 5.631e-02 -0.982 0.327
##
## Residual standard error: 94560 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("adf_plot2.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
## -323731 -24772 -4242 19717 721870
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8751.06774 9781.44538 0.895 0.372
## z.lag.1 -1.04574 0.07926 -13.195 <2e-16 ***
## tt 22.64743 49.48451 0.458 0.647
## z.diff.lag 0.03081 0.05566 0.554 0.580
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 89160 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("adf_plot3.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
## -653851 -30294 2946 24834 451577
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.280e+04 1.043e+04 -1.228 0.220
## z.lag.1 -1.118e+00 8.133e-02 -13.741 <2e-16 ***
## tt 5.295e+01 5.289e+01 1.001 0.317
## z.diff.lag 4.498e-02 5.560e-02 0.809 0.419
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 94850 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("adf_plot3.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
## AIC(n) 4.360780e+01 4.361211e+01 4.359799e+01 4.361547e+01 4.355325e+01
## HQ(n) 4.363523e+01 4.365782e+01 4.366198e+01 4.369774e+01 4.365381e+01
## SC(n) 4.367657e+01 4.372673e+01 4.375845e+01 4.382177e+01 4.380540e+01
## FPE(n) 8.682157e+18 8.719720e+18 8.597488e+18 8.749230e+18 8.221616e+18
## 6 7 8 9 10
## AIC(n) 4.355759e+01 4.354146e+01 4.355079e+01 4.352131e+01 4.352830e+01
## HQ(n) 4.367643e+01 4.367859e+01 4.370619e+01 4.369500e+01 4.372027e+01
## SC(n) 4.385559e+01 4.388530e+01 4.394047e+01 4.395684e+01 4.400967e+01
## FPE(n) 8.257668e+18 8.125891e+18 8.202463e+18 7.964814e+18 8.021344e+18
var_aic
## $selection
## AIC(n) HQ(n) SC(n) FPE(n)
## 9 1 1 9
##
## $criteria
## 1 2 3 4 5
## AIC(n) 4.359762e+01 4.360030e+01 4.358672e+01 4.360557e+01 4.354344e+01
## HQ(n) 4.363419e+01 4.365514e+01 4.365986e+01 4.369699e+01 4.365313e+01
## SC(n) 4.368931e+01 4.373783e+01 4.377010e+01 4.383480e+01 4.381851e+01
## FPE(n) 8.594244e+18 8.617296e+18 8.501239e+18 8.663155e+18 8.141448e+18
## 6 7 8 9 10
## AIC(n) 4.354573e+01 4.352782e+01 4.354001e+01 4.350597e+01 4.351243e+01
## HQ(n) 4.367371e+01 4.367408e+01 4.370456e+01 4.368880e+01 4.371354e+01
## SC(n) 4.386664e+01 4.389458e+01 4.395262e+01 4.396442e+01 4.401672e+01
## FPE(n) 8.160419e+18 8.015994e+18 8.114832e+18 7.843821e+18 7.895447e+18
#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
## 9.583741e-01 -1.139625e-02 -1.464490e+04 5.353715e+02
##
##
## Estimated coefficients for equation cin:
## ========================================
## Call:
## cin = act_int_net.l1 + cin.l1 + const + trend
##
## act_int_net.l1 cin.l1 const trend
## 4.895197e-02 1.010834e+00 1.611665e+04 -5.751958e+02
#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.104672e+00 1.002306e-01 -2.483357e-01 -1.626304e-01 -1.834409e-02
## cin.l3 act_int_net.l4 cin.l4 act_int_net.l5 cin.l5
## -8.898432e-02 4.972487e-02 2.575033e-01 2.637077e-01 -6.231989e-02
## act_int_net.l6 cin.l6 act_int_net.l7 cin.l7 act_int_net.l8
## -2.392682e-01 2.274360e-03 -2.391337e-01 -3.386538e-01 3.422231e-01
## cin.l8 act_int_net.l9 cin.l9 const trend
## 4.113410e-01 -6.438929e-02 -1.486605e-01 -1.356776e+04 5.153769e+02
##
##
## 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
## -2.303179e-01 7.437218e-01 1.131234e-01 2.209318e-02 2.307357e-01
## cin.l3 act_int_net.l4 cin.l4 act_int_net.l5 cin.l5
## 3.042722e-01 -2.177018e-01 -4.634476e-01 -1.291855e-01 2.592058e-01
## act_int_net.l6 cin.l6 act_int_net.l7 cin.l7 act_int_net.l8
## 1.220778e-01 -1.330444e-01 4.148931e-01 5.183019e-01 -4.642043e-01
## cin.l8 act_int_net.l9 cin.l9 const trend
## -5.577965e-01 2.429734e-01 3.628412e-01 1.889586e+04 -6.382648e+02
summary(p1ct, equation = "act_int_net")
##
## VAR Estimation Results:
## =========================
## Endogenous variables: act_int_net, cin
## Deterministic variables: both
## Sample size: 333
## Log Likelihood: -8147.677
## 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.105e+00 1.675e-01 6.597 1.79e-10 ***
## cin.l1 1.002e-01 1.599e-01 0.627 0.5314
## act_int_net.l2 -2.483e-01 2.267e-01 -1.095 0.2742
## cin.l2 -1.626e-01 2.095e-01 -0.776 0.4381
## act_int_net.l3 -1.834e-02 2.272e-01 -0.081 0.9357
## cin.l3 -8.898e-02 2.094e-01 -0.425 0.6712
## act_int_net.l4 4.972e-02 2.286e-01 0.218 0.8279
## cin.l4 2.575e-01 2.121e-01 1.214 0.2256
## act_int_net.l5 2.637e-01 2.283e-01 1.155 0.2490
## cin.l5 -6.232e-02 2.111e-01 -0.295 0.7680
## act_int_net.l6 -2.393e-01 2.286e-01 -1.047 0.2960
## cin.l6 2.274e-03 2.115e-01 0.011 0.9914
## act_int_net.l7 -2.391e-01 2.314e-01 -1.034 0.3021
## cin.l7 -3.387e-01 2.145e-01 -1.579 0.1154
## act_int_net.l8 3.422e-01 2.343e-01 1.460 0.1452
## cin.l8 4.113e-01 2.175e-01 1.891 0.0596 .
## act_int_net.l9 -6.439e-02 1.750e-01 -0.368 0.7131
## cin.l9 -1.487e-01 1.692e-01 -0.879 0.3803
## const -1.357e+04 1.466e+04 -0.925 0.3554
## trend 5.154e+02 2.194e+02 2.349 0.0194 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 87380 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 7.636e+09 -7.483e+09
## cin -7.483e+09 8.242e+09
##
## 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: -8147.677
## 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 -2.303e-01 1.740e-01 -1.324 0.18653
## cin.l1 7.437e-01 1.662e-01 4.476 1.07e-05 ***
## act_int_net.l2 1.131e-01 2.355e-01 0.480 0.63134
## cin.l2 2.209e-02 2.176e-01 0.102 0.91921
## act_int_net.l3 2.307e-01 2.361e-01 0.977 0.32912
## cin.l3 3.043e-01 2.176e-01 1.398 0.16297
## act_int_net.l4 -2.177e-01 2.375e-01 -0.917 0.36000
## cin.l4 -4.634e-01 2.203e-01 -2.103 0.03624 *
## act_int_net.l5 -1.292e-01 2.372e-01 -0.545 0.58643
## cin.l5 2.592e-01 2.193e-01 1.182 0.23804
## act_int_net.l6 1.221e-01 2.375e-01 0.514 0.60758
## cin.l6 -1.330e-01 2.197e-01 -0.605 0.54530
## act_int_net.l7 4.149e-01 2.404e-01 1.726 0.08531 .
## cin.l7 5.183e-01 2.228e-01 2.326 0.02066 *
## act_int_net.l8 -4.642e-01 2.435e-01 -1.907 0.05748 .
## cin.l8 -5.578e-01 2.260e-01 -2.468 0.01412 *
## act_int_net.l9 2.430e-01 1.818e-01 1.337 0.18228
## cin.l9 3.628e-01 1.758e-01 2.064 0.03982 *
## const 1.890e+04 1.523e+04 1.241 0.21568
## trend -6.383e+02 2.279e+02 -2.801 0.00542 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
##
## Residual standard error: 90780 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 7.636e+09 -7.483e+09
## cin -7.483e+09 8.242e+09
##
## 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.0000000 1.000000
## cin.l1 0.5501536 2.116493
##
## Weights W:
## (This is the loading matrix)
##
## act_int_net.l1 cin.l1
## act_int_net.d 0.0006946586 0.0007931634
## cin.d 0.0067722271 -0.0008020050
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.0683803 0.0822423
## cin -0.1264192 0.8074789
##
##
## A2:
## act_int_net.l2 cin.l2
## act_int_net -0.2811251 -0.2734960
## cin 0.3140306 0.3314435
##
##
## A3:
## act_int_net.l3 cin.l3
## act_int_net 0.12370483 0.092869480
## cin -0.04581596 0.009600664
##
##
## A4:
## act_int_net.l4 cin.l4
## act_int_net 0.08973462 0.09876642
## cin -0.13502322 -0.14479724
##
##
## Coefficient matrix of deterministic regressor(s).
##
## constant sd1 sd2 sd3
## act_int_net 13361.96 -3329.163 -11457.02 -21815.53
## cin -14143.47 -27834.260 -14549.37 11761.64
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 6.947e-04 6.772e-03
## constant 1.336e+04 -1.414e+04
## sd1 -3.329e+03 -2.783e+04
## sd2 -1.146e+04 -1.455e+04
## sd3 -2.182e+04 1.176e+04
## act_int_net.dl1 6.769e-02 -1.332e-01
## cin.dl1 8.186e-02 -1.962e-01
## act_int_net.dl2 -2.134e-01 1.808e-01
## cin.dl2 -1.916e-01 1.352e-01
## act_int_net.dl3 -8.973e-02 1.350e-01
## cin.dl3 -9.877e-02 1.448e-01
##
##
## $beta
## ect1
## act_int_net.l1 1.0000000
## cin.l1 0.5501536
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.05, Lag order = 6, p-value = 0.9296
## alternative hypothesis: stationary
pp.test(rt)
##
## Phillips-Perron Unit Root Test
##
## data: rt
## Dickey-Fuller Z(alpha) = -7.4072, Truncation lag parameter = 5, p-value
## = 0.6954
## 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
## -2109342 -87330 23956 162491 3274202
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## z.lag.1 0.0002303 0.0034792 0.066 0.947
## z.diff.lag -0.0543054 0.0554082 -0.980 0.328
##
## Residual standard error: 460200 on 338 degrees of freedom
## Multiple R-squared: 0.002835, Adjusted R-squared: -0.003066
## F-statistic: 0.4804 on 2 and 338 DF, p-value: 0.619
##
##
## Value of test-statistic is: 0.0662
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau1 -2.58 -1.95 -1.62