library(wooldridge)
## Warning: package 'wooldridge' was built under R version 4.0.5
data(hprice1)
head(force(hprice1),n=5)
## price assess bdrms lotsize sqrft colonial lprice lassess llotsize lsqrft
## 1 300 349.1 4 6126 2438 1 5.703783 5.855359 8.720297 7.798934
## 2 370 351.5 3 9903 2076 1 5.913503 5.862210 9.200593 7.638198
## 3 191 217.7 3 5200 1374 0 5.252274 5.383118 8.556414 7.225482
## 4 195 231.8 3 4600 1448 1 5.273000 5.445875 8.433811 7.277938
## 5 373 319.1 4 6095 2514 1 5.921578 5.765504 8.715224 7.829630
options(scipen = 999999)
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
modelo_precios<-lm(formula = price ~ lotsize + sqrft + bdrms, data = hprice1)
summary(modelo_precios)
##
## Call:
## lm(formula = price ~ lotsize + sqrft + bdrms, data = hprice1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -120.026 -38.530 -6.555 32.323 209.376
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -21.7703081 29.4750419 -0.739 0.46221
## lotsize 0.0020677 0.0006421 3.220 0.00182 **
## sqrft 0.1227782 0.0132374 9.275 0.0000000000000166 ***
## bdrms 13.8525217 9.0101454 1.537 0.12795
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 59.83 on 84 degrees of freedom
## Multiple R-squared: 0.6724, Adjusted R-squared: 0.6607
## F-statistic: 57.46 on 3 and 84 DF, p-value: < 0.00000000000000022
library(mctest)
library(stargazer)
library(haven)
## Warning: package 'haven' was built under R version 4.0.5
source(file = "C:/Users/Logistica4sv/Downloads/correccion_eigprop.R")
my_eigprop(mod = modelo_precios)
##
## Call:
## my_eigprop(mod = modelo_precios)
##
## Eigenvalues CI (Intercept) lotsize sqrft bdrms
## 1 3.4816 1.0000 0.0037 0.0278 0.0042 0.0029
## 2 0.4552 2.7656 0.0068 0.9671 0.0061 0.0051
## 3 0.0385 9.5082 0.4726 0.0051 0.8161 0.0169
## 4 0.0247 11.8678 0.5170 0.0000 0.1737 0.9750
##
## ===============================
## Row 2==> lotsize, proportion 0.967080 >= 0.50
## Row 3==> sqrft, proportion 0.816079 >= 0.50
## Row 4==> bdrms, proportion 0.975026 >= 0.50
#La multicolinealidad es leve por ser <20, no se considera un problema.
2.1 Indicie de condicion manual
Xmat<-model.matrix(modelo_precios)
print(Xmat)
## (Intercept) lotsize sqrft bdrms
## 1 1 6126 2438 4
## 2 1 9903 2076 3
## 3 1 5200 1374 3
## 4 1 4600 1448 3
## 5 1 6095 2514 4
## 6 1 8566 2754 5
## 7 1 9000 2067 3
## 8 1 6210 1731 3
## 9 1 6000 1767 3
## 10 1 2892 1890 3
## 11 1 6000 2336 4
## 12 1 7047 2634 5
## 13 1 12237 3375 3
## 14 1 6460 1899 3
## 15 1 6519 2312 3
## 16 1 3597 1760 4
## 17 1 5922 2000 4
## 18 1 7123 1774 3
## 19 1 5642 1376 3
## 20 1 8602 1835 4
## 21 1 5494 2048 3
## 22 1 7800 2124 3
## 23 1 6003 1768 3
## 24 1 5218 1732 4
## 25 1 9425 1440 3
## 26 1 6114 1932 3
## 27 1 6710 1932 3
## 28 1 8577 2106 3
## 29 1 8400 3529 7
## 30 1 9773 2051 4
## 31 1 4806 1573 4
## 32 1 15086 2829 4
## 33 1 5763 1630 3
## 34 1 6383 1840 4
## 35 1 9000 2066 4
## 36 1 3500 1702 4
## 37 1 10892 2750 4
## 38 1 15634 3880 5
## 39 1 6400 1854 4
## 40 1 8880 1421 2
## 41 1 6314 1662 3
## 42 1 28231 3331 5
## 43 1 7050 1656 4
## 44 1 5305 1171 3
## 45 1 6637 2293 5
## 46 1 7834 1764 3
## 47 1 1000 2768 3
## 48 1 8112 3733 4
## 49 1 5850 1536 3
## 50 1 6660 1638 4
## 51 1 6637 1972 3
## 52 1 15267 1478 2
## 53 1 5146 1408 3
## 54 1 6017 1812 3
## 55 1 8410 1722 3
## 56 1 5625 1780 4
## 57 1 5600 1674 4
## 58 1 6525 1850 4
## 59 1 6060 1925 3
## 60 1 5539 2343 4
## 61 1 7566 1567 3
## 62 1 5484 1664 4
## 63 1 5348 1386 6
## 64 1 15834 2617 5
## 65 1 8022 2321 4
## 66 1 11966 2638 4
## 67 1 8460 1915 4
## 68 1 15105 2589 4
## 69 1 10859 2709 4
## 70 1 6300 1587 3
## 71 1 11554 1694 3
## 72 1 6000 1536 3
## 73 1 31000 3662 5
## 74 1 4054 1736 3
## 75 1 20700 2205 2
## 76 1 5525 1502 3
## 77 1 92681 1696 4
## 78 1 8178 2186 3
## 79 1 5944 1928 4
## 80 1 18838 1294 3
## 81 1 4315 1535 4
## 82 1 5167 1980 3
## 83 1 7893 2090 4
## 84 1 6056 1837 3
## 85 1 5828 1715 3
## 86 1 6341 1574 3
## 87 1 6362 1185 2
## 88 1 4950 1774 4
## attr(,"assign")
## [1] 0 1 2 3
library(mctest)
mctest(modelo_precios)
##
## Call:
## omcdiag(mod = mod, Inter = TRUE, detr = detr, red = red, conf = conf,
## theil = theil, cn = cn)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.6918 0
## Farrar Chi-Square: 31.3812 1
## Red Indicator: 0.3341 0
## Sum of Lambda Inverse: 3.8525 0
## Theil's Method: -0.7297 0
## Condition Number: 11.8678 0
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
library(psych)
## Warning: package 'psych' was built under R version 4.0.5
library(fastGraph)
## Warning: package 'fastGraph' was built under R version 4.0.5
FG_test<-cortest.bartlett(Xmat[,-1])
## R was not square, finding R from data
print(FG_test)
## $chisq
## [1] 31.38122
##
## $p.value
## [1] 0.0000007065806
##
## $df
## [1] 3
VC_1<-qchisq(0.05,FG_test$df,lower.tail = FALSE)
shadeDist(xshade = FG_test$chisq,
ddist = "dchisq",
parm1 = FG_test$df,
lower.tail = FALSE,
sub=paste("VC:",VC_1,"FG:",FG_test$chisq))
Valor critico de 7.814 y prueba FG redondeada, se rechaza la Ho.
library(mctest)
mc.plot(modelo_precios, vif = 2)