rcorr gives error where cor works perfectly (need p-values for correlation matrix)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



rcorr gives error where cor works perfectly (need p-values for correlation matrix)



I need to get p-values for my correlation matrix that I created using cor. Strangely when I use rcorron the same data I get the following error:


cor


rcorr


Error in storage.mode(x) <- "double" :
(list) object cannot be coerced to type 'double'



Any suggestions?



below is my code for creating the correlation matrix(that gives error):


library(Hmisc)

corr < rcffull[,c("liwc_WC","liwc_informal","liwc_male",
"liwc_female","liwccsr_csrdic","liwc_negemo",
"liwc_posemo","liwc_risk")]
rcorr(corr)



this one is the one that works, but I don't get p-values:


cor(corr, use="complete.obs")





Is this Hmisc::rcorr? Please include the library() call when you're asking about something that's not in base R.
– Marius
Aug 13 at 5:53


Hmisc::rcorr


library()




1 Answer
1



Hmisc::rcorr expects the input to be a matrix and will not automatically convert dataframes, even when they are all numeric. So you should just be able to call as.matrix() on your input, e.g.


Hmisc::rcorr


matrix


as.matrix()


x <- c(-2, -1, 0, 1, 2)
y <- c(4, 1, 0, 1, 4)
z <- c(1, 2, 3, 4, NA)
v <- c(1, 2, 3, 4, 5)

df = data.frame(x, y, z, v)

# Fails with the same error as in the question
Hmisc::rcorr(df)
# Succeeds
Hmisc::rcorr(as.matrix(df))






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered