PCA - grade data

116 days ago by jhlee2chn

# grade data (R-code) Final <- c(100,0,0,100,100,120,0,0,120,0,0,120,0,120,110,0,100,120,0,60,120,110,0,100,110,0,0,110,120,120,0,80,60,120,120,40,120,110,120,100,120,100,0,0,120,120,120,0,0) PBL <- c(66,0,0,72,65,78,0,0,77,0,0,78,0,71,70,0,66,79,0,0,73,71,0,44,78,0,0,72,76,79,0,68,63,69,79,0,73,77,69,64,78,70,0,0,77,78,77,0,0) Mid <- c(61,0,0,75,80,97,0,0,98,0,0,97,0,90,91,0,63,93,0,61,98,96,0,75,97,40,0,97,38,98,0,62,0,86,98,20,95,97,95,60,97,0,0,0,97,91,96,0,0) QnA <- c(47,25,0,50,50,0,3,24,50,21,18,50,1,45,55,23,49,50,25,44,47,50,18,49,50,38,13,49,47,50,18,48,47,50,50,45,50,50,49,49,44,42,36,0,50,50,45,4,16) Atte <- c(35,21,0,36,36,36,3,21,35,17,15,36,0,32,36,20,35,36,23,34,34,36,15,36,35,30,11,36,35,36,15,35,35,36,36,35,36,35,36,36,36,25,30,0,36,36,36,3,14) Project <- c(0,0,0,9,0,10,0,0,7,0,0,10,0,0,0,0,0,8,0,0,10,0,0,10,0,0,0,0,10,10,0,0,9,9,10,0,10,0,0,0,0,8,0,0,10,10,10,0,0) data <- data.frame(Final, PBL, Mid, QnA, Atte, Project) 
       
# centering, scaling mydata <- scale(data, center = T, scale = T) mydata 
       
           Final           PBL        Mid         QnA       Atte   
Project
 [1,]  0.5654951  0.6131768284  0.2122585  0.60141755  0.6115025
-0.7162703
 [2,] -1.2941868 -1.2280616702 -1.1976096 -0.64776958 -0.5768565
-0.7162703
 [3,] -1.2941868 -1.2280616702 -1.1976096 -2.06730041 -2.3593950
-0.7162703
 [4,]  0.5654951  0.7805621464  0.5358348  0.77176125  0.6963853 
1.2579498
 [5,]  0.5654951  0.5852792754  0.6513978  0.77176125  0.6963853
-0.7162703
 [6,]  0.9374315  0.9479474645  1.0443118 -2.06730041  0.6963853 
1.4773076
 [7,] -1.2941868 -1.2280616702 -1.1976096 -1.89695671 -2.1047467
-0.7162703
 [8,] -1.2941868 -1.2280616702 -1.1976096 -0.70455081 -0.5768565
-0.7162703
 [9,]  0.9374315  0.9200499115  1.0674244  0.77176125  0.6115025 
