Matriz Y
#Generación de la matriz Y
matriz_Y<-matrix(data = c(30,20,36,24,40),
nrow = 5,
ncol = 1,
byrow = TRUE)
colnames(matriz_Y)<-c("Y")
print(matriz_Y)
## Y
## [1,] 30
## [2,] 20
## [3,] 36
## [4,] 24
## [5,] 40
Matriz X
matriz_X<-cbind(rep(1,6),matrix(data = c(4,10,3,8,6,11,4,9,8,12),nrow = 5,ncol = 2,byrow = TRUE))
colnames(matriz_X)<-c("Cte","X1","X2")
print(matriz_X)
## Cte X1 X2
## [1,] 1 4 10
## [2,] 1 3 8
## [3,] 1 6 11
## [4,] 1 4 9
## [5,] 1 8 12
Producto de Matrices Cálculo de X’X (Sigma matriz)
matriz_XX<-t(matriz_X)%*%matriz_X
print(matriz_XX)
## Cte X1 X2
## Cte 5 25 50
## X1 25 141 262
## X2 50 262 510
Función para facilitar (Sigma matriz)
Sigma_matriz<-function(matriz){t(matriz)%*%matriz}
matriz_XX2<-Sigma_matriz(matriz_X)
print(matriz_XX2)
## Cte X1 X2
## Cte 5 25 50
## X1 25 141 262
## X2 50 262 510