dat <- data.frame(group = c("a", "a", "a", "a", "a",
"b", "b", "b", "b", "b"),
x = c(5, NA, 6, 4, 6, 7, 9, 5, 8, 7),
y = c(3, 3, 5, 6, 7, 4, 7, NA, NA, 8),
z = c(1, 3, 1, NA, 2, 4, 6, 5, 9, 6))
# Pearson product-moment correlation coefficient
cor.matrix(dat[, c("x", "y")])
# Pearson product-moment correlation coefficient matrix using pairwise deletion
cor.matrix(dat[, c("x", "y", "z")])
# Spearman's rank-order correlation matrix using pairwise deletion
cor.matrix(dat[, c("x", "y", "z")], method = "spearman")
# Kendall's Tau-b correlation matrix using pairwise deletion
cor.matrix(dat[, c("x", "y", "z")], method = "kendall-b")
# Kendall-Stuart's Tau-c correlation matrix using pairwise deletion
cor.matrix(dat[, c("x", "y", "z")], method = "kendall-c")
# Pearson product-moment correlation coefficient matrix using pairwise deletion
# highlight statistically significant result at alpha = 0.05
cor.matrix(dat[, c("x", "y", "z")], sig = TRUE)
# Pearson product-moment correlation coefficient matrix using pairwise deletion
# highlight statistically significant result at alpha = 0.05
cor.matrix(dat[, c("x", "y", "z")], sig = TRUE, alpha = 0.10)
# Pearson product-moment correlation coefficient matrix using pairwise deletion,
# print sample size and significance values
cor.matrix(dat[, c("x", "y", "z")], print = "all")
# Pearson product-moment correlation coefficient matrix using listwise deletion,
# print sample size and significance values
cor.matrix(dat[, c("x", "y", "z")], na.omit = TRUE, print = "all")
# Pearson product-moment correlation coefficient matrix using listwise deletion,
# print sample size and significance values with Bonferroni correction
cor.matrix(dat[, c("x", "y", "z")], na.omit = TRUE, print = "all", p.adj = "bonferroni")
# Pearson product-moment correlation coefficient using pairwise deletion,
# results for group "a" and "b" separately
cor.matrix(dat[, c("x", "y")], group = dat$group)
# Pearson product-moment correlation coefficient matrix using pairwise deletion,
# results for group "a" and "b" separately
cor.matrix(dat[, c("x", "y", "z")], group = dat$group, print = "all")
if (FALSE) {
# Write Results into a Excel file
cor.matrix(dat[, c("x", "y", "z")], print = "all", write = "Correlation.xlsx")
result <- cor.matrix(dat[, c("x", "y", "z")], print = "all", output = FALSE)
write.result(result, "Correlation.xlsx")
}
Run the code above in your browser using DataLab