class: center middle main-title section-title-8 top-logo .small[ # Regresión lineal múltiple ] .class-info[ <br> **Sesión N° 6**<br> **EstadÃsitica II** <br> .pull-right.small[ **Profesora** Valentina Andrade de la Horra <br> **Apoyo docente** Nicolás Godoy <br> **Ayudantes** Moira Martinez, Charo Astorga y Alberto Reyes .tiny[Universidad Alberto Hurtado<br> ] ] ] --- class: title title-inv-8 # Contenidos Sesión -- .box-8.medium.sp-after-half[Regresión **lineal múltiple**] -- .box-8.medium.sp-after-half[**Efectos parciales**] -- .box-8.medium.sp-after-half[**MCO supuesto: multicolinealidad**] --- class: center middle main-title section-title-8 top-logo # Supuestos Modelo Regresión Lineal --- <center> <img src="data:image/png;base64,#https://raw.githubusercontent.com/statistics-R/slides/main/img/05/03.png" alt="drawing" style="width:1000px;"/> </center> --- class: center middle main-title section-title-8 top-logo ## ¿Es realista suponer que todos los otros factores que afectan a `\(y\)` y no son incorporados en la regresión **no estén correlacionados** con `\(x\)` -- ## ¡No! --- class: center middle main-title section-title-8 top-logo # Regresión múltiple --- class: title title-8 # Regresión múltiple - Se llama **múltiple** debido a que incluye más variables al modelo -- - Herramienta muy poderosa pues podemos entender como un fenómeno que queremos explicar ( `\(y\)` ) está determinado por multiples factores ( `\(x_s\)` ) --- class: title title-8 # 1. Pregunta - Tenemos como hipótesis que **salario** es afectado por **años de educación** e **inteligencia**. -- - Eso implica que tenemos **dos variables explicativas** *(o independientes)* --- <center> <img src="data:image/png;base64,#https://raw.githubusercontent.com/statistics-R/slides/main/img/05/14.png" alt="drawing" style="width:1000px;"/> </center> --- <img src="data:image/png;base64,#06-slide_files/figure-html/unnamed-chunk-1-1.png" width="100%" style="display: block; margin: auto;" /> --- <img src="data:image/png;base64,#06-slide_files/figure-html/unnamed-chunk-2-1.png" width="100%" style="display: block; margin: auto;" /> --- class: title title-8 # 2. Formalizar el modelo teórico `$$y = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + u$$` -- - `\(y\)` = datos sobre variable dependiente - `\(x_1\)` = datos sobre variable independiente (educación) - `\(x_2\)` = datos sobre variable independiente (inteligencia) - `\(\beta_1\)` = pendiente, parámetro que indica la relación de `\(x_1\)` e `\(y\)` - `\(\beta_2\)` = pendiente, parámetro que indica la relación de `\(x_2\)` e `\(y\)` - `\(\beta_o\)` = intercepto - `\(u\)` = error --- class: center middle main-title section-title-8 top-logo # Interpretación `\(\beta_1\)` -- ##Por cada **unidad** que cambie `\(x_1\)`, `\(y\)` va a cambiar en `\(\beta_1\)`, manteniendo `\(x_2\)` constante. `$$\triangle y = \beta_1 \triangle x_1$$` $$\triangle x_2 = 0 ~~~ \triangle u = 0 $$ --- class: center middle main-title section-title-8 top-logo # Interpretación `\(\beta_2\)` -- ##Por cada **unidad** que cambie `\(x_2\)`, `\(y\)` va a cambiar en `\(\beta_1\)`, manteniendo `\(x_1\)` constante. `$$\triangle y = \beta_2 \triangle x_2$$` $$\triangle x_1 = 0~~~ \triangle u = 0 $$ --- class: title title-8 # Regresión múltiple: ejemplo .tiny[ ``` ## ## Call: ## lm(formula = wage ~ educ + IQ, data = wages) ## ## Residuals: ## Min 1Q Median 3Q Max ## -860.29 -251.00 -35.31 203.98 2110.38 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) ## (Intercept) -128.8899 92.1823 -1.398 0.162 ## educ 42.0576 6.5498 6.421 2.15e-10 *** ## IQ 5.1380 0.9558 5.375 9.66e-08 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Residual standard error: 376.7 on 932 degrees of freedom ## Multiple R-squared: 0.1339, Adjusted R-squared: 0.132 ## F-statistic: 72.02 on 2 and 932 DF, p-value: < 2.2e-16 ``` ] --- class: title title-8 # Regresión múltiple: ejemplo - `\(\beta_1\)`: por cada año adicional de educación, el salario promedio semanal aumenta 42 dólares, manteniendo la experiencia constante. - `\(\beta_2\)`: por cada punto adicional del IQ, el salario promedio semanal aumenta 5 dólares, manteniendo la educación constante. --- class: title title-8 # "Manteniendo constante..." - Nos permite asegurar que el efecto se debe a que **un factor** está cambiando mientras los otros no cambian. -- 1. Si una persona tiene un año más de educación que la otra recibirá semanalmente 42 dolares más, considerando que ambas tienen el mismo *nivel de inteligencia*. -- 2. Dos personas con igual cantidad de años en educación, si una tiene un IQ un punto más alto recibirá *5 dolares* más en el empleo. --- class: center middle main-title section-title-8 top-logo # Efecto parcial --- <center> <img src="data:image/png;base64,#https://raw.githubusercontent.com/statistics-R/slides/main/img/05/15.png" alt="drawing" style="width:1000px;"/> </center> --- class: title title-8 # Regresión simple vs múltiple `$$y = \beta_0 + \beta_1 educ + u$$` `$$y = \beta_0 + \beta_2 exper + u$$` `$$y = \beta_0 + \beta_1 educ+ \beta_2 exper + u$$` --- <table style="border-collapse:collapse; border:none;"> <tr> <th style="border-top: double; text-align:center; font-style:normal; font-weight:bold; padding:0.2cm; text-align:left; "> </th> <th colspan="1" style="border-top: double; text-align:center; font-style:normal; font-weight:bold; padding:0.2cm; ">Modelo 1</th> <th colspan="1" style="border-top: double; text-align:center; font-style:normal; font-weight:bold; padding:0.2cm; ">Modelo 2</th> <th colspan="1" style="border-top: double; text-align:center; font-style:normal; font-weight:bold; padding:0.2cm; ">Modelo 3</th> </tr> <tr> <td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; text-align:left; ">Predictors</td> <td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">salario</td> <td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">salario</td> <td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">salario</td> </tr> <tr> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">(Intercept)</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">146.95</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">116.99</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">-128.89</td> </tr> <tr> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">educ</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">60.21</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; "></td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">42.06</td> </tr> <tr> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">IQ</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; "></td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">8.30</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">5.14</td> </tr> <tr> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; padding-top:0.1cm; padding-bottom:0.1cm; border-top:1px solid;">Observations</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; padding-top:0.1cm; padding-bottom:0.1cm; text-align:left; border-top:1px solid;" colspan="1">935</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; padding-top:0.1cm; padding-bottom:0.1cm; text-align:left; border-top:1px solid;" colspan="1">935</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; padding-top:0.1cm; padding-bottom:0.1cm; text-align:left; border-top:1px solid;" colspan="1">935</td> </tr> <tr> <td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; padding-top:0.1cm; padding-bottom:0.1cm;">R<sup>2</sup> / R<sup>2</sup> adjusted</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; padding-top:0.1cm; padding-bottom:0.1cm; text-align:left;" colspan="1">0.107 / 0.106</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; padding-top:0.1cm; padding-bottom:0.1cm; text-align:left;" colspan="1">0.096 / 0.095</td> <td style=" padding:0.2cm; text-align:left; vertical-align:top; padding-top:0.1cm; padding-bottom:0.1cm; text-align:left;" colspan="1">0.134 / 0.132</td> </tr> </table> --- <center> <img src="data:image/png;base64,#https://raw.githubusercontent.com/statistics-R/slides/main/img/05/16.png" alt="drawing" style="width:1000px;"/> </center> --- <center> <img src="data:image/png;base64,#https://raw.githubusercontent.com/statistics-R/slides/main/img/05/17.png" alt="drawing" style="width:1000px;"/> </center> --- <center> <img src="data:image/png;base64,#https://raw.githubusercontent.com/statistics-R/slides/main/img/05/18.png" alt="drawing" style="width:1000px;"/> </center> --- class: title title-8 # Correlación entre variables <table style="border-collapse:collapse; border:none;"> <tr> <th style="font-style:italic; font-weight:normal; border-top:double black; border-bottom:1px solid black; padding:0.2cm;"> </th> <th style="font-style:italic; font-weight:normal; border-top:double black; border-bottom:1px solid black; padding:0.2cm;">wage</th> <th style="font-style:italic; font-weight:normal; border-top:double black; border-bottom:1px solid black; padding:0.2cm;">educ</th> <th style="font-style:italic; font-weight:normal; border-top:double black; border-bottom:1px solid black; padding:0.2cm;">IQ</th> </tr> <tr> <td style="font-style:italic;">wage</td> <td style="padding:0.2cm; text-align:center;"> </td> <td style="padding:0.2cm; text-align:center;"> </td> <td style="padding:0.2cm; text-align:center;"> </td> </tr> <tr> <td style="font-style:italic;">educ</td> <td style="padding:0.2cm; text-align:center;">0.327<span style="vertical-align:super;font-size:0.8em;">***</span></td> <td style="padding:0.2cm; text-align:center;"> </td> <td style="padding:0.2cm; text-align:center;"> </td> </tr> <tr> <td style="font-style:italic;">IQ</td> <td style="padding:0.2cm; text-align:center;">0.309<span style="vertical-align:super;font-size:0.8em;">***</span></td> <td style="padding:0.2cm; text-align:center;">0.516<span style="vertical-align:super;font-size:0.8em;">***</span></td> <td style="padding:0.2cm; text-align:center;"> </td> </tr> <tr> <td colspan="4" style="border-bottom:double black; border-top:1px solid black; font-style:italic; font-size:0.9em; text-align:right;">Computed correlation used pearson-method with listwise-deletion.</td> </tr> </table> -- - **¡Hay correlación entre educ y IQ!** --- class: title title-8 # MCO `\(\beta_s\)` en regresión múltiple ## `$$\hat \beta_1 = \frac{Cov(X_1,Y)}{Var(X_1)} - \frac{\hat{\beta_2}*Cov(X_1,X_2)}{Var(X_1)}$$` -- ## `$$\hat \beta_2 = \frac{Cov(X_2,Y)}{Var(X_2)} - \frac{\hat{\beta_1}*Cov(X_1,X_2)}{Var(X_2)}$$` --- class: center middle main-title section-title-8 top-logo ## Pero, ¿qué pasa si `\(Cov(x_1, x_2)\)` es muy grande? -- ## Tendremos un problema de multicolinealidad --- <center> <img src="data:image/png;base64,#https://raw.githubusercontent.com/statistics-R/slides/main/img/05/19.png" alt="drawing" style="width:1000px;"/> </center> --- <center> <img src="data:image/png;base64,#https://raw.githubusercontent.com/statistics-R/slides/main/img/05/20.png" alt="drawing" style="width:1000px;"/> </center> --- class: title title-8 # Supuesto 4 .box-8[**Multicolinealidad imperfecta**] .box-inv-8[No existe una relación **lineal exacta** entre las variables independientes] -- - Esto es común cuando incorporamos variables que *miden lo mismo* (en distintas unidades de medida) - Una consecuencia de la multicolinealidad será que los **estimadores** `\(\beta\)` **serán poco precisos** --- <center> <img src="data:image/png;base64,#https://raw.githubusercontent.com/statistics-R/slides/main/img/05/13.png" alt="drawing" style="width:1000px;"/> </center> --- <center> <img src="data:image/png;base64,#https://raw.githubusercontent.com/statistics-R/slides/main/img/05/14_2.png" alt="drawing" style="width:1000px;"/> </center> --- class: center middle main-title section-title-8 top-logo # ¿Y si mejor no incorporamos las otras variables? --- class: center middle main-title section-title-8 top-logo ## Si no incorporamos `\(x_2\)` en la regresión esta será capturada por el error `\(u\)` -- ## Y si `\(x_2\)` con `\(x_1\)` correlacionan... ¿qué supuesto y propiedad ya no se cumplirÃan? (Tarea) --- layout: false class: center middle main-title section-title-8 top-logo .small[ # Regresión **lineal** múltiple ] .class-info[ <br> **Sesión N° 6**<br> **EstadÃsitica II** <br> .pull-right.small[ **Profesora** Valentina Andrade de la Horra <br> **Apoyo docente** Nicolás Godoy <br> **Ayudantes** Moira Martinez, Charo Astorga y Alberto Reyes .tiny[Universidad Alberto Hurtado<br> ] ] ]