Consider, i have two matrices, one with response, one with predictor variables, and i calculate distance matrices for each of those variables:
resp <- as.data.frame(matrix(rnorm(6*6,mean=1000,sd=100), 6, 6)) pred <- as.data.frame(matrix(rnorm(6*6,mean=1000,sd=100), 6, 6)) colnames(resp) <- paste("Resp_",letters[1:6],sep="") colnames(pred) <- paste("Pred_",LETTERS[1:6],sep="") #calculate distance matrices for each variable per site Z <- lapply(resp, function(x) dist(x)) A <- lapply(pred, function(x) dist(x)) I want to perform mantel statistics for every pair of matrices between A and Z:
library(vegan) res1 <- mantel(Z[[1]], A[[1]], method="spearman", perm=999) res2 <- mantel(Z[[2]], A[[1]], method="spearman", perm=999) or broadly put
res(i,j) <- mantel(Z[[1:i]], A[[1:j]], method="spearman", perm=999) I am interested in retrieving the r and p-values as in res1[[3]] and res1[[4]], possibly in a matrix, just like
cor(resp, pred) How can i do this in a loop?
Thank you!