1

I would like to get variables from a specific component (COMP 2) :

> pca$eig
         eigenvalue percentage of variance cumulative percentage of variance
comp 1 3.8167747447           47.709684309                          47.70968
comp 2 2.0680904354           25.851130442                          73.56081
comp 3 0.9728158313           12.160197892                          85.72101
comp 4 0.7962420036            9.953025045                          95.67404
comp 5 0.1792036107            2.240045134                          97.91408
comp 6 0.0924269941            1.155337427                          99.06942
comp 7 0.0740850743            0.926063429                          99.99548
comp 8 0.0003613058            0.004516322                         100.00000

Is there's any command in R I can use to do this?

3
  • 3
    which PCA package are you using? Commented Mar 4, 2021 at 19:45
  • @Waldi thank you for your comment, I use FactoMineR and factoextra Commented Mar 4, 2021 at 19:49
  • What about factorextra::get_pca_var() Commented Mar 4, 2021 at 19:51

2 Answers 2

2

With factoextra, you get all components with get_pca_var:

library(FactoMineR)
library(factoextra)

pca <- FactoMineR::PCA(iris[,1:4])

pca.var <- factoextra::get_pca_var(pca)

pca.var$coord

                  Dim.1      Dim.2       Dim.3       Dim.4
Sepal.Length  0.8901688 0.36082989 -0.27565767 -0.03760602
Sepal.Width  -0.4601427 0.88271627  0.09361987  0.01777631
Petal.Length  0.9915552 0.02341519  0.05444699  0.11534978
Petal.Width   0.9649790 0.06399985  0.24298265 -0.07535950

Coordinates of second dimension are:

pca.var$coord[,"Dim.2"]
Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
  0.36082989   0.88271627   0.02341519   0.06399985  
Sign up to request clarification or add additional context in comments.

Comments

1

You can select an specific PC component using prcomp and the index:

library(fastDummies)
table <- data.frame(NOM = c("Evian", "Montagne des Pyrenees", "Cristaline-St-Cyr", 
                                "Fiee des Lois", "Volcania", "Saint Diery"), 
                        ACRO = c("EVIAN", "MTPYR", "CRIST", "FIEE", "VOLCA", "STDIE"), 
                        PAYS = c("F", "F","F", "F", "F", "F"), 
                        TYPE = c("M", "S", "S", "S", "S", "M"), 
                        PG = c("P", "P", "P", "P", "P", "G"), 
                        CA = c(78, 48, 71, 89, 4.1, 85), 
                        MG = c(24, 11, 5.5, 31, 1.7, 80), 
                        `NA` = c(5,34, 11.2, 17, 2.7, 385), 
                        K = c(1, 1, 3.2, 2, 0.9, 65), 
                        SUL = c(10,16, 5, 47, 1.1, 25), 
                        NO3 = c(3.8, 4, 1, 0, 0.8, 1.9), 
                        HCO3 = c(357,183, 250, 360, 25.8, 1350), 
                        CL = c(4.5, 50, 20, 28, 0.9,285), 
                        MOY = c(60.41, 43.38, 45.86, 71.75, 4.75, 284.61),
                    stringsAsFactors = TRUE)

table_conv <- dummy_cols(table,
                         select_columns = c("NOM","ACRO","PAYS","TYPE","PG"),
                         remove_selected_columns = TRUE)

pca <- prcomp(as.matrix(table_conv))

pca$x[,"PC4"]

I used your previous question as a guide for the dataset. This is your PC2 Eigenvectors:

pca$rotation[,"PC2"]
> pca$rotation[,"PC2"]
                       CA                        MG                       NA. 
             0.4583258631              0.0567007399             -0.6581371706 
                        K                       SUL                       NO3 
            -0.1004287315              0.1358452663             -0.0009273267 
                     HCO3                        CL                       MOY 
             0.3046381925             -0.4804253636             -0.0355753827 
    NOM_Cristaline-St-Cyr                 NOM_Evian         NOM_Fiee des Lois 
             0.0010557813              0.0044191573              0.0038456894 
NOM_Montagne des Pyrenees           NOM_Saint Diery              NOM_Volcania 
            -0.0029622537             -0.0016729014             -0.0046854729 
               ACRO_CRIST                ACRO_EVIAN                 ACRO_FIEE 
             0.0010557813              0.0044191573              0.0038456894 
               ACRO_MTPYR                ACRO_STDIE                ACRO_VOLCA 
            -0.0029622537             -0.0016729014             -0.0046854729 
                   PAYS_F                    TYPE_M                    TYPE_S 
             0.0000000000              0.0027462560             -0.0027462560 
                     PG_G                      PG_P 
            -0.0016729014              0.0016729014

4 Comments

Thank you, but why get_pca_var mentioned in the answer above, gives me a different result
Mmmm, I guess it's because the iris dataset was used. I used the dataset you posted before.
Yeah, I use my data instead of the iris, and it's given me a different result, in fact, the question said : What are the variables that the second component opposes?
I made an edit, since you want the eigenvectors, for the second component. Please, could you edit your question and see it against the dataset I proposed? If not, we can use the classic Iris dataset.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.