Eigen Vectors Deep Practice
Purpose
> file <- "C:/Cauldron/garage/R/soulcraft/Volatility/Learn/Wolfgang_Multivariate/Data/bank2.dat" > x <- as.data.frame(read.table(file)) > colnames(x) <- c("length", "hl", "hr", "lframe", "uframe", "diag") > types <- c(rep("o", 100), rep("X", 100)) |
Standardize the variables
> y <- as.matrix(x) > n <- dim(y)[1] > p <- dim(y)[2] > H <- diag(n) - 1/n * rep(1, n) %*% t(rep(1, n)) > D.sqrt <- diag(p) > diag(D.sqrt) <- 1/sqrt(diag(cov(y))) > y.c <- (1/sqrt(n)) * H %*% y %*% D.sqrt > uk <- eigen(cov(y.c))$vectors > lambdas <- eigen(cov(y.c))$values > uk [,1] [,2] [,3] [,4] [,5] [,6] [1,] -0.006987029 0.81549497 -0.01768066 0.5746173 -0.0587961 -0.03105698 [2,] 0.467758161 0.34196711 0.10338286 -0.3949225 0.6394961 0.29774768 [3,] 0.486678705 0.25245860 0.12347472 -0.4302783 -0.6140972 -0.34915294 [4,] 0.406758327 -0.26622878 0.58353831 0.4036735 -0.2154756 0.46235361 [5,] 0.367891118 -0.09148667 -0.78757147 0.1102267 -0.2198494 0.41896754 [6,] -0.493458317 0.27394074 0.11387536 -0.3919305 -0.3401601 0.63179849 > svd(y.c)$v [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0.006987029 -0.81549497 0.01768066 0.5746173 -0.0587961 0.03105698 [2,] -0.467758161 -0.34196711 -0.10338286 -0.3949225 0.6394961 -0.29774768 [3,] -0.486678705 -0.25245860 -0.12347472 -0.4302783 -0.6140972 0.34915294 [4,] -0.406758327 0.26622878 -0.58353831 0.4036735 -0.2154756 -0.46235361 [5,] -0.367891118 0.09148667 0.78757147 0.1102267 -0.2198494 -0.41896754 [6,] 0.493458317 -0.27394074 -0.11387536 -0.3919305 -0.3401601 -0.63179849 |
> round(cumsum(lambdas/sum(lambdas)) * 100, 0) [1] 49 70 85 92 97 100 |
> library(scatterplot3d) > par(mfrow = c(2, 2)) > y.c.transf <- y.c %*% uk > plot(y.c.transf[, 1], y.c.transf[, 2], type = "n", main = "F1 - F2 ") > text(y.c.transf[, 1], y.c.transf[, 2], types, cex = 0.9, ) > plot(y.c.transf[, 1], y.c.transf[, 3], type = "n", main = "F1 - F3 ") > text(y.c.transf[, 1], y.c.transf[, 3], types, cex = 0.9, ) > plot(y.c.transf[, 2], y.c.transf[, 3], type = "n", main = "F2 - F3 ") > text(y.c.transf[, 2], y.c.transf[, 3], types, cex = 0.9, ) > scatterplot3d(y.c.transf[, 1], y.c.transf[, 2], y.c.transf[, + 3], angle = 120) |