library(wooldridge)
library(printr)
data(hprice1)
head(force(hprice1),n=5)
| 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 |
Estimando el modelo
modelo_precio<-lm(formula = price~lotsize+sqrft+bdrms,data = hprice1)
library(stargazer)
stargazer(modelo_precio,title="Modelo Precio",type = "html", digits=4)
Modelo Precio
|
|
|
|
Dependent variable:
|
|
|
|
|
|
price
|
|
|
|
lotsize
|
0.0021***
|
|
|
(0.0006)
|
|
|
|
|
sqrft
|
0.1228***
|
|
|
(0.0132)
|
|
|
|
|
bdrms
|
13.8525
|
|
|
(9.0101)
|
|
|
|
|
Constant
|
-21.7703
|
|
|
(29.4750)
|
|
|
|
|
|
|
Observations
|
88
|
|
R2
|
0.6724
|
|
Adjusted R2
|
0.6607
|
|
Residual Std. Error
|
59.8335 (df = 84)
|
|
F Statistic
|
57.4602*** (df = 3; 84)
|
|
|
|
Note:
|
p<0.1; p<0.05; p<0.01
|
Prueba de White
library(lmtest)
Wtest<-bptest(modelo_precio,~I(lotsize^2)+I(sqrft^2)+I(bdrms^2)+lotsize*sqrft+lotsize*bdrms+sqrft*bdrms,data = hprice1)
print(Wtest)
##
## studentized Breusch-Pagan test
##
## data: modelo_precio
## BP = 33.732, df = 9, p-value = 0.00009953
gl=3*2+choose(3,2)
VC<-qchisq(p = 0.95,df = gl)
library(fastGraph)
shadeDist(Wtest$statistic,ddist = 'dchisq',col=c('black','skyblue'),parm1 =VC,lower.tail = FALSE)

Como \(LM_{W}>VC\) se rechaza la hipotesis nula y se dice que existe evidencia de heterocedasticidad en el modelo