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
ck = read.xls("/Users/ferarevalo1/Documents/Econometria 1 /CasoK.xls")
ck
## Trimestre CT YT
## 1 1 192.5 202.3
## 2 2 196.1 197.1
## 3 3 196.9 202.9
## 4 4 197.0 202.2
## 5 5 198.1 203.5
## 6 6 199.0 211.7
## 7 7 199.4 215.3
## 8 8 200.6 215.1
## 9 9 199.9 212.9
## 10 10 203.6 213.9
## 11 11 204.8 214.0
## 12 12 209.0 214.9
## 13 13 210.7 228.0
## 14 14 214.2 227.3
## 15 15 225.6 232.0
## 16 16 217.0 236.1
## 17 17 222.3 230.9
## 18 18 214.5 236.3
## 19 19 217.5 239.1
## 20 20 219.8 240.8
## 21 21 220.0 238.1
## 22 22 222.7 240.9
## 23 23 223.8 245.8
## 24 24 230.2 248.8
## 25 25 234.0 253.3
## 26 26 236.2 256.1
## 27 27 236.0 255.9
## 28 28 234.1 255.9
## 29 29 233.4 254.4
## 30 30 236.4 254.8
## 31 31 239.0 257.0
## 32 32 243.2 260.9
## 33 33 248.7 263.0
## 34 34 253.7 271.5
## 35 35 259.9 276.5
## 36 36 261.8 281.4
## 37 37 263.2 282.0
## 38 38 263.7 286.2
## 39 39 263.4 287.7
## 40 40 266.9 291.0
## 41 41 268.9 291.1
## 42 42 270.4 294.6
## 43 43 273.4 296.1
## 44 44 272.1 293.3
## 45 45 268.9 291.3
## 46 46 270.9 292.6
## 47 47 274.4 299.9
## 48 48 278.7 302.1
## 49 49 283.8 305.9
## 50 50 289.7 312.5
## 51 51 290.8 311.3
## 52 52 292.8 313.2
## 53 53 295.4 315.4
## 54 54 299.5 320.3
## 55 55 298.6 321.0
## 56 56 299.6 320.1
## 57 57 297.0 318.4
## 58 58 301.6 324.8
library("lmtest")
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
reg1 = lm(formula = ck$CT ~ ck$YT, data = ck)
summary(reg1)
##
## Call:
## lm(formula = ck$CT ~ ck$YT, data = ck)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.0753 -2.8531 -0.5755 2.8859 9.0922
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 13.20030 3.37935 3.906 0.000255 ***
## ck$YT 0.88182 0.01279 68.935 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.719 on 56 degrees of freedom
## Multiple R-squared: 0.9884, Adjusted R-squared: 0.9881
## F-statistic: 4752 on 1 and 56 DF, p-value: < 2.2e-16
dwtest(reg1)
##
## Durbin-Watson test
##
## data: reg1
## DW = 1.1101, p-value = 9.213e-05
## alternative hypothesis: true autocorrelation is greater than 0
resid(reg1)
## 1 2 3 4 5 6
## 0.90675637 9.09223996 4.77766211 5.49493875 5.44856785 -0.88238703
## 7 8 9 10 11 12
## -3.65695258 -2.28058783 -1.04057555 1.77760069 2.88941831 6.29577692
## 13 14 15 16 17 18
## -3.55611441 0.56116222 7.81659052 -4.39888692 5.48659667 -7.07525167
## 19 20 21 22 23 24
## -6.54435821 -5.74345862 -3.16253445 -2.93164099 -6.15257745 -2.39804874
## 25 26 27 28 29 30
## -2.56625569 -2.83536223 -2.85899748 -4.75899748 -4.13626183 -1.48899134
## 31 32 33 34 35 36
## -0.82900362 -0.06811631 3.58005378 1.08455177 2.87543294 0.45449649
## 37 38 39 40 41 42
## 1.32540223 -1.87825759 -3.50099324 -2.91101167 -0.99919404 -2.58557722
## 43 44 45 46 47 48
## -0.90831287 0.26079367 -1.17555880 -0.32192969 -3.25924318 -0.89925547
## 49 50 51 52 53 54
## 0.84981422 0.92977737 3.08796589 3.41250073 4.07248845 3.85155199
## 55 56 57 58
## 2.33427536 4.12791675 3.02701715 1.98334505
barplot(resid(reg1))
## Si hay autocorrelacion positiva
ck2 = read.xls("/Users/ferarevalo1/Documents/Econometria 1 /CasoK2.xls")
reg2 = lm(formula = ck2$Error ~ ck2$Errort)
summary(reg2)
##
## Call:
## lm(formula = ck2$Error ~ ck2$Errort)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.5276 -1.6867 0.2818 2.0271 8.6741
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.01574 0.43782 0.036 0.971443
## ck2$Errort 0.44420 0.12011 3.698 0.000496 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.334 on 56 degrees of freedom
## Multiple R-squared: 0.1963, Adjusted R-squared: 0.1819
## F-statistic: 13.68 on 1 and 56 DF, p-value: 0.0004961