Creación de matrices

Matriz y

#Generacion de la matriz Y
matriz_y<-matrix(data = c(20, 30, 40, 36, 24, 40), nrow = 5, ncol = 1, byrow = TRUE)
print(matriz_y)
##      [,1]
## [1,]   20
## [2,]   30
## [3,]   40
## [4,]   36
## [5,]   24

Matriz X

Matriz_x<-cbind(rep(1,5), 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 Calculo 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

print(matriz_xx)
Cte  x1  x2

Cte 5 25 50 x1 25 141 262 x2 50 262 510

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