cor.matrix | R Documentation |
This function computes a correlation matrix based on Pearson product-moment
correlation coefficient, Spearman's rank-order correlation coefficient,
Kendall's Tau-b correlation coefficient, Kendall-Stuart's Tau-c correlation
coefficient, tetrachoric correlation coefficient, or polychoric correlation
coefficient and computes significance values (p-values) for testing the
hypothesis H0: \rho
= 0 for all pairs of variables.
cor.matrix(..., data = NULL,
method = c("pearson", "spearman", "kendall-b", "kendall-c", "tetra", "poly"),
na.omit = FALSE, group = NULL, sig = FALSE, alpha = 0.05,
print = c("all", "cor", "n", "stat", "df", "p"),
tri = c("both", "lower", "upper"),
p.adj = c("none", "bonferroni", "holm", "hochberg", "hommel",
"BH", "BY", "fdr"), continuity = TRUE,
digits = 2, p.digits = 3, as.na = NULL,
write = NULL, append = TRUE, check = TRUE, output = TRUE)
... |
a matrix or data frame. Alternatively, an expression indicating
the variable names in |
data |
a data frame when specifying one or more variables in the
argument |
method |
a character vector indicating which correlation coefficient
is to be computed, i.e. |
na.omit |
logical: if |
group |
either a character string indicating the variable name of
the grouping variable in |
sig |
logical: if |
alpha |
a numeric value between 0 and 1 indicating the significance
level at which correlation coefficients are printed boldface
when |
print |
a character string or character vector indicating which results
to show on the console, i.e. |
tri |
a character string indicating which triangular of the matrix
to show on the console, i.e., |
p.adj |
a character string indicating an adjustment method for multiple
testing based on |
continuity |
logical: if |
digits |
an integer value indicating the number of decimal places to be used for displaying correlation coefficients. |
p.digits |
an integer value indicating the number of decimal places to be used for displaying p-values. |
as.na |
a numeric vector indicating user-defined missing values,
i.e. these values are converted to |
write |
a character string naming a file for writing the output into
either a text file with file extension |
append |
logical: if |
check |
logical: if |
output |
logical: if |
Note that unlike the cor.test
function, this
function does not compute an exact p-value for Spearman's rank-order
correlation coefficient or Kendall's Tau-b correlation coefficient, but uses
the asymptotic t approximation.
Statistically significant correlation coefficients can be shown in boldface on
the console when specifying sig = TRUE
. However, this option is not supported
when using R Markdown, i.e., the argument sig
will switch to FALSE
.
Returns an object of class misty.object
, which is a list with following
entries:
call |
function call |
type |
type of analysis |
data |
data frame used for the current analysis |
args |
specification of function arguments |
result |
list with result tables, i.e., |
This function uses the polychoric()
function in the psych
package by William Revelle to estimate tetrachoric and polychoric correlation
coefficients.
Takuya Yanagida takuya.yanagida@univie.ac.at
Rasch, D., Kubinger, K. D., & Yanagida, T. (2011). Statistics in psychology - Using R and SPSS. John Wiley & Sons.
Revelle, W. (2018) psych: Procedures for personality and psychological research. Northwestern University, Evanston, Illinois, USA, https://CRAN.R-project.org/package=psych Version = 1.8.12.
write.result
, cohens.d
, effsize
,
multilevel.icc
, na.auxiliary
, size.cor
.
# Example 1a: Pearson product-moment correlation coefficient between 'Ozone' and 'Solar.R#
cor.matrix(airquality[, c("Ozone", "Solar.R")])
# Example 1b: Alternative specification using the 'data' argument
cor.matrix(Ozone, Solar.R, data = airquality)
# Example 2a: Pearson product-moment correlation matrix using pairwise deletion
cor.matrix(airquality[, c("Ozone", "Solar.R", "Wind")])
# Example 2b: Alternative specification using the 'data' argument
cor.matrix(Ozone:Wind, data = airquality)
# Example 3: Spearman's rank-order correlation matrix
cor.matrix(airquality[, c("Ozone", "Solar.R", "Wind")], method = "spearman")
# Example 4: Pearson product-moment correlation matrix
# highlight statistically significant result at alpha = 0.05
cor.matrix(airquality[, c("Ozone", "Solar.R", "Wind")], sig = TRUE)
# Example 5: Pearson product-moment correlation matrix
# highlight statistically significant result at alpha = 0.05
cor.matrix(airquality[, c("Ozone", "Solar.R", "Wind")], sig = TRUE, alpha = 0.10)
# Example 6: Pearson product-moment correlation matrix
# print sample size and significance values
cor.matrix(airquality[, c("Ozone", "Solar.R", "Wind")], print = "all")
# Example 7: Pearson product-moment correlation matrix using listwise deletion,
# print sample size and significance values
cor.matrix(airquality[, c("Ozone", "Solar.R", "Wind")], na.omit = TRUE, print = "all")
# Example 8: Pearson product-moment correlation matrix
# print sample size and significance values with Bonferroni correction
cor.matrix(airquality[, c("Ozone", "Solar.R", "Wind")], na.omit = TRUE,
print = "all", p.adj = "bonferroni")
# Example 9a: Pearson product-moment correlation matrix for 'mpg', 'cyl', and 'disp'
# results for group "0" and "1" separately
cor.matrix(mtcars[, c("mpg", "cyl", "disp")], group = mtcars$vs)
# Example 9b: Alternative specification using the 'data' argument
cor.matrix(mpg:disp, data = mtcars, group = "vs")
## Not run:
# Example 10a: Write results into a text file
cor.matrix(airquality[, c("Ozone", "Solar.R", "Wind")], print = "all", write = "Correlation.txt")
# Example 10b: Write results into an Excel file
cor.matrix(airquality[, c("Ozone", "Solar.R", "Wind")], print = "all", write = "Correlation.xlsx")
result <- cor.matrix(airquality[, c("Ozone", "Solar.R", "Wind")], print = "all", output = FALSE)
write.result(result, "Correlation.xlsx")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.