#1.

load("C:/Users/moises/Desktop/Guia 1 Archivos/datos_cajas.RData")
modelo_caja<-lm(formula = Tiempo ~ Distancia+N_cajas, data =datos_cajas)

#2

matriz_x<-model.matrix(modelo_caja)
sigma_matriz<-t(matriz_x)%*%matriz_x
matriz_a<-solve(sigma_matriz)%*%t(matriz_x)
matriz_p<-matriz_x%*%matriz_a
n<-nrow(matriz_x)
matriz_m<-diag(n)-matriz_p

#3

library(magrittr)
modelo_rsd<-modelo_caja$residuals
matriz_y<-datos_cajas$Tiempo
producto_rsd<-matriz_m%*%matriz_y
cbind(modelo_rsd,producto_rsd, modelo_rsd-producto_rsd) %>% as.data.frame() %>% round(digits = 2)->comparacion

names(comparacion)<-c("modelo_rsd","producto_rsd","diferencia")
print(comparacion)
##    modelo_rsd producto_rsd diferencia
## 1       -0.76        -0.76          0
## 2        0.13         0.13          0
## 3       -0.32        -0.32          0
## 4        2.94         2.94          0
## 5       -9.27        -9.27          0
## 6        0.77         0.77          0
## 7        1.31         1.31          0
## 8       -2.09        -2.09          0
## 9        1.43         1.43          0
## 10       0.52         0.52          0
## 11       0.52         0.52          0
## 12       1.38         1.38          0
## 13      -1.02        -1.02          0
## 14       2.89         2.89          0
## 15       1.59         1.59          0

#4

desmenusado<-eigen(x = sigma_matriz)
auto_valor<-desmenusado$values
print(auto_valor)
## [1] 1.697678e+04 7.099346e+02 2.872743e-01