Clase 27-3 Econometría

Autor/a

Juan Creide

Importar datos

library(readr)
poblacion <- read_csv("Archivos/datos_heterocedasticidad.csv")
Rows: 9959 Columns: 2
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (2): Ingreso, Gasto_Educacion

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(poblacion)
# A tibble: 6 × 2
  Ingreso Gasto_Educacion
    <dbl>           <dbl>
1  35882.           4702.
2  80947.          14659.
3  46808.           3996.
4  89472.          17573.
5  94642.          15800.
6  14100.           3646.

Los datos corresponden a una población simulada:

\[ \text{GastoEduc}_i = 2000 + 0.1 \times \text{Ingreso}_i + u_i \]

Donde:

\[ u_i \sim N(\mu = 0, \sigma = \text{Ingreso} \times 0.05) \]

Diagrama de dispersión

set.seed(123)
datos = poblacion[sample(nrow(poblacion), size=100, replace = FALSE), ]
plot(x = datos$Ingreso,
     y = datos$Gasto_Educacion,
     xlab = "Ingreso", ylab= "Gasto en Educación",
     main = "Diagrama de Dispersión: Gasto en Educación vs Ingreso")

Modelo naive

attach(datos)
modelo_naive = lm(Gasto_Educacion ~ Ingreso)
summary(modelo_naive)

Call:
lm(formula = Gasto_Educacion ~ Ingreso)

Residuals:
    Min      1Q  Median      3Q     Max 
-8116.7 -1450.2   145.9  1553.0 10151.0 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 1.631e+03  7.150e+02   2.281   0.0247 *  
Ingreso     1.093e-01  1.173e-02   9.319 3.64e-15 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 3105 on 98 degrees of freedom
Multiple R-squared:  0.4698,    Adjusted R-squared:  0.4644 
F-statistic: 86.85 on 1 and 98 DF,  p-value: 3.639e-15

Regresión

plot(x = datos$Ingreso,
     y = datos$Gasto_Educacion,
     xlab = "Ingreso",
     ylab = "Gasto en Educación",
     main = "Diagrama de Dispersión: Gasto en Educación")
abline(modelo_naive, col = "red")

Diagnóstico con los residuos

plot(modelo_naive, 1,
     main = "Residuos vs Predichos")

plot(modelo_naive, 2)