Numeral 1
options(scipen = 999999999)
load("C:/Users/Molin/Downloads/modelo_estimado.RData")
#Construyendo matriz x
Matriz_X<-model.matrix(modelo_estimado_1)
Matriz_XX<-t(Matriz_X)%*%(Matriz_X)
#Construyendo matriz A
Matriz_A<-solve(Matriz_XX)%*%t(Matriz_X)
#Constuyendo matriz P
Matriz_P<-(Matriz_X)%*%(Matriz_A)
#Constuyendo matriz M
n<-nrow(Matriz_X)
Matriz_M<-diag(n)-Matriz_P
Numeral 2
library(magrittr)
## Warning: package 'magrittr' was built under R version 4.2.3
Residuos_modelo_estimado<-modelo_estimado_1$residuals
Datos_Modelo<-modelo_estimado_1$model
Residuos_matrices<-Matriz_M%*%Datos_Modelo$crime
cbind(Residuos_matrices, Residuos_modelo_estimado, Residuos_modelo_estimado-Residuos_matrices)%>% round(digits=2) %>%as.data.frame()->comparacion
names(comparacion)<-c("Por matrices", "En el modelo", "Diferencia")
comparacion
## Por matrices En el modelo Diferencia
## 1 -311.71 -311.71 0
## 2 116.80 116.80 0
## 3 45.25 45.25 0
## 4 -34.45 -34.45 0
## 5 243.00 243.00 0
## 6 -145.12 -145.12 0
## 7 86.13 86.13 0
## 8 88.31 88.31 0
## 9 689.82 689.82 0
## 10 -163.29 -163.29 0
## 11 60.90 60.90 0
## 12 126.92 126.92 0
## 13 -19.27 -19.27 0
## 14 322.59 322.59 0
## 15 -22.44 -22.44 0
## 16 128.18 128.18 0
## 17 -70.82 -70.82 0
## 18 -227.95 -227.95 0
## 19 287.10 287.10 0
## 20 303.88 303.88 0
## 21 -341.99 -341.99 0
## 22 -107.18 -107.18 0
## 23 -30.63 -30.63 0
## 24 189.45 189.45 0
## 25 -811.14 -811.14 0
## 26 -351.77 -351.77 0
## 27 102.71 102.71 0
## 28 -23.36 -23.36 0
## 29 73.38 73.38 0
## 30 -91.63 -91.63 0
## 31 324.03 324.03 0
## 32 -115.85 -115.85 0
## 33 113.65 113.65 0
## 34 217.94 217.94 0
## 35 -112.70 -112.70 0
## 36 21.38 21.38 0
## 37 -88.91 -88.91 0
## 38 99.42 99.42 0
## 39 -102.65 -102.65 0
## 40 217.88 217.88 0
## 41 -84.09 -84.09 0
## 42 137.78 137.78 0
## 43 48.89 48.89 0
## 44 -67.16 -67.16 0
## 45 -39.29 -39.29 0
## 46 -415.78 -415.78 0
## 47 -145.50 -145.50 0
## 48 -183.61 -183.61 0
## 49 -138.39 -138.39 0
## 50 -232.91 -232.91 0
## 51 434.17 434.17 0
Numeral 3
eigen(x=Matriz_XX)->descomposicion
Auto_valores<-descomposicion$values
print(Auto_valores)
## [1] 17956.580914 279.157317 1.681762
print(Auto_valores>0)
## [1] TRUE TRUE TRUE