Creacion de Matrices

#Creacion 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")
rownames(matriz_y)<-c("a","b","c","d","e")
print(matriz_y)
##    y
## a 30
## b 20
## c 36
## d 24
## e 40

Creación de 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

Operaciones con Matrices

calcular 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

usando una función personalizada

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