###Soluciòn Ejercicio 1

####1.Generando la matriz**x’x

options(scipen = 99999999)
matriz_xx<-matrix(data = c(25,4586,2018,4585,1030398,364545,2018,364545,204312),nrow = 3,ncol = 3,byrow = TRUE)
print(matriz_xx)
##      [,1]    [,2]   [,3]
## [1,]   25    4586   2018
## [2,] 4585 1030398 364545
## [3,] 2018  364545 204312

####2.Generando la matriz x’y

matriz_xy<-matrix(data = c(55331,12524626,4374490),nrow = 3,ncol = 1,byrow = TRUE)
print(matriz_xy)
##          [,1]
## [1,]    55331
## [2,] 12524626
## [3,]  4374490

####3..Calculando la inversa de x’x, decir (x’x)-1 A traves de Gauss-Jordan, u otro método (usando 10 decimales para el redondeo) se obtiene:

inv_matriz_xx<- solve(matriz_xx)
print(inv_matriz_xx)
##              [,1]          [,2]          [,3]
## [1,]  0.397572312 -1.031056e-03 -2.087174e-03
## [2,] -0.001030009  5.303087e-06  7.113880e-07
## [3,] -0.002089041  7.217230e-07  2.424030e-05

####4.Calculo del estimador de parametros Beta

Puede Hacerse a través del producto de “inv_matriz_xx” con “matriz_xy”, usando el operador de productode matrices%*%

beta<-inv_matriz_xx%*%matriz_xy
print(beta)
##             [,1]
## [1,] -45.8357695
## [2,]  12.5396900
## [3,]  -0.5104679

###Solución del ejercicio 2

####1.Generando la matriz **x’x

options(scipen = 99999999)
matriz_xx<-matrix(data = c(26,5857,131,5857,1675143,28173,131,28173,869),nrow = 3,ncol = 3,byrow = TRUE)
print(matriz_xx)
##      [,1]    [,2]  [,3]
## [1,]   26    5857   131
## [2,] 5857 1675143 28173
## [3,]  131   28173   869

####2.Generando la matriz x’y

matriz_xy<-matrix(data = c(1181,298629,6086),nrow = 3,ncol = 1,byrow = TRUE)
print(matriz_xy)
##        [,1]
## [1,]   1181
## [2,] 298629
## [3,]   6086

####3.Calculo de la inversa de x’x, es decir (x’x)-1

inv_matriz_xx<-solve(matriz_xx)
print(inv_matriz_xx)
##               [,1]            [,2]           [,3]
## [1,]  0.3509517581 -0.000741721931 -0.02885862872
## [2,] -0.0007417219  0.000002880324  0.00001843291
## [3,] -0.0288586287  0.000018432909  0.00490353282

####4.Calculando el estimador de parametros Beta

Puede Hacerse a través del producto de “inv_matriz_xx” con “matriz_xy”, usando el operador de productode matrices%*%

beta<-inv_matriz_xx%*%matriz_xy
print(beta)
##             [,1]
## [1,] 17.34073347
## [2,]  0.09635743
## [3,]  1.26546137