0.8192342
[10,] -1.2941868 -1.2280616702 -1.1976096 -0.87489451 -0.9163876
-0.7162703
[11,] -1.2941868 -1.2280616702 -1.1976096 -1.04523821 -1.0861532
-0.7162703
[12,]  0.9374315  0.9479474645  1.0443118  0.77176125  0.6963853 
1.4773076
[13,] -1.2941868 -1.2280616702 -1.1976096 -2.01051917 -2.3593950
-0.7162703
[14,]  0.9374315  0.7526645934  0.8825237  0.48785508  0.3568542
-0.7162703
[15,]  0.7514633  0.7247670404  0.9056363  1.05566742  0.6963853
-0.7162703
[16,] -1.2941868 -1.2280616702 -1.1976096 -0.76133204 -0.6617393
-0.7162703
[17,]  0.5654951  0.6131768284  0.2584837  0.71498002  0.6115025
-0.7162703
[18,]  0.9374315  0.9758450175  0.9518614  0.77176125  0.6963853 
1.0385920
[19,] -1.2941868 -1.2280616702 -1.1976096 -0.64776958 -0.4070909
-0.7162703
[20,] -0.1783776 -1.2280616702  0.2122585  0.43107385  0.5266197
-0.7162703
[21,]  0.9374315  0.8084596994  1.0674244  0.60141755  0.5266197 
1.4773076
[22,]  0.7514633  0.7526645934  1.0211992  0.77176125  0.6963853
-0.7162703
[23,] -1.2941868 -1.2280616702 -1.1976096 -1.04523821 -1.0861532
-0.7162703
[24,]  0.5654951 -0.0005693378  0.5358348  0.71498002  0.6963853 
1.4773076
[25,]  0.7514633  0.9479474645  1.0443118  0.77176125  0.6115025
-0.7162703
[26,] -1.2941868 -1.2280616702 -0.2731059  0.09038645  0.1870886
-0.7162703
[27,] -1.2941868 -1.2280616702 -1.1976096 -1.32914438 -1.4256844
-0.7162703
[28,]  0.7514633  0.7805621464  1.0443118  0.71498002  0.6963853
-0.7162703
[29,]  0.9374315  0.8921523585 -0.3193311  0.60141755  0.6115025 
1.4773076
[30,]  0.9374315  0.9758450175  1.0674244  0.77176125  0.6963853 
1.4773076
[31,] -1.2941868 -1.2280616702 -1.1976096 -1.04523821 -1.0861532
-0.7162703
[32,]  0.1935587  0.6689719344  0.2353711  0.65819878  0.6115025
-0.7162703
[33,] -0.1783776  0.5294841693 -1.1976096  0.60141755  0.6115025 
1.2579498
[34,]  0.9374315  0.6968694874  0.7900733  0.77176125  0.6963853 
1.2579498
[35,]  0.9374315  0.9758450175  1.0674244  0.77176125  0.6963853 
1.4773076
[36,] -0.5503140 -1.2280616702 -0.7353578  0.48785508  0.6115025
-0.7162703
[37,]  0.9374315  0.8084596994  0.9980866  0.77176125  0.6963853 
1.4773076
[38,]  0.7514633  0.9200499115  1.0443118  0.77176125  0.6115025
-0.7162703
[39,]  0.9374315  0.6968694874  0.9980866  0.71498002  0.6963853
-0.7162703
[40,]  0.5654951  0.5573817224  0.1891459  0.71498002  0.6963853
-0.7162703
[41,]  0.9374315  0.9479474645  1.0443118  0.43107385  0.6963853
-0.7162703
[42,]  0.5654951  0.7247670404 -1.1976096  0.31751139 -0.2373253 
1.0385920
[43,] -1.2941868 -1.2280616702 -1.1976096 -0.02317601  0.1870886
-0.7162703
[44,] -1.2941868 -1.2280616702 -1.1976096 -2.06730041 -2.3593950
-0.7162703
[45,]  0.9374315  0.9200499115  1.0443118  0.77176125  0.6963853 
1.4773076
[46,]  0.9374315  0.9479474645  0.9056363  0.77176125  0.6963853 
1.4773076
[47,]  0.9374315  0.9200499115  1.0211992  0.48785508  0.6963853 
1.4773076
[48,] -1.2941868 -1.2280616702 -1.1976096 -1.84017547 -2.1047467
-0.7162703
[49,] -1.2941868 -1.2280616702 -1.1976096 -1.15880068 -1.1710360
-0.7162703
attr(,"scaled:center")
    Final       PBL       Mid       QnA      Atte   Project 
69.591837 44.020408 51.816327 36.408163 27.795918  3.265306 
attr(,"scaled:scale")
    Final       PBL       Mid       QnA      Atte   Project 
53.772638 35.845438 43.266458 17.611453 11.780951  4.558762 
           Final           PBL        Mid         QnA       Atte    Project
 [1,]  0.5654951  0.6131768284  0.2122585  0.60141755  0.6115025 -0.7162703
 [2,] -1.2941868 -1.2280616702 -1.1976096 -0.64776958 -0.5768565 -0.7162703
 [3,] -1.2941868 -1.2280616702 -1.1976096 -2.06730041 -2.3593950 -0.7162703
 [4,]  0.5654951  0.7805621464  0.5358348  0.77176125  0.6963853  1.2579498
 [5,]  0.5654951  0.5852792754  0.6513978  0.77176125  0.6963853 -0.7162703
 [6,]  0.9374315  0.9479474645  1.0443118 -2.06730041  0.6963853  1.4773076
 [7,] -1.2941868 -1.2280616702 -1.1976096 -1.89695671 -2.1047467 -0.7162703
 [8,] -1.2941868 -1.2280616702 -1.1976096 -0.70455081 -0.5768565 -0.7162703
 [9,]  0.9374315  0.9200499115  1.0674244  0.77176125  0.6115025  0.8192342
