Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thresh = 1 always retains only 2 components with preProcess(method = "pca") #825

Closed
paljenczy opened this issue Feb 3, 2018 · 1 comment
Closed

Comments

@paljenczy
Copy link

@paljenczy paljenczy commented Feb 3, 2018

With a high enough (but not 1) threshold argument thresh, PCA retains all principal components as expected:

library(caret)
#> Loading required package: lattice
#> Loading required package: ggplot2
preProcess(mtcars, method = "pca", thresh = 0.999)
#> Created from 32 samples and 11 variables
#>
#> Pre-processing:
#>   - centered (11)
#>   - ignored (0)
#>   - principal component signal extraction (11)
#>   - scaled (11)
#>
#> PCA needed 11 components to capture 99.9 percent of the variance

However, setting thresh = 1 retains only 2 principal components.

library(caret)
#> Loading required package: lattice
#> Loading required package: ggplot2
preProcess(mtcars, method = "pca", thresh = 1)
#> Created from 32 samples and 11 variables
#>
#> Pre-processing:
#>   - centered (11)
#>   - ignored (0)
#>   - principal component signal extraction (11)
#>   - scaled (11)
#>
#> PCA needed 2 components to capture 100 percent of the variance

sessionInfo()

> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-apple-darwin16.7.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] caret_6.0-78    ggplot2_2.2.1   lattice_0.20-35

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.3   purrr_0.2.4        reshape2_1.4.3    
 [4] kernlab_0.9-25     splines_3.4.3      colorspace_1.3-2  
 [7] stats4_3.4.3       yaml_2.1.16        survival_2.41-3   
[10] prodlim_1.6.1      rlang_0.1.6        ModelMetrics_1.1.0
[13] pillar_1.0.1       withr_2.1.1        foreign_0.8-69    
[16] glue_1.2.0         bindrcpp_0.2       foreach_1.4.4     
[19] bindr_0.1          plyr_1.8.4         dimRed_0.1.0      
[22] lava_1.5.1         robustbase_0.92-8  stringr_1.2.0     
[25] timeDate_3042.101  munsell_0.4.3      gtable_0.2.0      
[28] recipes_0.1.1      codetools_0.2-15   psych_1.7.8       
[31] parallel_3.4.3     class_7.3-14       DEoptimR_1.0-8    
[34] broom_0.4.3        Rcpp_0.12.14       scales_0.5.0      
[37] ipred_0.9-6        CVST_0.2-1         mnormt_1.5-5      
[40] stringi_1.1.6      dplyr_0.7.4        RcppRoll_0.2.2    
[43] ddalpha_1.3.1      grid_3.4.3         tools_3.4.3       
[46] magrittr_1.5       lazyeval_0.2.1     tibble_1.4.1      
[49] tidyr_0.7.2        DRR_0.0.2          pkgconfig_2.0.1   
[52] MASS_7.3-48        Matrix_1.2-12      lubridate_1.7.1   
[55] gower_0.1.2        assertthat_0.2.0   iterators_1.0.9   
[58] R6_2.2.2           rpart_4.1-11       sfsmisc_1.1-1     
[61] nnet_7.3-12        nlme_3.1-131       compiler_3.4.3  
topepo added a commit that referenced this issue Feb 5, 2018
topepo added a commit that referenced this issue Feb 5, 2018
@topepo
Copy link
Owner

@topepo topepo commented Feb 5, 2018

Found it. Should be fixed. Thanks

@topepo topepo closed this Feb 5, 2018
@topepo topepo reopened this Feb 5, 2018
@topepo topepo closed this Feb 7, 2018
topepo added a commit that referenced this issue Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.