CREACION DE MATRICES Y & X

Creando 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

Creando la 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("cts","x1","x2")
print(matriz_x)
##      cts x1 x2
## [1,]   1  4 10
## [2,]   1  3  8
## [3,]   1  6 11
## [4,]   1  4  9
## [5,]   1  8 12

CREACION DE LA MATRIZ X`X

Creando la matriz x`x (sigma matriz)

matriz_xx<-t(matriz_x)%*%(matriz_x)
print(matriz_xx)
##     cts  x1  x2
## cts   5  25  50
## x1   25 141 262
## x2   50 262 510

Usando una funcion personalizada para crear X`X

# 1. Creamos la funcion
sigma_matriz<-function(matriz){t(matriz)%*%(matriz)}

# 2, Usamos la funcion para crear X`X
matriz_xx_2<-sigma_matriz(matriz_x)
print(matriz_xx_2)
##     cts  x1  x2
## cts   5  25  50
## x1   25 141 262
## x2   50 262 510