3

I'm trying to use corr.test from package psych (psych_1.6.9), but it seems to be giving different p values from cor.test while using method="spearman". Correlation coefficients are the same, but p values differ. I have put together some sample code and output and it is shown below.

library(psych)
set.seed(5)
df<-data.frame("S1"=runif(5, min=1, max=3), "S2"=runif(5, min=1, max=3), "S3"=runif(5, min=1, max=3), "S4"=runif(5, min=1, max=3), "S5"=runif(5, min=1, max=3))
rownames(df)<-c("A","B","C","D","E")
dfm<-as.matrix(df)
x1<-head(dfm,n=3)
x2<-tail(dfm,n=2)
a<-corr.test(t(x1),t(x2),method="spearman",ci=FALSE, adjust="none")
a$p
      D         E
A 1.0000000 0.8728886
B 0.2847570 0.1881204
C 0.8728886 0.6238377
cor.test(dfm["B",],dfm["D",], method="spearman", alternative="two.sided")

    Spearman's rank correlation rho

data:  dfm["B", ] and dfm["D", ]
S = 32, p-value = 0.35
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho 
-0.6 

a$r
     D    E
A  0.0  0.1
B -0.6 -0.7
C  0.1 -0.3

I must be doing something wrong but just can't see it. I would appreciate any help on this.

Agnieszka

Agnieszka G
  • 31
  • 1
  • 3

0 Answers0