Estimacion del numero de crimenes violentos en funcion de la poblacion por debajo de la linea de pobreza (poverty) y el porcentaje que es padre soltero (single).

options(scipen = 999999)
library(foreign)
library(stargazer)
datos_regresion<-read.dta("https://stats.idre.ucla.edu/stat/data/crime.dta")
modelo_estimado_1<-lm(crime~poverty+single,data = datos_regresion)
stargazer(modelo_estimado_1,type = "text",title = "Modelo Estimado")
## 
## Modelo Estimado
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                                crime           
## -----------------------------------------------
## poverty                        6.787           
##                               (8.989)          
##                                                
## single                      166.373***         
##                              (19.423)          
##                                                
## Constant                   -1,368.189***       
##                              (187.205)         
##                                                
## -----------------------------------------------
## Observations                    51             
## R2                             0.707           
## Adjusted R2                    0.695           
## Residual Std. Error      243.610 (df = 48)     
## F Statistic           57.964*** (df = 2; 48)   
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01

Pruebas de Heterocedasticidad y Autocorrelacion

Prueba de White

library(lmtest)
prueba_white<-bptest(modelo_estimado_1,~ I(poverty˄2)+I(single˄2)+poverty*single, data=datos_regresion)
print(prueba_white)
## 
##  studentized Breusch-Pagan test
## 
## data:  modelo_estimado_1
## BP = 10.73, df = 5, p-value = 0.057

Hay evidencia estadistica para establecer presencia de heterocedasticidad ya que Pvalue es menor a 0.05

Prueba de Multiplicador de Lagrange segundo orden

library(lmtest)
prueba_LM<-bgtest(modelo_estimado_1,order = 2)
print(prueba_LM)
## 
##  Breusch-Godfrey test for serial correlation of order up to 2
## 
## data:  modelo_estimado_1
## LM test = 0.27165, df = 2, p-value = 0.873

Hay evidencia estadistica para establecer que no hay evidencia de autocorrelacion de segundo orden ya que el Pvalue es mayor que 0.05

Prueba de Multiplicador de Lagrange de primer orden

library(car)
durbinWatsonTest(modelo_estimado_1)
##  lag Autocorrelation D-W Statistic p-value
##    1     -0.07014421      2.040007   0.946
##  Alternative hypothesis: rho != 0

Hay evidencia estadistica para establecer que no hay evidencia de autocorrelacion de primer orden ya que el Pvalue es mayor que 0.05

Estimacion Robusta

Sin corregir

library(lmtest)
library(sandwich)
coeftest(modelo_estimado_1)
## 
## t test of coefficients:
## 
##               Estimate Std. Error t value         Pr(>|t|)    
## (Intercept) -1368.1887   187.2052 -7.3085 0.00000000247861 ***
## poverty         6.7874     8.9885  0.7551           0.4539    
## single        166.3727    19.4229  8.5658 0.00000000003117 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Ya que el modelo esta mal por presencia de heterocedasticidad no puedo hacer una lectura correcta

Corregida utilizando estimador HAC

options(scipen = 999999)
library(lmtest)
library(sandwich)
estimacion_omega<-vcovHC(modelo_estimado_1,type = "HC0")
coeftest(modelo_estimado_1,vcov. = estimacion_omega)
## 
## t test of coefficients:
## 
##               Estimate Std. Error t value      Pr(>|t|)    
## (Intercept) -1368.1887   276.4111 -4.9498 0.00000956181 ***
## poverty         6.7874    10.6010  0.6403        0.5251    
## single        166.3727    25.4510  6.5370 0.00000003774 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Ahora podemos realizar una lectura correcta y establecer que la variable: porcentaje de la pooblacion padre soltero (single) es significativa.

Si hubiese existido presencia de autocorrelacion de segundo orden

Estimador HAC NeweyWest

library(lmtest)
library(sandwich)
estimacion_omega<-NeweyWest(modelo_estimado_1,lag = 2)
coeftest(modelo_estimado_1,vcov. = estimacion_omega)
## 
## t test of coefficients:
## 
##               Estimate Std. Error t value      Pr(>|t|)    
## (Intercept) -1368.1887   303.8466 -4.5029 0.00004279768 ***
## poverty         6.7874    10.5943  0.6407        0.5248    
## single        166.3727    25.9154  6.4198 0.00000005708 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Uso de libreria Stargazer para presentar el modelo original y el corregido

library(stargazer)
library(sandwich)

## Modelo sin correción (Por defecto) y Corregido (Calculo Robusto)
estimacion_omega <- vcovHC(modelo_estimado_1,type = "HC1")
Robusto <- sqrt(diag(estimacion_omega))
stargazer(modelo_estimado_1, modelo_estimado_1, se = list(NULL, Robusto),
          column.labels = c("Por Defecto", "Calculo Robusto"), align = T, 
          type = "text",
          title="Comparativa de Modelos")
## 
## Comparativa de Modelos
## ===========================================================
##                                    Dependent variable:     
##                               -----------------------------
##                                           crime            
##                                Por Defecto  Calculo Robusto
##                                    (1)            (2)      
## -----------------------------------------------------------
## poverty                           6.787          6.787     
##                                  (8.989)       (10.927)    
##                                                            
## single                         166.373***     166.373***   
##                                 (19.423)       (26.234)    
##                                                            
## Constant                      -1,368.189***  -1,368.189*** 
##                                 (187.205)      (284.918)   
##                                                            
## -----------------------------------------------------------
## Observations                       51             51       
## R2                                0.707          0.707     
## Adjusted R2                       0.695          0.695     
## Residual Std. Error (df = 48)    243.610        243.610    
## F Statistic (df = 2; 48)        57.964***      57.964***   
## ===========================================================
## Note:                           *p<0.1; **p<0.05; ***p<0.01