PCA

First, lets read the data, extract the variables we need, then center and optionaly scale the data.

strength_df <- read.table("~/Documents/repos/PSYCH7821/assets/assignments/HW2/strength.csv", header = TRUE)

X <- as.matrix(scale(strength_df[ , 6:11],
                       center = TRUE, 
                       scale = TRUE)
               )

X
##           dm1     nd1    dm2      nd2     dm3     nd3
##  [1,] -0.9588 -1.1144 -0.864 -0.99887 -0.9076 -0.9320
##  [2,] -0.3131 -0.0662 -0.267  0.00762 -0.3316 -0.1434
##  [3,] -0.1517  0.1959 -0.118  0.17537 -0.2596  0.0319
##  [4,] -0.4745  0.1959 -0.341  0.00762 -0.6196 -0.0558
##  [5,] -1.1203 -1.2891 -1.237 -1.33437 -1.3395 -1.3701
##  [6,] -0.1517 -0.7650 -0.491 -0.66337 -0.2596 -0.4939
##  [7,] -0.3131 -0.7650 -0.491 -0.66337 -0.4756 -0.7568
##  [8,] -0.7974 -0.9397 -1.088 -0.99887 -1.0515 -1.1949
##  [9,] -0.0709  0.0212 -0.043 -0.16012 -0.3316 -0.1434
## [10,] -0.4745 -0.2409 -0.416 -0.16012 -0.6196 -0.6691
## [11,] -0.4745  0.4579  0.405  1.26574  0.9643  1.7844
## [12,] -1.1203 -0.7650 -1.088 -0.83112 -1.1235 -1.1073
## [13,] -0.9588 -0.9397 -0.938 -0.66337 -0.8356 -0.4063
## [14,] -1.1203 -0.9397 -1.088 -0.83112 -1.1955 -1.0196
## [15,] -1.2817 -1.8132 -1.237 -1.75374 -1.4835 -1.6330
## [16,] -1.4431 -1.4638 -1.386 -1.33437 -1.1955 -1.3701
## [17,]  1.1398  1.5061  0.927  1.18187  0.9643  0.7329
## [18,]  1.3013  1.5061  1.225  1.34962  1.2523  1.6967
## [19,] -0.3131  0.2832 -0.192  0.67862  0.2443  0.7329
## [20,]  0.8170  1.3314  1.300  1.51737  1.3962  0.9957
## [21,]  0.7362  0.6326  0.629  0.34312  0.6043  0.3824
## [22,]  1.9470  1.3314  1.449  0.93024  1.6842  0.9957
## [23,]  2.5120  2.0302  2.942  2.10449  2.3322  1.7844
## [24,]  0.2519  0.4579  0.405  0.17537  0.2443 -0.2310
## [25,]  1.4627  0.9820  0.852  1.51737  0.9643  1.7844
## [26,]  0.3327 -0.0662 -0.192 -0.32787  0.2443 -0.4939
## [27,]  0.8170 -0.1535  0.852 -0.32787  0.2443  0.0319
## [28,] -0.6360 -1.2891 -0.640 -1.41824 -0.1876 -0.7568
## [29,]  0.9784  0.8073  1.002  0.67862  0.9643  0.5576
## [30,]  0.1712  0.5453 -0.043  0.17537 -0.0436  0.4700
## [31,]  0.8170  1.3314  1.151  1.34962  1.3962  1.4339
## [32,]  0.1712 -0.2409  0.106 -0.16012  0.1004  0.0319
## [33,] -1.2817 -0.7650 -1.088 -0.83112 -1.3395 -0.6691
## attr(,"scaled:center")
##  dm1  nd1  dm2  nd2  dm3  nd3 
## 28.9 25.8 31.6 28.9 35.6 32.6 
## attr(,"scaled:scale")
##  dm1  nd1  dm2  nd2  dm3  nd3 
## 12.4 11.4 13.4 11.9 13.9 11.4

You can fit the model with a single call to the function prcomp like this

pca_fit <- prcomp(X)

The proportion of variance explained can be obtained using the summary function

summary(pca_fit)
## Importance of components:
##                          PC1    PC2   PC3     PC4     PC5     PC6
## Standard deviation     2.358 0.5189 0.301 0.20207 0.16276 0.11612
## Proportion of Variance 0.927 0.0449 0.015 0.00681 0.00442 0.00225
## Cumulative Proportion  0.927 0.9715 0.987 0.99334 0.99775 1.00000

