I know how to build a model using PCA components in caret package, however I don't know which variables explain which PCA components. I need some help on it.

When I perfom the preProcessing separately, like this:

trans<-preProcess(training_cl,method="pca",preProcOptions = list(thresh = 0.8))

I can check the PCA components of the data, like this:


However, when a perfome the PCA components using the caret package:

  1. I don't know which variables explain which PCA components(don't know how to access the $rotation).
  2. I don't get the same amount of PCA variables when compared with the code above(even when I define the same threshold).

example code using the caret:

fitControl <- trainControl(method = "cv",
                       number = 3,
                       preProcOptions = list(thresh = 0.80,pcaComp = NULL))
gbmGrid <-  expand.grid(interaction.depth = seq(3,5,10),
                    n.trees =  seq(100,130,10) ,
                    shrinkage = c(0.1),

gbmFit <- train(classe ~ .,method="gbm",
                tuneGrid = gbmGrid,
                 verbose = FALSE

How can I know which variables explain which PCA components when I use the caret package?


1 Answer 1


First, the "rotation" part can be accessed via:


The reason is because gbmFit$preProcess is a "preProcess" object just as trans is. Hence, you can access the "rotation" the same way.

As far as the discrepancy goes, I think it may be because it looks like you're passing in the whole training_cl data frame into the preProcess function and not excluding the classe column. Do you think that could be the problem?

  • $\begingroup$ Thank you! I forgot to exclude the classe from my data, I guess that this is why the differance happened. Now I wonder what will happening if I perfom the gbm with PCA in a data with NA. I know that gbm can handling with NA, however I don't know if PCA can handle this situation. My data has 72 features(observations), but 3 of them has missing values ( by definition some cases don't has values). I don't know if I can define a threshold in preProcOptions that don't apply pca to that 3 features. $\endgroup$ May 26, 2016 at 16:58

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.