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.

attach(coint)

#nombres de columnas
names(coint)
## [1] "Year"     "Quarter"  "tiempo"   "DPI"      "GDP"      "PCE"      "CP"      
## [8] "DIVIDEND"
class(coint)
## [1] "tbl_df"     "tbl"        "data.frame"
plot(PCE)

lnPCE = log(PCE)
lnDPI = log(DPI)


DPI.ts = ts(lnDPI, start=c(1974,1), end=c(2007,4), frequency = 4)
PCE.ts = ts(lnPCE, start=c(1974,1), end=c(2007,4), frequency = 4)

datos1=cbind(DPI.ts, PCE.ts)
plot(cbind(DPI.ts, PCE.ts))

modelo1 = lm(PCE.ts ~ DPI.ts)
summary(modelo1)
## 
## Call:
## lm(formula = PCE.ts ~ DPI.ts)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.031067 -0.009396 -0.001756  0.007100  0.046117 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.194408   0.021496   9.044 1.51e-15 ***
## DPI.ts      0.960252   0.002806 342.210  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0128 on 134 degrees of freedom
## Multiple R-squared:  0.9989, Adjusted R-squared:  0.9988 
## F-statistic: 1.171e+05 on 1 and 134 DF,  p-value: < 2.2e-16
cor(PCE,DPI)
## [1] 0.9984923
residuales=modelo1$residuals
summary(residuales)
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## -0.031067 -0.009396 -0.001756  0.000000  0.007100  0.046117
residualPlot(modelo1)

#prueba
adf.test(residuales)
## Augmented Dickey-Fuller Test 
## alternative: stationary 
##  
## Type 1: no drift no trend 
##      lag   ADF p.value
## [1,]   0 -6.05    0.01
## [2,]   1 -5.01    0.01
## [3,]   2 -4.90    0.01
## [4,]   3 -5.36    0.01
## [5,]   4 -4.10    0.01
## Type 2: with drift no trend 
##      lag   ADF p.value
## [1,]   0 -6.02    0.01
## [2,]   1 -5.00    0.01
## [3,]   2 -4.89    0.01
## [4,]   3 -5.36    0.01
## [5,]   4 -4.12    0.01
## Type 3: with drift and trend 
##      lag   ADF p.value
## [1,]   0 -6.00    0.01
## [2,]   1 -5.02    0.01
## [3,]   2 -4.93    0.01
## [4,]   3 -5.45    0.01
## [5,]   4 -4.26    0.01
## ---- 
## Note: in fact, p.value = 0.01 means p.value <= 0.01
y = ur.df(residuales, type = "trend", selectlags = "AIC")
summary(y)
## 
## ############################################### 
## # 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 
## -0.038950 -0.005109  0.000418  0.004343  0.039482 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.662e-03  1.724e-03  -0.964   0.3369    
## z.lag.1     -3.753e-01  7.480e-02  -5.017 1.69e-06 ***
## tt           1.829e-05  2.192e-05   0.835   0.4055    
## z.diff.lag  -1.680e-01  8.090e-02  -2.077   0.0398 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.009808 on 130 degrees of freedom
## Multiple R-squared:  0.2775, Adjusted R-squared:  0.2608 
## F-statistic: 16.64 on 3 and 130 DF,  p-value: 3.279e-09
## 
## 
## Value of test-statistic is: -5.017 8.6193 12.8112 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau3 -3.99 -3.43 -3.13
## phi2  6.22  4.75  4.07
## phi3  8.43  6.49  5.47
y2 = ur.df(residuales, type = "drift", selectlags = "AIC")
summary(y2)
## 
## ############################################### 
## # Augmented Dickey-Fuller Test Unit Root Test # 
## ############################################### 
## 
## Test regression drift 
## 
## 
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.040038 -0.004852  0.000548  0.004892  0.038497 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.0004084  0.0008463  -0.483   0.6302    
## z.lag.1     -0.3732403  0.0746724  -4.998 1.82e-06 ***
## z.diff.lag  -0.1683817  0.0808055  -2.084   0.0391 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.009797 on 131 degrees of freedom
## Multiple R-squared:  0.2736, Adjusted R-squared:  0.2625 
## F-statistic: 24.67 on 2 and 131 DF,  p-value: 8.05e-10
## 
## 
## Value of test-statistic is: -4.9984 12.6098 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau2 -3.46 -2.88 -2.57
## phi1  6.52  4.63  3.81
y3 = ur.df(residuales, type = "none", selectlags = "AIC")
summary(y3)
## 
## ############################################### 
## # 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 
## -0.040447 -0.005259  0.000139  0.004482  0.038084 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## z.lag.1    -0.37326    0.07446  -5.013 1.69e-06 ***
## z.diff.lag -0.16819    0.08057  -2.088   0.0388 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.009768 on 132 degrees of freedom
## Multiple R-squared:  0.2732, Adjusted R-squared:  0.2622 
## F-statistic: 24.81 on 2 and 132 DF,  p-value: 7.139e-10
## 
## 
## Value of test-statistic is: -5.0133 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau1 -2.58 -1.95 -1.62
#SEGUN TODAS ESTAS PRUEBAS SON ESTACIONARIAS


