]
---
# Modelos y ecuaciones
```r
reg1 <- lm(ciencia ~ matematicas + lectura, data=data)
reg2 <- lm(ciencia ~ matematicas + lectura + mujer + status, data=data)
```
```r
# librería equatiomatic R
extract_eq(reg1)
extract_eq(reg2)
```
`$$\operatorname{ciencia} = \alpha + \beta_{1}(\operatorname{matematicas}) + \beta_{2}(\operatorname{lectura}) + \epsilon$$`
`$$\operatorname{ciencia} = \alpha + \beta_{1}(\operatorname{matematicas}) + \beta_{2}(\operatorname{lectura}) + \beta_{3}(\operatorname{mujer}) + \beta_{4}(\operatorname{status}) + \epsilon$$`
---
.pull-left-narrow[
# Tabla de regresión
## con sjPlot
]
.pull-right-wide[
.smally[
<table style="border-collapse:collapse; border:none;">
<caption style="font-weight: bold; text-align:left;">Modelos de regresión para puntaje en ciencia <br> (Errores estándar entre paréntesis)</caption>
<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>
</tr>
<tr>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; text-align:left; ">Predictores</td>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">β</td>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">β</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; ">11.616 <sup>***</sup><br>(3.054)</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">12.325 <sup>***</sup><br>(3.194)</td>
</tr>
<tr>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">matematicas</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.402 <sup>***</sup><br>(0.073)</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.389 <sup>***</sup><br>(0.074)</td>
</tr>
<tr>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">lectura</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.365 <sup>***</sup><br>(0.066)</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.335 <sup>***</sup><br>(0.073)</td>
</tr>
<tr>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">mujer</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; ">-2.010 <sup></sup><br>(1.023)</td>
</tr>
<tr>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">status</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; ">0.050 <sup></sup><br>(0.062)</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">200</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">200</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.478 / 0.473</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.489 / 0.479</td>
</tr>
<tr>
<td colspan="3" style="font-style:italic; border-top:double black; text-align:right;">* p<0.05 ** p<0.01 *** p<0.001</td>
</tr>
</table>
]]
---
![:scale 90%](tabreg.png)
---
## Otras alternativas
.smally[
<br>
<table style="border-collapse:collapse; border:none;">
<caption style="font-weight: bold; text-align:left;">Modelos de regresión para puntaje en ciencia <br> (Errores estándar entre paréntesis)</caption>
<tr>
<th style="border-top: double; text-align:center; font-style:normal; font-weight:bold; padding:0.2cm; text-align:left; "> </th>
<th colspan="2" style="border-top: double; text-align:center; font-style:normal; font-weight:bold; padding:0.2cm; ">Modelo 1</th>
<th colspan="2" style="border-top: double; text-align:center; font-style:normal; font-weight:bold; padding:0.2cm; ">Modelo 2</th>
</tr>
<tr>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; text-align:left; ">Predictores</td>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">β</td>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">std. Error</td>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">β</td>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">std. Error</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; ">11.616 <sup>***</sup></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">3.054</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">12.325 <sup>***</sup></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">3.194</td>
</tr>
<tr>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">matematicas</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.402 <sup>***</sup></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.073</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.389 <sup>***</sup></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.074</td>
</tr>
<tr>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">lectura</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.365 <sup>***</sup></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.066</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.335 <sup>***</sup></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.073</td>
</tr>
<tr>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">mujer</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; "></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">-2.010 <sup></sup></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">1.023</td>
</tr>
<tr>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">status</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; "></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.050 <sup></sup></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.062</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="2">200</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="2">200</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="2">0.478 / 0.473</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; padding-top:0.1cm; padding-bottom:0.1cm; text-align:left;" colspan="2">0.489 / 0.479</td>
</tr>
<tr>
<td colspan="5" style="font-style:italic; border-top:double black; text-align:right;">* p<0.05 ** p<0.01 *** p<0.001</td>
</tr>
</table>
]
---
## Otras alternativas
.smally[
<br>
<table style="border-collapse:collapse; border:none;">
<caption style="font-weight: bold; text-align:left;">Modelos de regresión para puntaje en ciencia <br> (Errores estándar entre paréntesis)</caption>
<tr>
<th style="border-top: double; text-align:center; font-style:normal; font-weight:bold; padding:0.2cm; text-align:left; "> </th>
<th colspan="3" style="border-top: double; text-align:center; font-style:normal; font-weight:bold; padding:0.2cm; ">Modelo 1</th>
<th colspan="3" style="border-top: double; text-align:center; font-style:normal; font-weight:bold; padding:0.2cm; ">Modelo 2</th>
</tr>
<tr>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; text-align:left; ">Predictores</td>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">β</td>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">CI</td>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">p</td>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">β</td>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; ">CI</td>
<td style=" text-align:center; border-bottom:1px solid; font-style:italic; font-weight:normal; col7">p</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; ">11.62</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">5.59 – 17.64</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; "><strong><0.001</strong></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">12.33</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">6.03 – 18.62</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; col7"><strong><0.001</strong></td>
</tr>
<tr>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">matematicas</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.40</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.26 – 0.54</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; "><strong><0.001</strong></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.39</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.24 – 0.54</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; col7"><strong><0.001</strong></td>
</tr>
<tr>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">lectura</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.37</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.23 – 0.50</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; "><strong><0.001</strong></td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.34</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">0.19 – 0.48</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; col7"><strong><0.001</strong></td>
</tr>
<tr>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">mujer</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; "></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; ">-2.01</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">-4.03 – 0.01</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; col7">0.051</td>
</tr>
<tr>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:left; ">status</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; "></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; ">0.05</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; ">-0.07 – 0.17</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; text-align:center; col7">0.424</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="3">200</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="3">200</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="3">0.478 / 0.473</td>
<td style=" padding:0.2cm; text-align:left; vertical-align:top; padding-top:0.1cm; padding-bottom:0.1cm; text-align:left;" colspan="3">0.489 / 0.479</td>
</tr>
</table>
]
---
## Información para contraste de hipótesis en tabla de regresión
- error estándar
- t
- intervalo de confianza
- p / asteriscos
---
## Beta estandarizado o no estandarizado
- Betas:
- pueden aparecer en puntaje bruto (no estandarizado) o estandarizado
- beta estandarizado: se interpreta como cuantas unidades de desviación estándar aumenta Y por cada aumento de una desviación estándar de X
- betas estandarizados permiten comparar el efecto de cada variable independiente en una misma escala (desviaciones estándar)
---
.pull-left-narrow[
# Resumen:
# Tabla de regresión múltiple
]
.pull-right-wide[
.content-box-red[
Modelos se presentan en columnas]
.content-box-purple[
Información principal: beta y significación estadística para cada variable independiente]
.content-box-yellow[
Información secundaria: número de observaciones y varianza explicada]
]
---
.pull-left-narrow[
#Tabla de regresión múltiple:
## Sentido de presentación de modelos
]
.pull-right-wide[
.content-box-gray[
Se comienza ingresando variables de hipótesis principales]
.content-box-purple[
Modelos adicionales ingresan variables de hipótesis secundarias o variables de control]
.content-box-yellow[
La interpretación de la tabla se realiza en general para cada variable independiente a través de los modelos]
]
---
## Intervalos de confianza em regresión
Los **Intervalos de Confianza** proporcionan un rango de valores posibles para el parámetro poblacional y no sólo una estimación puntual.
- Para los coeficientes de regresión,
`$$IC=\beta_{j}\pm c*SE(\hat{\beta{j}})$$`
donde `\(c\)` representa el valor crítico de t
---
## Intervalos de confianza
`$$IC=\beta_{j}\pm c*SE(\hat{\beta{j}})$$`
.medium[
Calculamos el intervalo de confianza del `\(\beta\)` del ejemplo anterior (10, SE=4)
- al 95% de confianza:
`$$LimiteSuperior= 10 + 1.96*4=17.84$$`
`$$LimiteInferior= 10 - 1.96*4=2.16$$`
Como se puede observar en ninguno de los límites el `\(\beta\)` "atraviesa" el cero, por lo que se puede rechazar con el 95% de confianza que `\(\beta = 0\)`]
---
## Gráfico de intervalos de Confianza
```r
plot_summs(reg1)
```
![](7_inferencia_files/figure-html/unnamed-chunk-13-1.png)<!-- -->
---
class: roja middle center
# LECTURA
## [Moore 7: Inferencia para medias (482-543)](/docs/lecturas/Moore_inferencia_medias.pdf)
---
class: inverse
## Resumen
- La **inferencia** en estadística se refiere a la relación que existe entre los resultados obtenidos basados en nuestra muestra y la población.
- La inferencia en regresión se asocia a establecer un nivel de probabilidad de error asociado a la estimación de `\(\beta\)`
- ¿Qué probabilidad de error estamos asumiendo al decir que nuestro `\(\beta\)` existe en la población (= que es estadísticamente distinto de 0)?
---
class: inverse
## Resumen (II)
- La **prueba T** nos permite establecer de manera exacta el nivel de error que estamos asumiendo para rechazar `\(H_0\)`
- Conceptos clave:
- hipótesis nula
- hipótesis alternativa
- nivel de error
- nivel de significancia
- intervalo de confianza
- valor p
---
class: front
.pull-left[
# Estadística Multivariada
## Juan Carlos Castillo
## Sociología FACSO - UChile
## 1er Sem 2022
## [multivariada.netlify.com](https://multivariada.netlify.com)
]
.pull-right[
.right[
<br>
![:scale 80%](https://multivariada.netlify.com/img/hex_multiva.png)
]
]