Matriz Y
#Generacion de la matriz Y
Y <- matrix(c( 30, 20, 36, 24, 40),
nrow = 5,
ncol = 1,
byrow = TRUE)
colnames(Y)<- c("Y")
print(Y)
## Y
## [1,] 30
## [2,] 20
## [3,] 36
## [4,] 24
## [5,] 40
Matriz X
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(X) <- c("Cte", "x1", "x2")
print(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)
#Creando sigma matriz o, X'X (X trans * X)
matriz_Sigma <- t(X)%*%X
print(matriz_Sigma)
## Cte x1 x2
## Cte 5 25 50
## x1 25 141 262
## x2 50 262 510
La siguiente operacion obtiene la matrix X’Y
XY <- t(X)%*%Y
print(XY)
## Y
## Cte 150
## x1 812
## x2 1552
Calculando la inversa de matrices
XX_inv <- solve(matriz_Sigma)
print(XX_inv)
## Cte x1 x2
## Cte 40.825 4.375 -6.25
## x1 4.375 0.625 -0.75
## x2 -6.250 -0.750 1.00
Obtencion del estimador MCO
Beta <- XX_inv%*%XY
colnames(Beta) <- c("Parametros")
print(Beta)
## Parametros
## Cte -23.75
## x1 -0.25
## x2 5.50
Obtencion de autovalores y autovectores Se usara el comando eigen()
autovalores <- eigen(matriz_Sigma)
print(autovalores)
## eigen() decomposition
## $values
## [1] 650.78185037 5.19448432 0.02366531
##
## $vectors
## [,1] [,2] [,3]
## [1,] -0.08623239 0.1629390 0.9828606
## [2,] -0.45874789 -0.8822205 0.1060061
## [3,] -0.88437229 0.4417441 -0.1508239
Muestra solo autovalores
print(autovalores$values)
## [1] 650.78185037 5.19448432 0.02366531