EXPORTACION DE DATOS

library(wooldridge)
## Warning: package 'wooldridge' was built under R version 4.2.3
data(hprice1)
head(force(hprice1),n=5) #mostrar las primeras 5 observaciones
price assess bdrms lotsize sqrft colonial lprice lassess llotsize lsqrft
300 349.1 4 6126 2438 1 5.703783 5.855359 8.720297 7.798934
370 351.5 3 9903 2076 1 5.913503 5.862210 9.200593 7.638198
191 217.7 3 5200 1374 0 5.252274 5.383118 8.556414 7.225481
195 231.8 3 4600 1448 1 5.273000 5.445875 8.433811 7.277938
373 319.1 4 6095 2514 1 5.921578 5.765504 8.715224 7.829630

ESTIMACION DEL MODELO

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

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) -2.177e+01 2.948e+01 -0.739 0.46221
lotsize 2.068e-03 6.421e-04 3.220 0.00182 ** sqrft 1.228e-01 1.324e-02 9.275 1.66e-14 *** bdrms 1.385e+01 9.010e+00 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: < 2.2e-16

PRUEBA DE WHITE

library(lmtest)
## Warning: package 'lmtest' was built under R version 4.2.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.2.3
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
prueba_white=bptest(Modelo_estimado, ~ I(lotsize^2) + I(sqrft^2)+I(bdrms^2)+lotsize*sqrft+sqrft*bdrms,data=hprice1 )
print(prueba_white)
## 
##  studentized Breusch-Pagan test
## 
## data:  Modelo_estimado
## BP = 32.648, df = 8, p-value = 7.127e-05

Interpretacion: como el p-value es menor al nivel de significancia de 0.05 hay Hay evidencia de que la varianza de los residuos es Heterocedástica.

library(fastGraph)
## Warning: package 'fastGraph' was built under R version 4.2.3
prueba=prueba_white$statistic
gl=3+3+2
alpha_sig<-0.05
VC<-qchisq(p = 0.95,df = gl)
shadeDist(prueba,ddist = "dchisq",
          parm1 = gl,
          lower.tail = FALSE,xmin=0,
          sub=paste("VC:",round(VC,2)," ","Prueba_de_white:",round(prueba,2)))

PREUBA MANUAL

library(stargazer)
u_i<-Modelo_estimado$residuals
data_prueba_white<-as.data.frame(cbind(u_i,hprice1))
regresion_auxiliar<-lm(I(u_i^2) ~ lotsize + sqrft + bdrms +I(lotsize^2) + I(sqrft^2)+I(bdrms^2) + lotsize:sqrft + lotsize:bdrms + sqrft:bdrms,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+2
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)
## 
## <table style="text-align:center"><caption><strong>Resultados de la prueba de White</strong></caption>
## <tr><td colspan="3" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">LMw</td><td>Valor Crítico</td><td>p value</td></tr>
## <tr><td colspan="3" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">33.731660</td><td>15.507310</td><td>0.000045</td></tr>
## <tr><td colspan="3" style="border-bottom: 1px solid black"></td></tr></table>

Interpretacion como el P-value es muy bajo al nivel de significacia la hipotesis nula se rechaza y por lo tanto Hay evidencia de que la varianza de los residuos es Heterocedástica.