[10,] -1.2941868 -1.2280616702 -1.1976096 -0.87489451 -0.9163876 -0.7162703
[11,] -1.2941868 -1.2280616702 -1.1976096 -1.04523821 -1.0861532 -0.7162703
[12,]  0.9374315  0.9479474645  1.0443118  0.77176125  0.6963853  1.4773076
[13,] -1.2941868 -1.2280616702 -1.1976096 -2.01051917 -2.3593950 -0.7162703
[14,]  0.9374315  0.7526645934  0.8825237  0.48785508  0.3568542 -0.7162703
[15,]  0.7514633  0.7247670404  0.9056363  1.05566742  0.6963853 -0.7162703
[16,] -1.2941868 -1.2280616702 -1.1976096 -0.76133204 -0.6617393 -0.7162703
[17,]  0.5654951  0.6131768284  0.2584837  0.71498002  0.6115025 -0.7162703
[18,]  0.9374315  0.9758450175  0.9518614  0.77176125  0.6963853  1.0385920
[19,] -1.2941868 -1.2280616702 -1.1976096 -0.64776958 -0.4070909 -0.7162703
[20,] -0.1783776 -1.2280616702  0.2122585  0.43107385  0.5266197 -0.7162703
[21,]  0.9374315  0.8084596994  1.0674244  0.60141755  0.5266197  1.4773076
[22,]  0.7514633  0.7526645934  1.0211992  0.77176125  0.6963853 -0.7162703
[23,] -1.2941868 -1.2280616702 -1.1976096 -1.04523821 -1.0861532 -0.7162703
[24,]  0.5654951 -0.0005693378  0.5358348  0.71498002  0.6963853  1.4773076
[25,]  0.7514633  0.9479474645  1.0443118  0.77176125  0.6115025 -0.7162703
[26,] -1.2941868 -1.2280616702 -0.2731059  0.09038645  0.1870886 -0.7162703
[27,] -1.2941868 -1.2280616702 -1.1976096 -1.32914438 -1.4256844 -0.7162703
[28,]  0.7514633  0.7805621464  1.0443118  0.71498002  0.6963853 -0.7162703
[29,]  0.9374315  0.8921523585 -0.3193311  0.60141755  0.6115025  1.4773076
[30,]  0.9374315  0.9758450175  1.0674244  0.77176125  0.6963853  1.4773076
[31,] -1.2941868 -1.2280616702 -1.1976096 -1.04523821 -1.0861532 -0.7162703
[32,]  0.1935587  0.6689719344  0.2353711  0.65819878  0.6115025 -0.7162703
[33,] -0.1783776  0.5294841693 -1.1976096  0.60141755  0.6115025  1.2579498
[34,]  0.9374315  0.6968694874  0.7900733  0.77176125  0.6963853  1.2579498
[35,]  0.9374315  0.9758450175  1.0674244  0.77176125  0.6963853  1.4773076
[36,] -0.5503140 -1.2280616702 -0.7353578  0.48785508  0.6115025 -0.7162703
[37,]  0.9374315  0.8084596994  0.9980866  0.77176125  0.6963853  1.4773076
[38,]  0.7514633  0.9200499115  1.0443118  0.77176125  0.6115025 -0.7162703
[39,]  0.9374315  0.6968694874  0.9980866  0.71498002  0.6963853 -0.7162703
[40,]  0.5654951  0.5573817224  0.1891459  0.71498002  0.6963853 -0.7162703
[41,]  0.9374315  0.9479474645  1.0443118  0.43107385  0.6963853 -0.7162703
[42,]  0.5654951  0.7247670404 -1.1976096  0.31751139 -0.2373253  1.0385920
[43,] -1.2941868 -1.2280616702 -1.1976096 -0.02317601  0.1870886 -0.7162703
[44,] -1.2941868 -1.2280616702 -1.1976096 -2.06730041 -2.3593950 -0.7162703
[45,]  0.9374315  0.9200499115  1.0443118  0.77176125  0.6963853  1.4773076
[46,]  0.9374315  0.9479474645  0.9056363  0.77176125  0.6963853  1.4773076
[47,]  0.9374315  0.9200499115  1.0211992  0.48785508  0.6963853  1.4773076
[48,] -1.2941868 -1.2280616702 -1.1976096 -1.84017547 -2.1047467 -0.7162703
[49,] -1.2941868 -1.2280616702 -1.1976096 -1.15880068 -1.1710360 -0.7162703
attr(,"scaled:center")
    Final       PBL       Mid       QnA      Atte   Project 
