load("C:/Users/Jacqueline Vanessa/Desktop/UES/Ciclo I - 2022/EMA118/DOCUMENTOS/Parcial 1/Practica 1/datos_parcial_1.RData")

a) Estimar el modelo para los ingresos

modelo_ingresos<-lm(formula=income~sex+status+verbal+gamble,data = teengamb)
summary(modelo_ingresos)
## 
## Call:
## lm(formula = income ~ sex + status + verbal + gamble, data = teengamb)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.9561 -1.9072 -0.6399  1.1958  7.1716 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  4.41097    2.00311   2.202   0.0332 *  
## sex          0.09035    1.07210   0.084   0.9332    
## status      -0.06279    0.03250  -1.932   0.0601 .  
## verbal       0.24660    0.26492   0.931   0.3572    
## gamble       0.07214    0.01491   4.839 1.79e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.736 on 42 degrees of freedom
## Multiple R-squared:  0.4581, Adjusted R-squared:  0.4065 
## F-statistic: 8.877 on 4 and 42 DF,  p-value: 2.743e-05

b) Calcular intervalo de confianza del 92.5% en las variables “verbal” y “gamble”

confint(object=modelo_ingresos,parm = "verbal",level = 0.925)
##            3.75 %  96.25 %
## verbal -0.2370767 0.730284
confint(object=modelo_ingresos,parm = "gamble",level = 0.925)
##            3.75 %    96.25 %
## gamble 0.04492279 0.09936007

Las variables no tienen relación en cuanto sus ingresos.

c) ¿El modelo resulta ser estadisticamente significativo?

d) Matriz A, P, M

model.matrix(modelo_ingresos)->matriz_X
matriz_XX<-t(matriz_X)%*%matriz_X

# Cálculo de la matriz A
matriz_A<-solve(matriz_XX)%*%t(matriz_X)
print(matriz_A[1:5,1:5])
##                         1             2             3             4
## (Intercept) -0.1074542196 -2.196091e-02  0.0166636550  0.1071925261
## sex          0.0809403937  2.485496e-02  0.0546438428  0.0478553863
## status       0.0012534153 -1.991280e-03  0.0004440685  0.0004276380
## verbal       0.0053215827  1.872697e-02 -0.0052703695 -0.0181905266
## gamble       0.0002006996 -7.513551e-05 -0.0001277504 -0.0001794904
##                         5
## (Intercept) -0.1997769992
## sex          0.1347212618
## status       0.0034635069
## verbal      -0.0012648221
## gamble       0.0009505469
# Cálculo de la matriz P
matriz_P<-matriz_X%*%matriz_A
print(matriz_P[1:5,1:5])
##            1          2          3          4          5
## 1 0.07998301 0.05115446 0.05179203 0.03133324 0.10146454
## 2 0.05115446 0.09695391 0.04157846 0.02149756 0.02180388
## 3 0.05179203 0.04157846 0.05611581 0.06172736 0.05550509
## 4 0.03133324 0.02149756 0.06172736 0.09294939 0.03380216
## 5 0.10146454 0.02180388 0.05550509 0.03380216 0.16858435
# Cálculo de la matriz M
n<-nrow(matriz_X)
matriz_M<-diag(n)-matriz_P
print(matriz_M[1:5,1:5])
##             1           2           3           4           5
## 1  0.92001699 -0.05115446 -0.05179203 -0.03133324 -0.10146454
## 2 -0.05115446  0.90304609 -0.04157846 -0.02149756 -0.02180388
## 3 -0.05179203 -0.04157846  0.94388419 -0.06172736 -0.05550509
## 4 -0.03133324 -0.02149756 -0.06172736  0.90705061 -0.03380216
## 5 -0.10146454 -0.02180388 -0.05550509 -0.03380216  0.83141565