Now pca_fit is a list with three objects (rotation, sdev, X). You can access the objects with the $ operator, so for example:

Q is the loading matrix (eigenvectors)

Q <- pca_fit$rotation 
Q
##       PC1    PC2     PC3     PC4     PC5      PC6
## dm1 0.399 -0.602  0.1065 -0.6222  0.1288  0.25248
## nd1 0.413  0.149  0.6804  0.0749  0.2489 -0.52646
## dm2 0.413 -0.348 -0.0746  0.3689 -0.7345 -0.16596
## nd2 0.410  0.444  0.2423  0.1548 -0.0936  0.73744
## dm3 0.414 -0.165 -0.4804  0.4673  0.5934  0.00422
## nd3 0.401  0.520 -0.4803 -0.4784 -0.1456 -0.29616

sigma is the vector of standard deviations

sigma <- pca_fit$sdev 
sigma 
## [1] 2.358 0.519 0.301 0.202 0.163 0.116

Z is the matrix of sample PC scores

Z <- X %*% Q 
Z
##            PC1     PC2     PC3      PC4     PC5       PC6
##  [1,] -2.35773 -0.0666 -0.1542  0.06154 -0.0759  0.023514
##  [2,] -0.45402  0.2549  0.1716  0.00622 -0.0375  0.046756
##  [3,] -0.05106  0.2985  0.2778 -0.04375 -0.0595 -0.003102
##  [4,] -0.52517  0.5101  0.4345 -0.07771 -0.1219 -0.146745
##  [5,] -3.14030 -0.1711  0.0742 -0.03294 -0.0273  0.017165
##  [6,] -1.15607 -0.3603 -0.2988 -0.13172  0.1304  0.101842
##  [7,] -1.41540 -0.3642 -0.0860 -0.00646  0.0197  0.138025
##  [8,] -2.47874 -0.1728  0.1940 -0.04993  0.1056  0.086696
##  [9,] -0.29775 -0.0302  0.1994 -0.08128 -0.1332 -0.098943
## [10,] -1.05103  0.0776  0.3969  0.12948 -0.0708  0.153522
## [11,]  1.80065  1.5436 -0.7828  0.27184 -0.0504 -0.019040
## [12,] -2.46135  0.1793  0.3116  0.11446  0.0363  0.010655
## [13,] -1.93819  0.3958 -0.2356 -0.11881 -0.0428  0.035931
## [14,] -2.52809  0.2108  0.1852  0.02581 -0.0626  0.076372
## [15,] -3.75787 -0.4510 -0.2057  0.02177 -0.1865  0.020306
## [16,] -3.34310  0.0254 -0.1370  0.16708  0.0827  0.052990
## [17,]  2.63624 -0.0378  0.5480  0.02865  0.1957 -0.000391
## [18,]  3.39855  0.2895 -0.0177 -0.26223  0.0122 -0.169706
## [19,]  0.58599  0.9394 -0.1313  0.01378  0.1461  0.088165
## [20,]  3.01116  0.2150  0.1145  0.48211  0.0233  0.119526
## [21,]  1.35833 -0.3162  0.0711 -0.02619  0.0614 -0.109136
## [22,]  3.40216 -0.8250 -0.0569 -0.12225  0.2851 -0.051673
## [23,]  5.59751 -0.7559 -0.0382  0.23639 -0.4044  0.110549
## [24,]  0.53678 -0.3069  0.3443  0.27871  0.0114 -0.045860
## [25,]  3.07735  0.4117 -0.1924 -0.69011 -0.0228  0.305422
## [26,] -0.20525 -0.5858  0.0452  0.01685  0.4151  0.056237
## [27,]  0.59388 -0.9803 -0.2932 -0.15716 -0.3880 -0.104562
## [28,] -2.01200 -0.5784 -0.7870  0.11783  0.1988 -0.198270
## [29,]  2.03780 -0.3851  0.0121  0.11018  0.0188 -0.004857
## [30,]  0.51793  0.3225  0.2301 -0.29958  0.0786 -0.246754
## [31,]  3.05667  0.4204 -0.1255  0.19152  0.0848 -0.109170
## [32,]  0.00149 -0.2469 -0.2559 -0.07851 -0.0460  0.025309
## [33,] -2.43938  0.5400  0.1877 -0.09560 -0.1764 -0.160772

