setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE)
Y <- matrix(c(30,20,36,24,40), ncol = 1, byrow = TRUE )
colnames(Y) <- c("Y")
print(Y)
## Y
## [1,] 30
## [2,] 20
## [3,] 36
## [4,] 24
## [5,] 40
X <- cbind(rep(1, 5), matrix(
data = c(4, 10, 3, 8, 6, 11, 4, 9, 8, 12),
nrow = 5,
ncol = 2,
byrow = FALSE
))
colnames(X) <- c("cte", "X1", "X2")
print(X)
## cte X1 X2
## [1,] 1 4 11
## [2,] 1 10 4
## [3,] 1 3 9
## [4,] 1 8 8
## [5,] 1 6 12
XX <- t(X)%*%X
print(XX)
## cte X1 X2
## cte 5 31 44
## X1 31 225 247
## X2 44 247 426
Creacion de la matriz XY
# Creacion de la Matriz XY
XY <- t(X)%*%Y
print(XY)
## Y
## cte 150
## X1 860
## X2 1406
beta <- solve(XX,XY)
print(beta)
## Y
## cte 20.3663921
## X1 -0.8191104
## X2 1.6718287
A <- solve(XX)%*%t(X)
P <- X%*%solve(XX)%*%t(X)
M <- diag(5)-P
Demostracion numerica de matriz P es idempotente
round(P%*%P-P,2)
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0 0 0 0
## [2,] 0 0 0 0 0
## [3,] 0 0 0 0 0
## [4,] 0 0 0 0 0
## [5,] 0 0 0 0 0
Demostracion numerica de matriz P es simetrica
round(t(P)-P, 2)
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0 0 0 0
## [2,] 0 0 0 0 0
## [3,] 0 0 0 0 0
## [4,] 0 0 0 0 0
## [5,] 0 0 0 0 0
Demostracion numerica de P ortogonal
round(M%*%P,2)
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0 0 0 0 0
## [2,] 0 0 0 0 0
## [3,] 0 0 0 0 0
## [4,] 0 0 0 0 0
## [5,] 0 0 0 0 0
Demostracion numerica de proyección de X sobre X
round(P%*%X-X, 2)
## cte X1 X2
## [1,] 0 0 0
## [2,] 0 0 0
## [3,] 0 0 0
## [4,] 0 0 0
## [5,] 0 0 0
```