options(scipen = 9999999999)
matriz_xx<-matrix(data = c(25,4586, 2018,
4586, 1030398, 364545,
2018, 364545, 204312), nrow = 3, ncol = 3, byrow = TRUE)
print(matriz_xx)
## [,1] [,2] [,3]
## [1,] 25 4586 2018
## [2,] 4586 1030398 364545
## [3,] 2018 364545 204312
matriz_xy<-matrix(data = c(55331,
12524626,
4374490), nrow = 3, ncol = 1, byrow = TRUE)
print(matriz_xy)
## [,1]
## [1,] 55331
## [2,] 12524626
## [3,] 4374490
inv_matriz_xx<-solve(matriz_xx)
print(inv_matriz_xx)
## [,1] [,2] [,3]
## [1,] 0.397982654 -1.032120e-03 -2.089328e-03
## [2,] -0.001032120 5.308560e-06 7.224679e-07
## [3,] -0.002089328 7.224679e-07 2.424181e-05
beta<-inv_matriz_xx%*%matriz_xy
print(beta)
## [,1]
## [1,] -45.8830775
## [2,] 12.5399333
## [3,] -0.5104348
options(scipen = 9999999999)
matriz_xx_2<-matrix(data = c(26,5857, 131,
5857, 1675143, 28173,
131, 28173, 869), nrow = 3, ncol = 3, byrow = TRUE)
print(matriz_xx_2)
## [,1] [,2] [,3]
## [1,] 26 5857 131
## [2,] 5857 1675143 28173
## [3,] 131 28173 869
2.Generando matriz X’Y
matriz_xy_2<-matrix(data = c(1181,
298629,
6068), nrow = 3, ncol = 1, byrow = TRUE)
print(matriz_xy_2)
## [,1]
## [1,] 1181
## [2,] 298629
## [3,] 6068
inv_matriz_xx_2<-solve(matriz_xx_2)
print(inv_matriz_xx_2)
## [,1] [,2] [,3]
## [1,] 0.3509517581 -7.417219e-04 -2.885863e-02
## [2,] -0.0007417219 2.880324e-06 1.843291e-05
## [3,] -0.0288586287 1.843291e-05 4.903533e-03
beta_2<-inv_matriz_xx_2%*%matriz_xy_2
print(beta_2)
## [,1]
## [1,] 17.86018879
## [2,] 0.09602564
## [3,] 1.17719778