library(wooldridge)
data(hprice1)
#Visualizacion de las primeras 5 observaciones
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
library(stargazer)
regresion_wool<-lm(formula = price ~ lotsize + sqrft + bdrms, data = hprice1)
stargazer(regresion_wool, title="Estimación Modelo Price", type = "text")
##
## Estimación Modelo Price
## ===============================================
## Dependent variable:
## ---------------------------
## price
## -----------------------------------------------
## lotsize 0.002***
## (0.001)
##
## sqrft 0.123***
## (0.013)
##
## bdrms 13.853
## (9.010)
##
## Constant -21.770
## (29.475)
##
## -----------------------------------------------
## Observations 88
## R2 0.672
## Adjusted R2 0.661
## Residual Std. Error 59.833 (df = 84)
## F Statistic 57.460*** (df = 3; 84)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
library(stargazer)
matriz_X<-model.matrix(regresion_wool)
matriz_XX<-t(matriz_X)%*%matriz_X
matriz_Normalizacion<-solve(diag(sqrt(diag(matriz_XX))))
matriz_Normalizada<-(matriz_Normalizacion%*%matriz_XX)%*%matriz_Normalizacion
autovalores_Normalizada<-eigen(matriz_Normalizada,symmetric = TRUE)
indice_Condicion<-sqrt(max(autovalores_Normalizada$values)/min(autovalores_Normalizada$values))
stargazer(indice_Condicion, title = "Indice de Condición", type = "text", digits = 16)
##
## Indice de Condición
## ===================
## 11.8677800000000000
## -------------------
#indice de Condición
#eigprop(mod = regresion_wool)
library(mctest)
library(psych)
library(fastGraph)
library(stargazer)
#Prueba FG
prueba_FG<-cortest.bartlett(matriz_X[,-1])
valor_Critico<-qchisq(0.05, prueba_FG$df, lower.tail = FALSE)
print(prueba_FG)
## $chisq
## [1] 31.38122
##
## $p.value
## [1] 7.065806e-07
##
## $df
## [1] 3
#Prueba FG Version Grafica
shadeDist(xshade= prueba_FG$chisq, ddist = "dchisq", parm1 = prueba_FG$df, lower.tail = FALSE, sub = paste("VC:" ,valor_Critico, "FG:" ,prueba_FG$chisq), col = "blue")
Como P-Value es menor que 0.05 podemos decir quew existe evidencia pra rechazar la hipotesis nula es decir que existe colinealidad
#VIF por medio de la librería "CAR"
library(car)
VIF_car<-vif(regresion_wool)
stargazer(VIF_car, title = "F. Inflacionarios de la Varianza", type = "text", digits = 8)
##
## F. Inflacionarios de la Varianza
## ================================
## lotsize sqrft bdrms
## --------------------------------
## 1.03721100 1.41865400 1.39666300
## --------------------------------
#VIF Forma Gráfica
library(mctest)
mc.plot(x = matriz_X[,-1], y = hprice1$price, vif = 2, mod = regresion_wool)