69.591837 44.020408 51.816327 36.408163 27.795918  3.265306 
attr(,"scaled:scale")
    Final       PBL       Mid       QnA      Atte   Project 
53.772638 35.845438 43.266458 17.611453 11.780951  4.558762 
# principal component analysis mypca <- prcomp(mydata, center = F, scale = F, retx = T) summary(mypca) 
       
Importance of components:
                          PC1    PC2     PC3     PC4     PC5     PC6
Standard deviation     2.1617 0.8501 0.60810 0.36715 0.28017 0.14616
Proportion of Variance 0.7788 0.1205 0.06163 0.02247 0.01308 0.00356
Cumulative Proportion  0.7788 0.8993 0.96089 0.98336 0.99644 1.00000
Importance of components:
                          PC1    PC2     PC3     PC4     PC5     PC6
Standard deviation     2.1617 0.8501 0.60810 0.36715 0.28017 0.14616
Proportion of Variance 0.7788 0.1205 0.06163 0.02247 0.01308 0.00356
Cumulative Proportion  0.7788 0.8993 0.96089 0.98336 0.99644 1.00000
# loadings (rotation matrix) mypca$rotation 
       
               PC1         PC2        PC3        PC4         PC5        
PC6
Final   -0.4500057  0.03518674  0.2949377 -0.2185785  0.04156574 
0.81225877
PBL     -0.4381927  0.07680633  0.3328376 -0.5930696  0.22389618
-0.53800190
Mid     -0.4233017 -0.10651782  0.4894729  0.6508663 -0.31536101
-0.21634805
QnA     -0.4038055 -0.36872301 -0.5301262 -0.2321380 -0.60321448
-0.04684924
Atte    -0.4224637 -0.26483275 -0.4165005  0.3220256  0.68834465
-0.01991293
Project -0.2911413  0.88058139 -0.3288476  0.1388398 -0.10490073
-0.03730683
               PC1         PC2        PC3        PC4         PC5         PC6
Final   -0.4500057  0.03518674  0.2949377 -0.2185785  0.04156574  0.81225877
PBL     -0.4381927  0.07680633  0.3328376 -0.5930696  0.22389618 -0.53800190
Mid     -0.4233017 -0.10651782  0.4894729  0.6508663 -0.31536101 -0.21634805
QnA     -0.4038055 -0.36872301 -0.5301262 -0.2321380 -0.60321448 -0.04684924
Atte    -0.4224637 -0.26483275 -0.4165005  0.3220256  0.68834465 -0.01991293
Project -0.2911413  0.88058139 -0.3288476  0.1388398 -0.10490073 -0.03730683
# PC1~PC2 scores mypca$x[, 1:2] 
       
             PC1         PC2
 [1,] -0.9056725 -0.97005223
 [2,]  2.3412789 -0.25141065
 [3,]  3.6675512  0.74407761
 [4,] -1.7954125  0.66150948
 [5,] -1.1839820 -1.10426048
 [6,] -1.1688074  1.87328086
 [7,]  3.4911858  0.61382874
 [8,]  2.3642075 -0.23047411
 [9,] -2.0853432  0.26484146
