Question: Error from pcaMethods and psych packages from biocLite("pcaMethods")
0
gravatar for allantanaka11
2.1 years ago by
allantanaka110 wrote:

I'm confused now because Running the following code gives me error: 

Train1=Train
Train1 <- subset(Train1, select = -c(Item_Fat_Content.LF,Item_Fat_Content.reg))
Train1=as.matrix(Train1)
outEM = PPCAEM(Train1, nComp=2, tol=0.00000000000001, maxit=100)#Probabilistic PCA
Xrecon = outEM$Xrecon
loadingsEM = outEM$loadings
scoresEM = outEM$scores
mean((Xrecon-Train1)^2)
prin_comp <- princomp(Train1, scale. = T,center = TRUE)#scale.=F, meaning that it will adjust if there's multicolinearity. But we have treated multicoll above (FULL RANK dummy)
scores_origpca = prin_comp$scores[,1:2]
loadings_origpca = prin_comp$loadings[,1:2]
Xrecon_origpca = scores_origpca%*%t(loadings_origpca)
outpcam = pca(Train1, nPcs=2, threshold=1e-8, method='ppca', scale='none', center=T)
loadings_pcam = loadings(outpcam)
scores_pcam = scores(outpcam)

 

This code: 

> scores_pcam = scores(outpcam)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘scores’ for signature ‘"psych"’

Note that i have installed psych and pcaMethods from biocLite("pcaMethods").

pcamethods • 422 views
ADD COMMENTlink modified 2.1 years ago by James W. MacDonald49k • written 2.1 years ago by allantanaka110

One of the reasons we always ask people to post the output from sessionInfo() is to ensure that they have all packages loaded that they are trying to use. Simply installing a package doesn't mean you had it loaded, which is one possible problem. Another possible problem is that you might have the wrong version of psych, which sessionInfo() would show as well.

ADD REPLYlink written 2.1 years ago by James W. MacDonald49k

Hi.

Here is sessionInfo() output that was wrote in RStudio:

> sessionInfo() 

attached base packages:
 [1] grid      parallel  splines   stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] psych_1.6.12        pracma_1.9.9        replyr_0.2.4        xts_0.9-7           zoo_1.7-14         
 [6] rsparkling_0.2.0    sparklyr_0.5.3-9002 SparseM_1.76        plyr_1.8.4          glmnet_2.0-5       
[11] vtreat_0.5.30       tidyr_0.6.1         dplyr_0.5.0.9000    dummies_1.5.6       sigr_0.1.4         
[16] WVPlots_0.2.3       stringr_1.2.0       rpart.plot_2.1.1    h2o_3.11.0.3815     randomForest_4.6-12
[21] doSNOW_1.0.14       snow_0.4-2          testthat_1.0.2      pcaMethods_1.66.0   Biobase_2.34.0     
[26] BiocGenerics_0.20.0 Matrix_1.2-7.1      MASS_7.3-45         jsonlite_1.3        rjson_0.2.15       
[31] rJava_0.9-8         R2jags_0.5-7        rjags_4-6           coda_0.19-1         reshape2_1.4.2     
[36] magrittr_1.5        doParallel_1.0.10   iterators_1.0.8     foreach_1.4.3       caTools_1.17.1     
[41] ROCR_1.0-7          gplots_3.0.1        pROC_1.9.1          robustbase_0.92-7   car_2.1-4          
[46] DMwR_0.4.1          mice_2.30           data.table_1.10.4   C50_0.1.0-24        adabag_4.1         
[51] caret_6.0-73        ggplot2_2.2.1       mlbench_2.1-1       rpart_4.1-10        xgboost_0.6-4      
[56] e1071_1.6-8         gbm_2.1.3           lattice_0.20-34     survival_2.39-5     mlr_2.11           
[61] ParamHelpers_1.10  

loaded via a namespace (and not attached):
 [1] minqa_1.2.4        colorspace_1.3-2   class_7.3-14       rprojroot_1.2      base64enc_0.1-3   
 [6] rstudioapi_0.6     MatrixModels_0.4-1 codetools_0.2-15   mnormt_1.5-5       Formula_1.2-1     
[11] nloptr_1.0.4       pbkrtest_0.4-7     shiny_1.0.0        httr_1.2.1         backports_1.0.5   
[16] assertthat_0.1     lazyeval_0.2.0     htmltools_0.3.5    quantreg_5.29      tools_3.3.2       
[21] partykit_1.1-1     gtable_0.2.0       glue_0.0.0.9000    Rcpp_0.12.10       parallelMap_1.3   
[26] gdata_2.17.0       nlme_3.1-128       lme4_1.1-12        mime_0.5           gtools_3.5.0      
[31] DEoptimR_1.0-8     scales_0.4.1       BBmisc_1.11        quantmod_0.4-7     gridExtra_2.2.1   
[36] stringi_1.1.2      checkmate_1.8.2    TTR_0.23-1         boot_1.3-18        rlang_0.0.0.9001  
[41] bitops_1.0-6       wrapr_0.1.1        R6_2.2.0           DBI_0.6            foreign_0.8-67    
[46] mgcv_1.8-15        abind_1.4-5        RCurl_1.95-4.8     nnet_7.3-12        tibble_1.2        
[51] crayon_1.3.2       KernSmooth_2.23-15 ModelMetrics_1.1.0 digest_0.6.12      xtable_1.8-2      
[56] httpuv_1.3.3       stats4_3.3.2       munsell_0.4.3      quadprog_1.5-5     R2WinBUGS_2.1-21  

ADD REPLYlink written 2.1 years ago by allantanaka110

please kindly let me know if anything :)

ADD REPLYlink written 2.1 years ago by allantanaka110
Answer: Error from pcaMethods and psych packages from biocLite("pcaMethods")
0
gravatar for James W. MacDonald
2.1 years ago by
United States
James W. MacDonald49k wrote:

This looks like a function clash, although I don't see a pca method in the psych package. Anyway, the safest way to run code when you might have a function clash is to specify the package and function using the :: operator. So if you do

outpcam <- pcaMethods::pca(Train1, nPcs = 2, threshold=1e-8, method='ppca', scale='none', center=T)

Then you are assured that you will be calling the right version of pca, which will return the correct object type.

ADD COMMENTlink written 2.1 years ago by James W. MacDonald49k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 132 users visited in the last hour