library(foreign)
datos_regresion <- read.dta("https://stats.idre.ucla.edu/stat/data/crime.dta")
modelo_estimado_1<-lm(crime~poverty+single,data=datos_regresion)
print(modelo_estimado_1)##
## Call:
## lm(formula = crime ~ poverty + single, data = datos_regresion)
##
## Coefficients:
## (Intercept) poverty single
## -1368.189 6.787 166.373
Pruebas de Heterocedasticidad y Autocorrelación.
Prueba de Breusch Pagan (White):
library(lmtest)
white_test<-bptest(modelo_estimado_1,~I(poverty^2)+I(single^2)+poverty*single,data = datos_regresion)
print(white_test)##
## studentized Breusch-Pagan test
##
## data: modelo_estimado_1
## BP = 10.73, df = 5, p-value = 0.057
Hay evidencia de heterocedasticidad ya que Pvalue < 0.05
Prueba de Breusch Godfrey (Prueba del Multiplicador)
Verificando autocorrelación de 1° orden
library(lmtest)
prueba_LM<-bgtest(modelo_estimado_1,order = 1)
print(prueba_LM)##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: modelo_estimado_1
## LM test = 0.27156, df = 1, p-value = 0.6023
No hay evidencia de autocorrelación de 1° orden ya que Pvalue < 0.05
Verificando autocorrelación de 2° 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
No hay evidencia de autocorrelación de 2° orden ya que Pvalue < 0.05
Estimación Robusta
Sin corregir
library(lmtest)
library(sandwich)
library(stargazer)
modelo_sin_corregir<-coeftest(modelo_estimado_1)
coeftest(modelo_estimado_1)##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1368.1887 187.2052 -7.3085 2.479e-09 ***
## poverty 6.7874 8.9885 0.7551 0.4539
## single 166.3727 19.4229 8.5658 3.117e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
stargazer(modelo_sin_corregir, title= "Modelo sin corregir", type = "html", digits = 6)| Dependent variable: | |
| poverty | 6.787359 |
| (8.988529) | |
| single | 166.372700*** |
| (19.422910) | |
| Constant | -1,368.189000*** |
| (187.205200) | |
| Note: | p<0.1; p<0.05; p<0.01 |
Corregido
library(stargazer)
estimacion_omega<-vcovHC(modelo_estimado_1,type = "HC1")
coeftest(modelo_estimado_1,vcov. = estimacion_omega)##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1368.1887 284.9180 -4.8020 1.577e-05 ***
## poverty 6.7874 10.9273 0.6211 0.5374
## single 166.3727 26.2343 6.3418 7.519e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
stargazer(estimacion_omega, title= "Modelo corregido", type = "html", digits = 6)| (Intercept) | poverty | single | |
| (Intercept) | 81,178.290000 | -747.835400 | -6,510.567000 |
| poverty | -747.835400 | 119.405400 | -73.603100 |
| single | -6,510.567000 | -73.603100 | 688.236700 |