*** PCA Analysis *** May 14, 2008 Monthly log returns of IBM, Hewlett-Packard, Intel, Merrill Lynch, and Morgan Stanley Dean Witter from 1990 to 2003. > setwd("C:/teaching/ama") > da=read.table("m-pca5c-9003.txt") > dim(da) [1] 168 6 > da[1,] V1 V2 V3 V4 V5 V6 1 4.67 -5.716 13.534 -14.31 -8.053 19900132 > rtn=da[,1:5] > pca.cov=princomp(rtn) > names(pca.cov) [1] "sdev" "loadings" "center" "scale" "n.obs" "scores" "call" > summary(pca.cov) Importance of components: Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Standard deviation 19.1512557 10.8345557 8.0099130 7.56366645 4.62750533 Proportion of Variance 0.5850173 0.1872390 0.1023363 0.09125127 0.03415608 Cumulative Proportion 0.5850173 0.7722563 0.8745926 0.96584392 1.00000000 > pca.cov$sdev Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 19.151256 10.834556 8.009913 7.563666 4.627505 > pca.cov$center V1 V2 V3 V4 V5 0.9710476 1.0353095 2.0366369 1.8732917 1.6031131 > loadings(pca.cov) Loadings: Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 V1 -0.300 -0.165 -0.221 0.907 -0.103 V2 -0.487 -0.183 -0.765 -0.376 V3 -0.543 -0.602 0.565 -0.151 V4 -0.418 0.526 0.146 -0.720 V5 -0.450 0.547 0.158 0.685 Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 SS loadings 1.0 1.0 1.0 1.0 1.0 Proportion Var 0.2 0.2 0.2 0.2 0.2 Cumulative Var 0.2 0.4 0.6 0.8 1.0 > screeplot(pca.cov) *** Use correlation matrix > pca.cor=princomp(rtn,cor=T) > summary(pca.cor) Importance of components: Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Standard deviation 1.6963832 0.9602490 0.7620928 0.65809751 0.43165765 Proportion of Variance 0.5755432 0.1844156 0.1161571 0.08661847 0.03726567 Cumulative Proportion 0.5755432 0.7599588 0.8761159 0.96273433 1.00000000 > loadings(pca.cor) Loadings: Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 V1 -0.388 -0.471 0.787 V2 -0.457 -0.253 -0.413 -0.745 V3 -0.425 -0.443 -0.439 0.656 V4 -0.474 0.530 -0.699 V5 -0.484 0.487 0.131 0.709 Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 SS loadings 1.0 1.0 1.0 1.0 1.0 Proportion Var 0.2 0.2 0.2 0.2 0.2 Cumulative Var 0.2 0.4 0.6 0.8 1.0 *** Independent component analysis > library(fastICA) > help(fastICA) > m1=fastICA(rtn,5) > names(m1) [1] "X" "K" "W" "A" "S" > dim(m1$S) [1] 168 5 > dim(m1$W) [1] 5 5 > m1$W [,1] [,2] [,3] [,4] [,5] [1,] 0.03020418 -0.1572847 -0.1676556507 0.35791819 -0.90450836 [2,] -0.33998054 -0.2698250 -0.8735226075 0.04573872 0.21557815 [3,] 0.49388755 -0.2058824 -0.0007325449 0.76628846 0.35565290 [4,] -0.75819322 0.2775278 0.2579654927 0.52365101 0.08581828 [5,] 0.25439942 0.8848993 -0.3772308377 0.09161960 -0.03920365 > dim(m1$K) [1] 5 5 > m1$K [,1] [,2] [,3] [,4] [,5] [1,] -0.01568876 0.01525672 -0.02754237 0.119956278 -0.022165045 [2,] -0.02544748 0.01691268 -0.09554424 -0.049752181 0.008690809 [3,] -0.02836024 0.05560006 0.07053068 -0.019997499 0.001893273 [4,] -0.02184953 -0.04856258 0.01825232 -0.011712873 -0.155657714 [5,] -0.02347517 -0.05050039 0.01978233 0.008824529 0.147983505 > dim(m1$A) [1] 5 5 > m1$A [,1] [,2] [,3] [,4] [,5] [1,] -6.9793413 -1.7790409 0.5794890 1.9345052 2.805629 [2,] 2.2701632 1.5691257 -1.3383301 -0.5780121 5.636725 [3,] 1.3509372 -0.9693974 -4.2710975 7.4068742 5.555762 [4,] 0.2184103 -9.4205302 -0.5522189 -2.8879327 -1.825547 [5,] 5.5698632 6.4384122 12.3250691 6.5092392 6.880336 > var(m1$S) [,1] [,2] [,3] [,4] [,5] [1,] 1.005988e+00 3.563506e-16 1.145233e-16 -2.504509e-16 -7.506129e-16 [2,] 3.563506e-16 1.005988e+00 -6.900569e-16 1.053911e-15 2.973376e-17 [3,] 1.145233e-16 -6.900569e-16 1.005988e+00 5.446843e-16 -4.204976e-17 [4,] -2.504509e-16 1.053911e-15 5.446843e-16 1.005988e+00 -2.545219e-16 [5,] -7.506129e-16 2.973376e-17 -4.204976e-17 -2.545219e-16 1.005988e+00