[10,]  2.5764328 -0.07774550
[11,]  2.7169384  0.03002363
[12,] -2.3152363  0.82645349
[13,]  3.6446226  0.72314106
[14,] -1.2644560 -0.90833432
[15,] -1.5510537 -1.21876699
[16,]  2.4229960 -0.18705782
[17,] -0.9710969 -1.01684913
[18,] -2.1605982  0.45211904
[19,]  2.2695592 -0.29637014
[20,]  0.3405374 -1.05235609
[21,] -2.1233918  0.92104717
[22,] -1.4975534 -1.12425106
[23,]  2.7169384  0.03002363
[24,] -1.4940619  0.81561257
[25,] -1.5570486 -1.08923426
[26,]  1.3291244 -0.82437956
[27,]  2.9750208  0.22462533
[28,] -1.4966329 -1.10363370
[29,] -1.6089093  1.05270973
[30,] -2.3372444  0.82613430
[31,]  2.7169384  0.03002363
[32,] -0.7954602 -1.00225249
[33,] -0.5122295  0.88598274
[34,] -2.0337320  0.64108766
[35,] -2.3372444  0.82613430
[36,]  0.8502499 -1.00792159
[37,] -2.2345466  0.82066375
[38,] -1.5448241 -1.09137696
[39,] -1.5240789 -1.09859441
[40,] -0.9531570 -1.03622858
[41,] -1.5390238 -0.97955110
[42,] -0.3954420  1.06347393
[43,]  1.7663255 -0.68403035
[44,]  3.6675512  0.74407761
[45,] -2.3030118  0.82431078
[46,] -2.2565347  0.84122491
[47,] -2.1785853  0.93145542
[48,]  3.4682572  0.59289220
[49,]  2.7986554  0.09437647
             PC1         PC2
 [1,] -0.9056725 -0.97005223
 [2,]  2.3412789 -0.25141065
 [3,]  3.6675512  0.74407761
 [4,] -1.7954125  0.66150948
 [5,] -1.1839820 -1.10426048
 [6,] -1.1688074  1.87328086
 [7,]  3.4911858  0.61382874
 [8,]  2.3642075 -0.23047411
 [9,] -2.0853432  0.26484146
[10,]  2.5764328 -0.07774550
[11,]  2.7169384  0.03002363
[12,] -2.3152363  0.82645349
[13,]  3.6446226  0.72314106
[14,] -1.2644560 -0.90833432
[15,] -1.5510537 -1.21876699
[16,]  2.4229960 -0.18705782
[17,] -0.9710969 -1.01684913
[18,] -2.1605982  0.45211904
[19,]  2.2695592 -0.29637014
[20,]  0.3405374 -1.05235609
[21,] -2.1233918  0.92104717
[22,] -1.4975534 -1.12425106
[23,]  2.7169384  0.03002363
[24,] -1.4940619  0.81561257
[25,] -1.5570486 -1.08923426
[26,]  1.3291244 -0.82437956
[27,]  2.9750208  0.22462533
[28,] -1.4966329 -1.10363370
[29,] -1.6089093  1.05270973
[30,] -2.3372444  0.82613430
[31,]  2.7169384  0.03002363
[32,] -0.7954602 -1.00225249
[33,] -0.5122295  0.88598274
[34,] -2.0337320  0.64108766
[35,] -2.3372444  0.82613430
[36,]  0.8502499 -1.00792159
[37,] -2.2345466  0.82066375
[38,] -1.5448241 -1.09137696
[39,] -1.5240789 -1.09859441
[40,] -0.9531570 -1.03622858
[41,] -1.5390238 -0.97955110
[42,] -0.3954420  1.06347393
[43,]  1.7663255 -0.68403035
[44,]  3.6675512  0.74407761
[45,] -2.3030118  0.82431078
[46,] -2.2565347  0.84122491
[47,] -2.1785853  0.93145542
[48,]  3.4682572  0.59289220
[49,]  2.7986554  0.09437647
# dimension reduction PC1 = mypca$x[, 1] PC2 = mypca$x[, 2] # k-means clustering myclust <- kmeans(mypca$x[, 1:2], centers = 3, nstart = 10) myclust$cluster 
       
 [1] 2 3 3 1 2 1 3 3 1 3 3 1 3 2 2 3 2 1 3 2 1 2 3 1 2 3 3 2 1 1 3 2 1 1
1 2 1 2 2 2 2 1 3 3 1 1 1 3
[49] 3
 [1] 2 3 3 1 2 1 3 3 1 3 3 1 3 2 2 3 2 1 3 2 1 2 3 1 2 3 3 2 1 1 3 2 1 1 1 2 1 2 2 2 2 1 3 3 1 1 1 3
[49] 3
# visualization plot(PC1, PC2, xlab = "PC 1", ylab = "PC 2", type="p", col = myclust$cluster) text(PC1, PC2, labels = 1:49, pos=2, cex=0.8) dev.off() 
       
null device 
          1 
null device 
          1 
# biplot biplot(mypca) dev.off() 
       
null device 
          1 
null device 
          1