library(wooldridge)
## Warning: package 'wooldridge' was built under R version 4.2.3
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
price = ˆα + ˆα1(lotsize) + ˆα2(sqrft) + ˆα3(bdrms) + E
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
Mod.precio<-lm(formula = price~lotsize+sqrft+bdrms,data=hprice1)
stargazer(Mod.precio,title = "Modelo de precio", type = "text",digits = 4)
##
## Modelo de 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
library(stargazer)
resid<-Mod.precio$residuals
data.white<-as.data.frame(cbind(resid,hprice1))
reg.white<-lm(formula=I(resid^2)~lotsize+sqrft+bdrms+I(lotsize^2)+I(sqrft^2)+I(bdrms^2)+lotsize*sqrft+lotsize*bdrms+lotsize*lotsize+sqrft*bdrms+sqrft*sqrft+bdrms*bdrms,data.white)
Resumen<-summary(reg.white)
R.2<-Resumen$r.squared
n<-nrow(data.white)
LM.Precio<-n*R.2
gl<-3+3+3
VC<-qchisq(p=0.95,df=gl)
p.value<-1-pchisq(q=LM.Precio,df=gl)
salida.prueba<-c(LM.Precio,VC,p.value)
names(salida.prueba)<-c("LMw","Valor Crítico", "P Value")
stargazer(salida.prueba,title = "Prueba de White", type = "html",digits = 6)
| LMw | Valor Crítico | P Value |
| 33.731660 | 16.918980 | 0.000100 |
-Rechazar H0 sí LMw ≥ VC
-Rechazar H0 sí P Value ≤ α
Cómo 33.73 > 0.0001 se rechaza la H0, lo que indica que NO hay evidencia de que la varianza de los residuos es homocedastica
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
prueba.white<-bptest(Mod.precio,~I(lotsize^2)+I(sqrft^2)+I(bdrms^2)+lotsize*sqrft+lotsize*bdrms+lotsize*lotsize+sqrft*bdrms+sqrft*sqrft+bdrms*bdrms,data=hprice1)
print(prueba.white)
##
## studentized Breusch-Pagan test
##
## data: Mod.precio
## BP = 33.732, df = 9, p-value = 9.953e-05
Criterio de decisión:
-Rechazar H0 sí LMw ≥ VC
-Rechazar H0 sí P Value ≤ α
Cómo 0.000099 < 0.05 se rechaza la H0, lo que indica que NO hay evidencia de que la varianza de los residuos es homocedastica
options(scipen = 999999)
library(fastGraph)
Pw<-prueba.white
gl<-3+3+3
vc<-qchisq(p=.95,df=gl)
alpha_sig<-0.05
shadeDist(Pw$statistic,
ddist = "dchisq",
parm1 = gl,
lower.tail = FALSE,
main = "Grafica de los resultados de la prueba White",
sub=paste("LMw:", Pw$statistic, "Vc:", vc))