library("gdata")
## gdata: read.xls support for 'XLS' (Excel 97-2004) files ENABLED.
##
## gdata: read.xls support for 'XLSX' (Excel 2007+) files ENABLED.
##
## Attaching package: 'gdata'
## The following object is masked from 'package:stats':
##
## nobs
## The following object is masked from 'package:utils':
##
## object.size
library("lmtest")
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
cb = read.xls("/Users/ferarevalo1/Documents/Econometria 1 /CasoB.xls")
reg3 = lm(formula = cb$Cpdes ~ cb$ppib, data = cb)
summary(reg3)
##
## Call:
## lm(formula = cb$Cpdes ~ cb$ppib, data = cb)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.6865 -0.2715 -0.0728 0.3053 6.9449
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.3222 0.4312 3.066 0.004036 **
## cb$ppib -0.4477 0.1224 -3.658 0.000787 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.669 on 37 degrees of freedom
## Multiple R-squared: 0.2656, Adjusted R-squared: 0.2457
## F-statistic: 13.38 on 1 and 37 DF, p-value: 0.0007874
dwtest(reg3)
##
## Durbin-Watson test
##
## data: reg3
## DW = 2.9747, p-value = 0.9994
## alternative hypothesis: true autocorrelation is greater than 0
resid(reg3)
## 1 2 3 4 5
## 0.574620051 -0.890795191 1.488293261 0.295531598 0.137354693
## 6 7 8 9 10
## 0.185075824 -0.234227005 -0.156478852 0.297140317 -0.072832662
## 11 12 13 14 15
## 0.592582580 -0.198570365 -6.686505873 6.944861448 -0.689454891
## 16 17 18 19 20
## -0.186505873 0.089633561 -0.171492362 -0.211706739 0.900089335
## 21 22 23 24 25
## -0.623771231 -0.286505873 -0.702859683 0.134405674 0.192582580
## 26 27 28 29 30
## 0.247810467 0.526898919 0.313494127 -0.129669268 0.583735524
## 31 32 33 34 35
## -0.002859683 -0.255138552 -0.334227005 -0.613315457 -0.471492362
## 36 37 38 39
## -0.256478852 0.610813527 0.321000882 -1.261036589
barplot(resid(reg3))
### Aqui podemos ver que hay autocorrelacion negativa
cb$errorcuad = (resid(reg3))^2
cb$xcuad = cb$ppib^2
reg4 = lm(formula = cb$errorcuad~cb$ppib+cb$xcuad, data = cb)
summary(reg4)
##
## Call:
## lm(formula = cb$errorcuad ~ cb$ppib + cb$xcuad, data = cb)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.313 -3.164 -2.813 -1.768 44.921
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.5646 2.7558 0.568 0.574
## cb$ppib 0.8824 1.2486 0.707 0.484
## cb$xcuad -0.1096 0.2521 -0.435 0.666
##
## Residual standard error: 10.54 on 36 degrees of freedom
## Multiple R-squared: 0.0147, Adjusted R-squared: -0.04004
## F-statistic: 0.2686 on 2 and 36 DF, p-value: 0.766
v = 0.0147*39
cac = read.xls(“/Users/ferarevalo1/Documents/Econometria 1 /Caso C .xlsx”)
cac = read.xls("/Users/ferarevalo1/Documents/Econometria 1 /Caso C .xlsx")
reg5 = lm(formula = cac$Cambio~cac$Crecimiento, data = cac)
summary(reg5)
##
## Call:
## lm(formula = cac$Cambio ~ cac$Crecimiento, data = cac)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.2478 -0.7969 0.1877 0.7565 2.9353
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.3040 0.2853 4.57 0.000136 ***
## cac$Crecimiento -0.3944 0.0337 -11.70 3.64e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.326 on 23 degrees of freedom
## Multiple R-squared: 0.8562, Adjusted R-squared: 0.85
## F-statistic: 137 on 1 and 23 DF, p-value: 3.638e-11
dwtest(reg5)
##
## Durbin-Watson test
##
## data: reg5
## DW = 1.6062, p-value = 0.1261
## alternative hypothesis: true autocorrelation is greater than 0
q = resid(reg5)
barplot(q)
### Si hay autocorrelacion positiva
cac$ycuad = q^2
cac$xcuad = cac$Crecimiento^2
reg6 = lm(formula = cac$ycuad ~ cac$Cambio+cac$xcuad)
summary(reg6)
##
## Call:
## lm(formula = cac$ycuad ~ cac$Cambio + cac$xcuad)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.3869 -1.3843 -0.6847 0.1663 8.4382
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.510018 0.762964 1.979 0.0604 .
## cac$Cambio 0.236815 0.157494 1.504 0.1469
## cac$xcuad 0.001263 0.007778 0.162 0.8725
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.591 on 22 degrees of freedom
## Multiple R-squared: 0.09384, Adjusted R-squared: 0.01146
## F-statistic: 1.139 on 2 and 22 DF, p-value: 0.3383
vc = 0.09384*25
vc
## [1] 2.346