F (pattern matrix) is the loadings multiplied by a scaling factor

F <- Q %*% diag(sigma)
F
##      [,1]    [,2]    [,3]    [,4]    [,5]     [,6]
## dm1 0.940 -0.3123  0.0320 -0.1257  0.0210  0.02932
## nd1 0.973  0.0772  0.2045  0.0151  0.0405 -0.06113
## dm2 0.973 -0.1806 -0.0224  0.0745 -0.1195 -0.01927
## nd2 0.966  0.2303  0.0728  0.0313 -0.0152  0.08563
## dm3 0.977 -0.0856 -0.1444  0.0944  0.0966  0.00049
## nd3 0.946  0.2699 -0.1444 -0.0967 -0.0237 -0.03439

To extract the first factor, use subsetting with []. For example, the first factor is

f1 <- F[ , 1]
as.matrix(f1)
##      [,1]
## dm1 0.940
## nd1 0.973
## dm2 0.973
## nd2 0.966
## dm3 0.977
## nd3 0.946

sample PC scores scaled

Zs <- Z %*% diag(1/sigma)
Zs
##            [,1]    [,2]    [,3]    [,4]    [,5]     [,6]
##  [1,] -0.999936 -0.1283 -0.5131  0.3046 -0.4662  0.20251
##  [2,] -0.192554  0.4912  0.5708  0.0308 -0.2301  0.40266
##  [3,] -0.021655  0.5753  0.9243 -0.2165 -0.3658 -0.02671
##  [4,] -0.222728  0.9829  1.4456 -0.3845 -0.7488 -1.26376
##  [5,] -1.331833 -0.3298  0.2470 -0.1630 -0.1678  0.14782
##  [6,] -0.490303 -0.6942 -0.9942 -0.6519  0.8009  0.87706
##  [7,] -0.600284 -0.7019 -0.2860 -0.0320  0.1208  1.18866
##  [8,] -1.051259 -0.3330  0.6454 -0.2471  0.6488  0.74663
##  [9,] -0.126281 -0.0581  0.6636 -0.4022 -0.8186 -0.85209
## [10,] -0.445753  0.1495  1.3206  0.6408 -0.4349  1.32212
## [11,]  0.763673  2.9746 -2.6048  1.3453 -0.3094 -0.16397
## [12,] -1.043885  0.3456  1.0368  0.5664  0.2232  0.09176
## [13,] -0.822007  0.7628 -0.7840 -0.5880 -0.2630  0.30944
## [14,] -1.072191  0.4062  0.6163  0.1277 -0.3847  0.65771
## [15,] -1.593753 -0.8692 -0.6845  0.1077 -1.1457  0.17487
## [16,] -1.417844  0.0489 -0.4560  0.8269  0.5079  0.45635
## [17,]  1.118056 -0.0729  1.8236  0.1418  1.2024 -0.00337
## [18,]  1.441361  0.5578 -0.0589 -1.2977  0.0749 -1.46150
## [19,]  0.248525  1.8104 -0.4369  0.0682  0.8979  0.75927
## [20,]  1.277063  0.4144  0.3810  2.3858  0.1433  1.02935
## [21,]  0.576084 -0.6093  0.2366 -0.1296  0.3775 -0.93988
## [22,]  1.442893 -1.5897 -0.1893 -0.6050  1.7515 -0.44501
## [23,]  2.373963 -1.4566 -0.1270  1.1698 -2.4847  0.95204
## [24,]  0.227656 -0.5915  1.1455  1.3792  0.0698 -0.39494
## [25,]  1.305137  0.7933 -0.6401 -3.4151 -0.1399  2.63028
## [26,] -0.087050 -1.1289  0.1502  0.0834  2.5502  0.48431
## [27,]  0.251869 -1.8891 -0.9754 -0.7777 -2.3839 -0.90049
## [28,] -0.853309 -1.1147 -2.6188  0.5831  1.2212 -1.70749
## [29,]  0.864251 -0.7420  0.0403  0.5453  0.1156 -0.04183
## [30,]  0.219661  0.6215  0.7657 -1.4825  0.4829 -2.12503
## [31,]  1.296363  0.8101 -0.4175  0.9478  0.5213 -0.94016
## [32,]  0.000634 -0.4758 -0.8514 -0.3885 -0.2829  0.21796
## [33,] -1.034565  1.0406  0.6245 -0.4731 -1.0838 -1.38456

