Search code examples
rpca

How to save PCA summary?


I have used prcomp function to perform PCA of my data. I can save other data like, center, scale, score, rotation in csv using write.csv function but I don't know how to save PCA summary.

Data I used

structure(list(Location = c("Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", 
"Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", 
"Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", 
"Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay", 
"Luoyuan Bay", "Luoyuan Bay", "Luoyuan Bay"), Serial = 32:52, 
    Station = c("NDDZ91", "NDDZ92", "NDDZ94", "NDDZ95", "NDDZ96", 
    "NDDZ97", "NDDZ98", "NDDZ99", "NDDZ103", "NDDZ105", "NDDZ106", 
    "NDDZ107", "NDDZ112", "NDDZ113", "NDDZ114", "NDDZ115", "NDDZ116", 
    "NDDZ117", "NDDZ119", "NDDZ122", "NDDZ123"), Longitude = c(119.6875, 
    119.6641667, 119.7163889, 119.7425, 119.69, 119.7719444, 
    119.6622222, 119.7544444, 119.6644444, 119.6875, 119.7369444, 
    119.7672222, 119.6583333, 119.6327778, 119.5991667, 119.6769444, 
    119.7019444, 119.7419444, 119.6216667, 119.6722222, 119.6408333
    ), Latitude = c(26.34944444, 26.35972222, 26.36, 26.36027778, 
    26.37583333, 26.38277778, 26.38638889, 26.39277778, 26.41055556, 
    26.41972222, 26.42833333, 26.42861111, 26.43361111, 26.44416667, 
    26.45, 26.45, 26.44805556, 26.44805556, 26.46638889, 26.47166667, 
    26.4775), Petrolium = c(20.26723856, 35.12860786, 38.00639611, 
    485.9158071, 6.801285888, 130.2613429, 26.41691724, 21.47363409, 
    75.24255785, 9.088017875, 17.83869051, 106.4365614, 367.7372615, 
    26.95847112, 42.01753212, 17.56582294, 72.00256098, 382.5705508, 
    150.0004825, 452.8679126, 61.51137016), Sulfide = c(15.16, 
    47.67, 30.23, 75.05, 10.51, 38.75, 21.64, 35.97, 122.53, 
    6.95, 58.52, 75.92, 92.23, 10.85, 72.1, 28.46, 81.19, 195.59, 
    42.54, 277.4, 81.67), PAH = c(0.0479, 0.0638, 0.1312, 0.1293, 
    0.0589, 0.1032, 0.2725, 0.0712, 0.1173, 0.0703, 0.2097, 0.1261, 
    0.0685, 0.0796, 0.1353, 0.0354, 0.0323, 0.034, 0.0269, 0.0952, 
    0.0269), OCP = c(0.01071845, 0, 0, 0, 0, 0.004247812, 0, 
    0, 0, 0.002020821, 0, 0.055799207, 0.003690873, 0.019063717, 
    0, 0.173323781, 0.010429405, 0, 0, 0.013486877, 0), PES = c(0, 
    44.15139004, 17.922209, 35.47228577, 0, 66.9289217, 11.62692114, 
    30.51552678, 57.2039725, 35.11363161, 49.43776022, 83.9088046, 
    0, 0, 45.56461801, 0, 0, 8.461490717, 29.69151766, 76.46222766, 
    34.05399385), Acrylic = c(0, 0, 0, 0, 0, 0, 0, 30.51552678, 
    0, 0, 0, 41.9544023, 0, 0, 0, 0, 0, 0, 0, 0, 0), PP = c(0, 
    0, 0, 0, 5.263920851, 0, 0, 0, 0, 0, 49.43776022, 0, 186.2662335, 
    248.4375, 0, 0, 0, 4.230745359, 0, 0, 0), Rayon = c(74.23500995, 
    58.86852005, 53.766627, 70.94457153, 26.31960425, 0, 69.76152682, 
    61.03105356, 114.407945, 70.22726323, 49.43776022, 41.9544023, 
    0, 0, 136.693854, 112.339267, 36.33232944, 16.92298143, 59.38303531, 
    305.8489106, 102.1619815)), class = "data.frame", row.names = c(NA, 
-21L))

CODE I used for PCA

Mydata = read.csv("PCA_Luoyuan.csv")
head(Mydata)
pca = prcomp(Mydata[,6:13], scale. = TRUE)
summary(pca)

Solution

  • You can extract importance from summary(pca).

    write.csv(summary(pca)$importance, 'temp.csv')