简体   繁体   中英

Apply a pairwise function on the columns of a matrix in R

I would like to apply some pairwise correlation estimator on all the columns of large matrix. Since I am working with large dimensions, I am looking for a function that might be of help here. I have been experimenting with the apply function but I have not gotten very far so all help is greatly appreciated.

require(ccaPP)
require(mvtnorm)
d<- 10
Sigma <- matrix(0.2, nrow = d, ncol = d)
diag(Sigma) <- 1
#Data generation
X <- rmvnorm(100, sigma = Sigma) # 100 x d matrix
Q <- apply(X, 2, FUN = corQuadrant, consistent = TRUE)

I apologise if this has been asked before but a search did not reveal something I can use. Thank you.

Nested for loops are one way:

require(ccaPP)
require(mvtnorm)
d<- 10
Sigma <- matrix(0.2, nrow = d, ncol = d)
diag(Sigma) <- 1
#Data generation
X <- rmvnorm(100, sigma = Sigma) # 100 x d matrix
Q <- matrix(nrow = d,ncol = d)
for (i in 1: (d-1)) { 
  for (j in (i+1):d) {
    Q[i,j] <- corQuadrant( X[,i], X[,j] ) 
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM