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
1. Estime el modelo
library(stargazer)
options(scipen = 999999)
modelo_hprice1<-lm(formula = price~bdrms+lotsize+sqrft,data = hprice1)
stargazer(modelo_hprice1,title = "Modelo hprice1",type = "text",digits = 8)
##
## Modelo hprice1
## ===============================================
## Dependent variable:
## ---------------------------
## price
## -----------------------------------------------
## bdrms 13.85252000
## (9.01014500)
##
## lotsize 0.00206771***
## (0.00064213)
##
## sqrft 0.12277820***
## (0.01323741)
##
## 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
Prueba de Normalidad de los residuos
library(fitdistrplus)
library(stargazer)
fit_normal<-fitdist(data = modelo_hprice1$residuals,distr = "norm")
## $start.arg
## $start.arg$mean
## [1] 0.0000000000000005451369
##
## $start.arg$sd
## [1] 58.45781
##
##
## $fix.arg
## NULL
plot(fit_normal)

summary(fit_normal)
## Fitting of the distribution ' norm ' by maximum likelihood
## Parameters :
## estimate Std. Error
## mean 0.0000000000000005451369 6.231624
## sd 58.4578135693031910591344 4.406423
## Loglikelihood: -482.8775 AIC: 969.7549 BIC: 974.7096
## Correlation matrix:
## mean sd
## mean 1 0
## sd 0 1
2. Verifique el supuesto de normalidad, a través de:
a) La prueba JB
library(stargazer)
library(normtest)
jb.norm.test(modelo_hprice1$residuals)
##
## Jarque-Bera test for normality
##
## data: modelo_hprice1$residuals
## JB = 32.278, p-value < 0.00000000000000022
Graficando los resultados
library(stargazer)
library(fastGraph)
gl<-2
VC<-qchisq(p = 0.95, df=gl)
prueba_JB<-jb.norm.test(modelo_hprice1$residuals)
print(prueba_JB)
##
## Jarque-Bera test for normality
##
## data: modelo_hprice1$residuals
## JB = 32.278, p-value = 0.0015
shadeDist(xshade = prueba_JB$statistic, ddist = "dchisq", parm1 = gl,
lower.tail = FALSE, sub = paste("VC:", VC, "JB:", prueba_JB$statistic))

b. La prueba KS
library(stargazer)
library(nortest)
lillie.test(modelo_hprice1$residuals)
##
## Lilliefors (Kolmogorov-Smirnov) normality test
##
## data: modelo_hprice1$residuals
## D = 0.075439, p-value = 0.2496
qqnorm(modelo_hprice1$residuals)
qqline(modelo_hprice1$residuals)

hist(modelo_hprice1$residuals,main = "Histograma de los residuos",xlab = "Residuos",ylab = "frecuencia")

c. La prueba SW
library(stargazer)
shapiro.test(modelo_hprice1$residuals)
##
## Shapiro-Wilk normality test
##
## data: modelo_hprice1$residuals
## W = 0.94132, p-value = 0.0005937
Graficando
library(stargazer)
library(fastGraph)
X_mat<-model.matrix(modelo_hprice1)
m<-ncol(X_mat[,-1])
n<-nrow(X_mat[,-1])
gl<-m*(m-1)/2
VC<-qchisq(p = 0.95, df=gl)
prueba_SW<-shapiro.test(modelo_hprice1$residuals)
print(prueba_JB)
##
## Jarque-Bera test for normality
##
## data: modelo_hprice1$residuals
## JB = 32.278, p-value = 0.0015
shadeDist(xshade = prueba_SW$statistic, ddist = "dchisq", parm1 = gl,
lower.tail = FALSE, sub = paste("VC:", VC, "sw:", prueba_SW$statistic))
