1. Carga 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
2. Estimacion del Modelo
modelo_hprice1<-lm(formula = price~ (lotsize) + (sqrft) + (bdrms) , data = hprice1)
library(stargazer)
stargazer(modelo_hprice1, title = "hprice1", type = "text", digits = 8)
##
## hprice1
## ===============================================
## Dependent variable:
## ---------------------------
## price
## -----------------------------------------------
## lotsize 0.00206771***
## (0.00064213)
##
## sqrft 0.12277820***
## (0.01323741)
##
## bdrms 13.85252000
## (9.01014500)
##
## Constant -21.77031000
## (29.47504000)
##
## -----------------------------------------------
## Observations 88
## R2 0.67236220
## Adjusted R2 0.66066090
## Residual Std. Error 59.83348000 (df = 84)
## F Statistic 57.46023000*** (df = 3; 84)
## ===============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
a) Use la libreria lmtest para verificar si su varianza residual es homocedástica a través de la prueba de White (incluya los términos cruzados).
Prueba de White
library(lmtest)
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.0.5
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
white_test<-bptest(modelo_hprice1,price~lotsize+sqrft+bdrms,data=hprice1)
print(white_test)
##
## studentized Breusch-Pagan test
##
## data: modelo_hprice1
## BP = 14.092, df = 3, p-value = 0.002782
Libreria fastGraph
options(scipen = 99999)
#Crear Matriz de Coef. Desv. p_value
Coef_modelo<-summary(modelo_hprice1)$coefficients
t_values<-Coef_modelo[,"t value"]
etiquetas<-names(t_values)
#Gráficas Pruebas t
for(j in 2:3){
tc<-t_values[j]
t_VC<-
fastGraph:: shadeDist( c(-tc, tc ), "dt", 13,col=c("black","red"),sub=paste("Parámetro de la Variable:",etiquetas[j]))
print(confint(modelo_hprice1,parm = j,level = 0.95))}

## 2.5 % 97.5 %
## lotsize 0.000790769 0.003344644

## 2.5 % 97.5 %
## sqrft 0.09645415 0.1491022