Cargamos los datos y corremos el modelo.

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
library(stargazer)
modelo_lineal<-lm(formula = price~lotsize+sqrft+bdrms,data = hprice1)
stargazer(modelo_lineal, title = "Precio de lotes",type = "text")
## 
## Precio de lotes
## ===============================================
##                         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
  1. PRUEBA DE WHITE USANDO LMTEST

Carga de datos

u_i<-modelo_lineal$residuals
datos_modelo<-as.data.frame(cbind(hprice1$price,hprice1$lotsize,hprice1$sqrft,hprice1$bdrms))
names(datos_modelo)<-c("Y","X1","X2","X3")

-Implementamos la prueba

library(lmtest)
options(scipen = 999999)
prueba_de_white<-bptest(modelo_lineal,~I(X1^2)+I(X2^2)+I(X3^2)+X1*X2+X1*X3+X2*X3,data = datos_modelo)
print(prueba_de_white)
## 
##  studentized Breusch-Pagan test
## 
## data:  modelo_lineal
## BP = 33.732, df = 9, p-value = 0.00009953

Interpretacion de resultados: Dado que el valor p es inferior al nivel de significancia rechazamos la hipotesis nula, lo cual sugiere que hay evidencia de heterocedasticidad en los residuos del modelo.

  1. PRESENTACION DE RESULTADOS CON FASTGRAPH.
library(fastGraph)
matriz_x<-model.matrix(modelo_lineal)
m<-ncol(matriz_x[,-1])
gl<-9
vc<-qchisq(p=0.95,df=gl)
#Aplicamos la libreria 
shadeDist(xshade = prueba_de_white$statistic,ddist = "dchisq",parm1 =gl,lower.tail = FALSE,sub=paste("vc",vc,"W",prueba_de_white$statistic ))