I am a novice at this. I wanted to create a correlation matrix using corrplot and used the following code:
cor.mtest <- function(mat, ...) {
mat <- as.matrix(mat)
n <- ncol(mat)
p.mat<- matrix(NA, n, n)
diag(p.mat) <- 0
for (i in 1:(n - 1)) {
for (j in (i + 1):n) {
tmp <- cor.test(mat[, i], mat[, j], ...)
p.mat[i, j] <- p.mat[j, i] <- tmp$p.value
}
}
colnames(p.mat) <- rownames(p.mat) <- colnames(mat)
p.mat
}
p.mat<-cor.mtest(dataset)
corrplot(cor(dataset, use="complete.obs"), type="upper", order="hclust",
p.mat=p.mat, sig.level=0.1)
It's one I used before, but this time around I got an error message:
Error in corrplot(cor(dataset, use = "complete.obs"), type = "upper", :
unused arguments (type = "upper", order = "hclust", p.mat = p.mat, sig.level = 0.01)
Any idea why that is and how I can fix it?
mtcarsfordatasetthen it runs as expected and I cannot reproduce the error. ps the answer here shows an approach with less code (but extra package) to get the pvalues. - user20650