#Philips y Oularis
prueba.P0 = ca.po(datos1, type="Pz")
summary(prueba.P0)
## 
## ######################################## 
## # Phillips and Ouliaris Unit Root Test # 
## ######################################## 
## 
## Test of type Pz 
## detrending of series none 
## 
## Response DPI.ts :
## 
## Call:
## lm(formula = DPI.ts ~ zr - 1)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.035593 -0.005006  0.000100  0.005352  0.053987 
## 
## Coefficients:
##          Estimate Std. Error t value Pr(>|t|)    
## zrDPI.ts  0.78931    0.05893  13.394  < 2e-16 ***
## zrPCE.ts  0.21501    0.05979   3.596 0.000454 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01117 on 133 degrees of freedom
## Multiple R-squared:      1,  Adjusted R-squared:      1 
## F-statistic: 3.18e+07 on 2 and 133 DF,  p-value: < 2.2e-16
## 
## 
## Response PCE.ts :
## 
## Call:
## lm(formula = PCE.ts ~ zr - 1)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.035093 -0.004833  0.000136  0.005776  0.042633 
## 
## Coefficients:
##          Estimate Std. Error t value Pr(>|t|)    
## zrDPI.ts  0.06780    0.05341    1.27    0.206    
## zrPCE.ts  0.93239    0.05418   17.21   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01012 on 133 degrees of freedom
## Multiple R-squared:      1,  Adjusted R-squared:      1 
## F-statistic: 3.761e+07 on 2 and 133 DF,  p-value: < 2.2e-16
## 
## 
## 
## Value of test-statistic is: 50.7408 
## 
## Critical values of Pz are:
##                   10pct    5pct    1pct
## critical values 33.9267 40.8217 55.1911
prueba.P2 = ca.po(datos1, type="Pu")
summary(prueba.P2)
## 
## ######################################## 
## # Phillips and Ouliaris Unit Root Test # 
## ######################################## 
## 
## Test of type Pu 
## detrending of series none 
## 
## 
## Call:
## lm(formula = z[, 1] ~ z[, -1] - 1)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.064570 -0.006143  0.001245  0.008814  0.043063 
## 
## Coefficients:
##          Estimate Std. Error t value Pr(>|t|)    
## z[, -1] 1.0146094  0.0001865    5441   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01642 on 135 degrees of freedom
## Multiple R-squared:      1,  Adjusted R-squared:      1 
## F-statistic: 2.961e+07 on 1 and 135 DF,  p-value: < 2.2e-16
## 
## 
## Value of test-statistic is: 38.8218 
## 
## Critical values of Pu are:
##                   10pct    5pct    1pct
## critical values 20.3933 25.9711 38.3413
tendencia=seq_along(PCE.ts)
print(tendencia)
##   [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18
##  [19]  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36
##  [37]  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54
##  [55]  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72
##  [73]  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
##  [91]  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108
## [109] 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
## [127] 127 128 129 130 131 132 133 134 135 136
#hacemos un nuevo modelo
modelo2=lm(PCE.ts~tendencia+DPI.ts)
residuales2 = modelo2$residuals
residualPlot(modelo2)

DFresiduales2 = ur.df(residuales2, type = "trend", selectlags = "AIC")
summary(DFresiduales2)
## 
## ############################################### 
## # 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 
## -0.033155 -0.005175 -0.000228  0.004714  0.040952 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.428e-03  1.616e-03  -0.884   0.3783    
## z.lag.1     -3.483e-01  7.237e-02  -4.813 4.06e-06 ***
## tt           1.423e-05  2.054e-05   0.693   0.4898    
## z.diff.lag  -1.844e-01  8.088e-02  -2.279   0.0243 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.009195 on 130 degrees of freedom
## Multiple R-squared:  0.2688, Adjusted R-squared:  0.2519 
## F-statistic: 15.93 on 3 and 130 DF,  p-value: 7.031e-09
## 
## 
## Value of test-statistic is: -4.8128 7.9497 11.7426 
## 
## Critical values for test statistics: 
##       1pct  5pct 10pct
## tau3 -3.99 -3.43 -3.13
## phi2  6.22  4.75  4.07
## phi3  8.43  6.49  5.47
dlnPCE = diff(PCE.ts)
dlnDPI = diff(DPI.ts)
modelo3 = lm(dlnPCE~dlnDPI)
summary(modelo3)
## 
## Call:
## lm(formula = dlnPCE ~ dlnDPI)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.039263 -0.004656  0.000486  0.004847  0.039199 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 0.005772   0.001040   5.552 1.48e-07 ***
## dlnDPI      0.336966   0.069578   4.843 3.50e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.009362 on 133 degrees of freedom
## Multiple R-squared:  0.1499, Adjusted R-squared:  0.1435 
## F-statistic: 23.45 on 1 and 133 DF,  p-value: 3.499e-06
res3=modelo3$residuals
res3_1 = lag(res3)
MCE = lm(dlnPCE ~ dlnDPI + res3_1)
summary(MCE)
## 
## Call:
## lm(formula = dlnPCE ~ dlnDPI + res3_1)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.035477 -0.005194  0.000119  0.005468  0.041716 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.004802   0.001045   4.593 1.01e-05 ***
## dlnDPI       0.423487   0.071830   5.896 2.99e-08 ***
## res3_1      -0.238421   0.087117  -2.737  0.00707 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.009041 on 131 degrees of freedom
##   (1 observation deleted due to missingness)
## Multiple R-squared:  0.216,  Adjusted R-squared:  0.204 
## F-statistic: 18.05 on 2 and 131 DF,  p-value: 1.195e-07
MCE$coefficients[3]
##     res3_1 
## -0.2384208
abs(MCE$coefficients[3])
##    res3_1 
## 0.2384208