2

When I need to speed up the cor(..., method="kendall"), I found Fast correlation in R using C and parallelization. This can easily speed up the pearson correlation calculation by cor() in R.

But the kendall is actually the slower one. Then the fast alternative can be cor.fk (x, y = NULL), which is way faster than the cor(..., method="kendall").

Xiaorui Zhu
  • 161
  • 7

1 Answers1

0

When bootstrap or very large matrix are involved, a very fast alternative can be cor.fk (x, y = NULL).

It can be used as follows:

library(PAsso)
# import data -------------------------------------------------------------
data(ANES2016)
summary(ANES2016)

system.time(
  cor_matrix <- cor(ANES2016[, c("Prevote.num","PID")], method = "pearson")
)
# user  system elapsed 
#   0       0       0 

system.time(
  cor_matrix <- cor(ANES2016[, c("PreVote.num","PID")], method = "kendall")
)
# user  system elapsed 
# 0.19    0.00    0.19 

library(pcaPP)
system.time(
  cor.fk(ANES2016[, c("PreVote.num","PID")])
)

# user  system elapsed 
#   0       0       0 
Xiaorui Zhu
  • 161
  • 7