Pruebas de Normalidad

#carga de datos 
library(wooldridge)
data(hprice1)
head(force(hprice1),n=5) #mostrar las primeras 5 observaciones
##   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. Estimación del modelo
library(stargazer)
estimacion_modelo<-lm(formula = price~lotsize+sqrft+bdrms,data = hprice1)
stargazer(estimacion_modelo,title = "estimación del modelo",type = "text")
## 
## estimación del modelo
## ===============================================
##                         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
library(fitdistrplus)
ajuste_normal<-fitdist(data = estimacion_modelo$residuals, distr = 'norm')
plot(ajuste_normal)

summary(ajuste_normal)
## Fitting of the distribution ' norm ' by maximum likelihood 
## Parameters : 
##          estimate Std. Error
## mean 9.992007e-16   6.231624
## sd   5.845781e+01   4.406424
## Loglikelihood:  -482.8775   AIC:  969.7549   BIC:  974.7096 
## Correlation matrix:
##      mean sd
## mean    1  0
## sd      0  1

1.Prueba de Normalidad de Jarque - Bera

library(normtest)
jb.norm.test(estimacion_modelo$residuals)
## 
##  Jarque-Bera test for normality
## 
## data:  estimacion_modelo$residuals
## JB = 32.278, p-value < 2.2e-16

#Jarque-Bera con fastGraph

##Jarque-Bera con fastGraph
library(fastGraph)
library(psych)
options(scipen = 9)
mat_2<-model.matrix(estimacion_modelo)
Grafica_JB<-cortest.bartlett(mat_2[,-1])
print(Grafica_JB)
## $chisq
## [1] 31.38122
## 
## $p.value
## [1] 0.0000007065806
## 
## $df
## [1] 3
VC_JB<-qchisq(0.95,Grafica_JB$df)
print(VC_JB)
## [1] 7.814728
shadeDist(Grafica_JB$chisq,ddist = "dchisq",parm1 = Grafica_JB$df,lower.tail = FALSE,sub=paste("vc:",VC_JB,"FG:",Grafica_JB$chisq))

2.Prueba de Normalidad de Kolmogorov - Smirnov

library(nortest)
lillie.test((estimacion_modelo$residuals))
## 
##  Lilliefors (Kolmogorov-Smirnov) normality test
## 
## data:  (estimacion_modelo$residuals)
## D = 0.075439, p-value = 0.2496

3.Prueba de Normalidad de Shapiro - Wilk

shapiro.test(estimacion_modelo$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  estimacion_modelo$residuals
## W = 0.94132, p-value = 0.0005937

##Shapiro-Wilk con fastGraph

##Shapiro-Wilk con fastGraph
shapiro.test(estimacion_modelo$residuals)
## 
##  Shapiro-Wilk normality test
## 
## data:  estimacion_modelo$residuals
## W = 0.94132, p-value = 0.0005937
qqnorm(estimacion_modelo$residuals)
qqline(estimacion_modelo$residuals)

library(fastGraph)
shadeDist(0.94132,parm1 = 0,ddist ="dnorm",lower.tail = F)