Elder Ariel Peréz Palacios

Importación de datos

library(wooldridge)
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

Estimación del Modelo

library(stargazer)
Modelo_hprice1 <- lm(formula = price ~ lotsize + sqrft + bdrms,data = hprice1)
stargazer(Modelo_hprice1,title = "Modelo price", type = "html")
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

Prueba White

library(stargazer)
u_i<-Modelo_hprice1$residuals
data_prueba_white<-as.data.frame(cbind(u_i,hprice1))
regresion_auxiliar<-lm(I(u_i^2)~lotsize+bdrms+sqrft+I(lotsize^2)+I(bdrms^2)+I(sqrft^2)+lotsize*bdrms + lotsize*sqrft+bdrms*sqrft,data = data_prueba_white)
sumario<-summary(regresion_auxiliar)
n<-nrow(data_prueba_white)
R_2<-sumario$r.squared
LM_w<-n*R_2
gl=3+3+3
p_value<-1-pchisq(q = LM_w,df = gl)
VC<-qchisq(p = 0.95,df = gl)
salida_white<-c(LM_w,VC,p_value)
names(salida_white)<-c("LMw","Valor Crítico","p value")
stargazer(salida_white,title = "Resultados de la prueba de White",type = "html",digits = 6)
Resultados de la prueba de White
LMw Valor Crítico p value
33.731660 16.918980 0.000100

Obtenemos un P-value 0.000100 < 0.05 se rechaza la Ho, por lo tanto hay evidencia que la varianza de los residuos es heterocedástica.

Usando la Libreria lmtest

library(lmtest)
prueba_white<-bptest(Modelo_hprice1,~I(lotsize^2)+I(bdrms^2)+I(sqrft^2)+lotsize*sqrft+lotsize*bdrms + +sqrft*bdrms,data = hprice1)
print(prueba_white)
## 
##  studentized Breusch-Pagan test
## 
## data:  Modelo_hprice1
## BP = 33.732, df = 9, p-value = 9.953e-05

Obtenemos un P-value 0.00009953 < 0.05 se rechaza la Ho, por lo tanto hay evidencia que la varianza de los residuos es heterocedástica.

library(fastGraph)
alpha_sig<-0.05
gl<-3+3+3
VC<-qchisq(1-alpha_sig,gl,lower.tail = TRUE)
shadeDist(LM_w,
          ddist = "dchisq",
          parm1 = gl,
          lower.tail = FALSE,
          xmin=0,
          sub=paste("VC:",VC," ","WH:",LM_w))