rcorr problem of Hmisc package
1
0
Entering edit mode
yueli7 ▴ 20
@yueli7-8401
Last seen 2.9 years ago
China

Hello,

 

I try to calculate the correlation of P value of two matrix.

Thanks in advance!

 

 

 

> library("Hmisc")
> x<-as.matrix(read.table("tmp01"))
> x
     V1 V2 V3 V4 V5
[1,]  1  2  3  4  5
[2,]  4  1  6  5  1
[3,]  3  5  5  2  2
[4,]  1  2  3  4  5
[5,]  4  1  6  5  1
> y<-as.matrix(read.table("tmp02"))
> y
     V1 V2 V3 V4 V5
[1,]  7  8  9  6  6
[2,] 10  1 12  8  8
[3,]  7  8  9  6  6
[4,] 10  1 12  8  8
[5,]  7  8  9  6  6
> P<-matrix(0,nrow(x),nrow(y))
> for (i in 1:nrow(x)){
+ for(j in 1:nrow(y)){
+ P[i,j]<-rcorr(x[i,],y[j,])}}
Error in P[i, j] <- rcorr(x[i, ], y[j, ]) :
  number of items to replace is not a multiple of replacement length

 

 

> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.4 LTS

Matrix products: default
BLAS: /usr/local/lib/R/lib/libRblas.so
LAPACK: /usr/local/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] Hmisc_4.1-1     ggplot2_2.2.1   Formula_1.2-3   survival_2.41-3
[5] lattice_0.20-35

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.16        pillar_1.2.2        compiler_3.5.0     
 [4] RColorBrewer_1.1-2  plyr_1.8.4          base64enc_0.1-3    
 [7] tools_3.5.0         rpart_4.1-13        digest_0.6.15      
[10] tibble_1.4.2        gtable_0.2.0        htmlTable_1.11.2   
[13] checkmate_1.8.5     rlang_0.2.0         Matrix_1.2-14      
[16] rstudioapi_0.7      gridExtra_2.3       stringr_1.3.0      
[19] cluster_2.0.7-1     knitr_1.20          htmlwidgets_1.2    
[22] grid_3.5.0          nnet_7.3-12         data.table_1.11.0  
[25] tcltk_3.5.0         foreign_0.8-70      latticeExtra_0.6-28
[28] magrittr_1.5        scales_0.5.0        backports_1.1.2    
[31] htmltools_0.3.6     splines_3.5.0       colorspace_1.3-2   
[34] stringi_1.2.2       acepack_1.4.1       lazyeval_0.2.1   

hmisc software error • 1.3k views
ADD COMMENT
0
Entering edit mode
shepherl 3.8k
@lshep
Last seen 33 minutes ago
United States

The result of rcorr is not a single numeric value that can be placed into a matrix it is an object of rcorr class.

> vl <- rcorr(x[1, ], y[1, ])
> vl
      x     y
x  1.00 -0.49
y -0.49  1.00

n= 5 


P
  x      y     
x        0.4075
y 0.4075    

> class(vl)
[1] "rcorr"
ADD COMMENT

Login before adding your answer.

Traffic: 826 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6