The first standardized principle component pc1

z1 <- Zs[ , 1]
as.matrix(z1)
##            [,1]
##  [1,] -0.999936
##  [2,] -0.192554
##  [3,] -0.021655
##  [4,] -0.222728
##  [5,] -1.331833
##  [6,] -0.490303
##  [7,] -0.600284
##  [8,] -1.051259
##  [9,] -0.126281
## [10,] -0.445753
## [11,]  0.763673
## [12,] -1.043885
## [13,] -0.822007
## [14,] -1.072191
## [15,] -1.593753
## [16,] -1.417844
## [17,]  1.118056
## [18,]  1.441361
## [19,]  0.248525
## [20,]  1.277063
## [21,]  0.576084
## [22,]  1.442893
## [23,]  2.373963
## [24,]  0.227656
## [25,]  1.305137
## [26,] -0.087050
## [27,]  0.251869
## [28,] -0.853309
## [29,]  0.864251
## [30,]  0.219661
## [31,]  1.296363
## [32,]  0.000634
## [33,] -1.034565

plots

biplot(pca_fit, scale = 0)

plot(pca_fit)

comparison with SVD (Advanced)

svd_fit <- svd(X)

# singular values

Sigma_svd <- diag(svd_fit$d)
Sigma_svd 
##      [,1] [,2] [,3] [,4]  [,5]  [,6]
## [1,] 13.3 0.00  0.0 0.00 0.000 0.000
## [2,]  0.0 2.94  0.0 0.00 0.000 0.000
## [3,]  0.0 0.00  1.7 0.00 0.000 0.000
## [4,]  0.0 0.00  0.0 1.14 0.000 0.000
## [5,]  0.0 0.00  0.0 0.00 0.921 0.000
## [6,]  0.0 0.00  0.0 0.00 0.000 0.657
#the left singular vectors 
U  <- svd_fit$u
U
##            [,1]     [,2]     [,3]     [,4]    [,5]      [,6]
##  [1,] -0.176765 -0.02268 -0.09071  0.05384 -0.0824  0.035798
##  [2,] -0.034039  0.08683  0.10091  0.00544 -0.0407  0.071181
##  [3,] -0.003828  0.10170  0.16340 -0.03828 -0.0647 -0.004722
##  [4,] -0.039373  0.17376  0.25556 -0.06798 -0.1324 -0.223403
##  [5,] -0.235437 -0.05829  0.04366 -0.02882 -0.0297  0.026132
##  [6,] -0.086674 -0.12272 -0.17575 -0.11523  0.1416  0.155043
##  [7,] -0.106116 -0.12407 -0.05056 -0.00565  0.0214  0.210128
##  [8,] -0.185838 -0.05888  0.11410 -0.04368  0.1147  0.131986
##  [9,] -0.022323 -0.01027  0.11731 -0.07111 -0.1447 -0.150630
## [10,] -0.078799  0.02643  0.23345  0.11327 -0.0769  0.233720
## [11,]  0.135000  0.52583 -0.46046  0.23781 -0.0547 -0.028986
## [12,] -0.184535  0.06109  0.18328  0.10013  0.0395  0.016221
## [13,] -0.145312  0.13484 -0.13860 -0.10394 -0.0465  0.054701
## [14,] -0.189538  0.07181  0.10895  0.02258 -0.0680  0.116268
## [15,] -0.281738 -0.15365 -0.12100  0.01905 -0.2025  0.030914
## [16,] -0.250642  0.00864 -0.08061  0.14617  0.0898  0.080672
## [17,]  0.197646 -0.01288  0.32237  0.02506  0.2126 -0.000596
## [18,]  0.254799  0.09861 -0.01042 -0.22940  0.0132 -0.258359
## [19,]  0.043933  0.32003 -0.07723  0.01205  0.1587  0.134222
## [20,]  0.225755  0.07325  0.06734  0.42176  0.0253  0.181965
## [21,]  0.101838 -0.10771  0.04182 -0.02291  0.0667 -0.166148
## [22,]  0.255070 -0.28103 -0.03347 -0.10694  0.3096 -0.078667
## [23,]  0.419661 -0.25750 -0.02244  0.20680 -0.4392  0.168299
## [24,]  0.040244 -0.10456  0.20250  0.24382  0.0123 -0.069817
## [25,]  0.230718  0.14024 -0.11315 -0.60372 -0.0247  0.464972
## [26,] -0.015388 -0.19957  0.02656  0.01474  0.4508  0.085614
## [27,]  0.044525 -0.33395 -0.17244 -0.13748 -0.4214 -0.159185
## [28,] -0.150845 -0.19705 -0.46294  0.10308  0.2159 -0.301844
## [29,]  0.152779 -0.13118  0.00712  0.09639  0.0204 -0.007394
## [30,]  0.038831  0.10987  0.13536 -0.26208  0.0854 -0.375656
## [31,]  0.229167  0.14321 -0.07381  0.16754  0.0922 -0.166199
## [32,]  0.000112 -0.08410 -0.15051 -0.06868 -0.0500  0.038530
## [33,] -0.182887  0.18395  0.11041 -0.08363 -0.1916 -0.244758
#the right singular vectors
Q <- svd_fit$v
Q
##       [,1]   [,2]    [,3]    [,4]    [,5]     [,6]
## [1,] 0.399 -0.602  0.1065 -0.6222  0.1288  0.25248
## [2,] 0.413  0.149  0.6804  0.0749  0.2489 -0.52646
## [3,] 0.413 -0.348 -0.0746  0.3689 -0.7345 -0.16596
## [4,] 0.410  0.444  0.2423  0.1548 -0.0936  0.73744
## [5,] 0.414 -0.165 -0.4804  0.4673  0.5934  0.00422
## [6,] 0.401  0.520 -0.4803 -0.4784 -0.1456 -0.29616
#reconstuction error residual
res <- X - U %*% Sigma_svd %*% t(Q)
res 
##             dm1       nd1       dm2       nd2       dm3       nd3
##  [1,]  0.00e+00 -3.77e-15 -1.11e-16 -3.77e-15  2.22e-16 -1.11e-16
##  [2,]  2.78e-16  2.08e-16  2.22e-16 -1.72e-16  2.22e-16  3.05e-16
##  [3,]  2.78e-16 -2.50e-16  1.11e-16  3.05e-16  3.33e-16 -2.08e-17
##  [4,]  4.44e-16 -2.78e-16  1.67e-16  1.02e-16  4.44e-16 -1.18e-16
##  [5,] -2.22e-16 -4.44e-16  6.66e-16  0.00e+00  4.44e-16  0.00e+00
##  [6,] -1.94e-16 -1.11e-16  3.89e-16  0.00e+00  1.67e-16 -2.22e-16
##  [7,] -2.22e-16  0.00e+00  1.67e-16  0.00e+00  1.11e-16  1.11e-16
##  [8,]  0.00e+00 -4.44e-16  4.44e-16  0.00e+00  2.22e-16  0.00e+00
##  [9,] -2.78e-17 -3.82e-17  2.08e-17  0.00e+00  2.22e-16 -1.11e-16
## [10,]  3.33e-16 -2.50e-16  2.78e-16  5.55e-17  1.11e-16  2.22e-16
## [11,]  1.05e-15  1.67e-16 -3.33e-16 -2.22e-16 -5.55e-16  4.44e-16
## [12,]  2.22e-16 -3.33e-16  0.00e+00  0.00e+00  6.66e-16  4.44e-16
## [13,]  3.33e-16 -2.22e-16  5.55e-16 -2.22e-16  3.33e-16  1.67e-16
## [14,]  2.22e-16 -4.44e-16  6.66e-16  0.00e+00  4.44e-16  2.22e-16
## [15,]  0.00e+00  0.00e+00  4.44e-16  0.00e+00  4.44e-16  4.44e-16
## [16,]  2.22e-16 -2.22e-16  4.44e-16 -2.22e-16  4.44e-16  6.66e-16
## [17,]  2.22e-16  0.00e+00 -2.22e-16  4.44e-16 -6.66e-16 -5.55e-16
## [18,]  0.00e+00  2.22e-16 -6.66e-16 -2.22e-16 -6.66e-16 -4.44e-16
## [19,]  5.55e-16  0.00e+00  1.94e-16  0.00e+00 -2.78e-17  3.33e-16
## [20,]  1.11e-16  2.22e-16 -6.66e-16  0.00e+00 -1.33e-15 -2.22e-16
## [21,] -1.11e-16  1.11e-16 -2.22e-16  2.22e-16 -1.11e-16 -3.33e-16
## [22,] -8.88e-16  2.22e-16 -6.66e-16  1.11e-16 -8.88e-16 -9.99e-16
## [23,] -4.44e-16  8.88e-16 -1.78e-15  4.44e-16 -1.78e-15 -4.44e-16
## [24,] -5.55e-17  1.11e-16 -3.33e-16  3.05e-16 -1.67e-16  2.22e-16
## [25,] -2.22e-16 -3.33e-16  0.00e+00  0.00e+00 -7.77e-16 -1.11e-15
## [26,] -3.89e-16  1.25e-16  2.78e-17  2.78e-16 -1.39e-16 -3.33e-16
## [27,] -9.99e-16  2.78e-16 -3.33e-16 -1.11e-16 -4.44e-16 -4.72e-16
## [28,] -7.77e-16  2.22e-16 -3.33e-16 -4.44e-16 -3.61e-16 -1.11e-16
## [29,] -6.66e-16  2.22e-16 -6.66e-16  3.33e-16 -6.66e-16 -1.11e-16
## [30,]  8.33e-17 -1.11e-16  2.29e-16  1.11e-16  4.02e-16 -2.22e-16
## [31,]  3.33e-16  4.44e-16 -2.22e-16  4.44e-16 -6.66e-16  0.00e+00
## [32,] -2.22e-16  8.33e-17 -6.94e-17 -1.67e-16 -8.33e-17 -1.25e-16
## [33,]  4.44e-16 -4.44e-16  2.22e-16 -1.11e-16  6.66e-16  3.33e-16
## attr(,"scaled:center")
##  dm1  nd1  dm2  nd2  dm3  nd3 
## 28.9 25.8 31.6 28.9 35.6 32.6 
## attr(,"scaled:scale")
##  dm1  nd1  dm2  nd2  dm3  nd3 
## 12.4 11.4 13.4 11.9 13.9 11.4
Z_svd1 <- U %*% Sigma_svd 
Z_svd1
##           [,1]    [,2]    [,3]     [,4]    [,5]      [,6]
##  [1,] -2.35773 -0.0666 -0.1542  0.06154 -0.0759  0.023514
##  [2,] -0.45402  0.2549  0.1716  0.00622 -0.0375  0.046756
##  [3,] -0.05106  0.2985  0.2778 -0.04375 -0.0595 -0.003102
##  [4,] -0.52517  0.5101  0.4345 -0.07771 -0.1219 -0.146745
##  [5,] -3.14030 -0.1711  0.0742 -0.03294 -0.0273  0.017165
##  [6,] -1.15607 -0.3603 -0.2988 -0.13172  0.1304  0.101842
##  [7,] -1.41540 -0.3642 -0.0860 -0.00646  0.0197  0.138025
##  [8,] -2.47874 -0.1728  0.1940 -0.04993  0.1056  0.086696
##  [9,] -0.29775 -0.0302  0.1994 -0.08128 -0.1332 -0.098943
## [10,] -1.05103  0.0776  0.3969  0.12948 -0.0708  0.153522
## [11,]  1.80065  1.5436 -0.7828  0.27184 -0.0504 -0.019040
## [12,] -2.46135  0.1793  0.3116  0.11446  0.0363  0.010655
## [13,] -1.93819  0.3958 -0.2356 -0.11881 -0.0428  0.035931
## [14,] -2.52809  0.2108  0.1852  0.02581 -0.0626  0.076372
## [15,] -3.75787 -0.4510 -0.2057  0.02177 -0.1865  0.020306
## [16,] -3.34310  0.0254 -0.1370  0.16708  0.0827  0.052990
## [17,]  2.63624 -0.0378  0.5480  0.02865  0.1957 -0.000391
## [18,]  3.39855  0.2895 -0.0177 -0.26223  0.0122 -0.169706
## [19,]  0.58599  0.9394 -0.1313  0.01378  0.1461  0.088165
## [20,]  3.01116  0.2150  0.1145  0.48211  0.0233  0.119526
## [21,]  1.35833 -0.3162  0.0711 -0.02619  0.0614 -0.109136
## [22,]  3.40216 -0.8250 -0.0569 -0.12225  0.2851 -0.051673
## [23,]  5.59751 -0.7559 -0.0382  0.23639 -0.4044  0.110549
## [24,]  0.53678 -0.3069  0.3443  0.27871  0.0114 -0.045860
## [25,]  3.07735  0.4117 -0.1924 -0.69011 -0.0228  0.305422
## [26,] -0.20525 -0.5858  0.0452  0.01685  0.4151  0.056237
## [27,]  0.59388 -0.9803 -0.2932 -0.15716 -0.3880 -0.104562
## [28,] -2.01200 -0.5784 -0.7870  0.11783  0.1988 -0.198270
## [29,]  2.03780 -0.3851  0.0121  0.11018  0.0188 -0.004857
## [30,]  0.51793  0.3225  0.2301 -0.29958  0.0786 -0.246754
## [31,]  3.05667  0.4204 -0.1255  0.19152  0.0848 -0.109170
## [32,]  0.00149 -0.2469 -0.2559 -0.07851 -0.0460  0.025309
## [33,] -2.43938  0.5400  0.1877 -0.09560 -0.1764 -0.160772
Z_svd2 <- X %*% Q
Z_svd2
##           [,1]    [,2]    [,3]     [,4]    [,5]      [,6]
##  [1,] -2.35773 -0.0666 -0.1542  0.06154 -0.0759  0.023514
##  [2,] -0.45402  0.2549  0.1716  0.00622 -0.0375  0.046756
##  [3,] -0.05106  0.2985  0.2778 -0.04375 -0.0595 -0.003102
##  [4,] -0.52517  0.5101  0.4345 -0.07771 -0.1219 -0.146745
##  [5,] -3.14030 -0.1711  0.0742 -0.03294 -0.0273  0.017165
##  [6,] -1.15607 -0.3603 -0.2988 -0.13172  0.1304  0.101842
##  [7,] -1.41540 -0.3642 -0.0860 -0.00646  0.0197  0.138025
##  [8,] -2.47874 -0.1728  0.1940 -0.04993  0.1056  0.086696
##  [9,] -0.29775 -0.0302  0.1994 -0.08128 -0.1332 -0.098943
## [10,] -1.05103  0.0776  0.3969  0.12948 -0.0708  0.153522
## [11,]  1.80065  1.5436 -0.7828  0.27184 -0.0504 -0.019040
## [12,] -2.46135  0.1793  0.3116  0.11446  0.0363  0.010655
## [13,] -1.93819  0.3958 -0.2356 -0.11881 -0.0428  0.035931
## [14,] -2.52809  0.2108  0.1852  0.02581 -0.0626  0.076372
## [15,] -3.75787 -0.4510 -0.2057  0.02177 -0.1865  0.020306
## [16,] -3.34310  0.0254 -0.1370  0.16708  0.0827  0.052990
## [17,]  2.63624 -0.0378  0.5480  0.02865  0.1957 -0.000391
## [18,]  3.39855  0.2895 -0.0177 -0.26223  0.0122 -0.169706
## [19,]  0.58599  0.9394 -0.1313  0.01378  0.1461  0.088165
## [20,]  3.01116  0.2150  0.1145  0.48211  0.0233  0.119526
## [21,]  1.35833 -0.3162  0.0711 -0.02619  0.0614 -0.109136
## [22,]  3.40216 -0.8250 -0.0569 -0.12225  0.2851 -0.051673
## [23,]  5.59751 -0.7559 -0.0382  0.23639 -0.4044  0.110549
## [24,]  0.53678 -0.3069  0.3443  0.27871  0.0114 -0.045860
## [25,]  3.07735  0.4117 -0.1924 -0.69011 -0.0228  0.305422
## [26,] -0.20525 -0.5858  0.0452  0.01685  0.4151  0.056237
## [27,]  0.59388 -0.9803 -0.2932 -0.15716 -0.3880 -0.104562
## [28,] -2.01200 -0.5784 -0.7870  0.11783  0.1988 -0.198270
## [29,]  2.03780 -0.3851  0.0121  0.11018  0.0188 -0.004857
## [30,]  0.51793  0.3225  0.2301 -0.29958  0.0786 -0.246754
## [31,]  3.05667  0.4204 -0.1255  0.19152  0.0848 -0.109170
## [32,]  0.00149 -0.2469 -0.2559 -0.07851 -0.0460  0.025309
## [33,] -2.43938  0.5400  0.1877 -0.09560 -0.1764 -0.160772