| 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
two-sided hypothesis H0: \rho = 0 for all pairs of variables. Statistically
significant correlations can be highlighted by specifying the argument color.
cor.matrix(data, ...,
method = c("pearson", "spearman", "kendall-b", "kendall-c", "tetra", "poly"),
group = NULL, exact = FALSE, continuity = TRUE, ml = FALSE,
print = c("all", "cor", "n", "stat", "df", "p"),
tri = c("both", "lower", "upper"), alpha = 0.05,
color = "default", style = c("regular", "bold", "italic"),
p.adj = c("none", "bonferroni", "holm", "hochberg", "hommel",
"BH", "BY", "fdr"),
na.omit = FALSE, digits = 2, p.digits = 3, as.na = NULL,
write = NULL, append = TRUE, check = TRUE, output = TRUE)
data |
a data frame with numeric variables, i.e., factors and character
variables are excluded from |
... |
an expression indicating the variable names in |
method |
a character vector indicating which correlation coefficient
is to be computed, i.e. |
group |
either a character string indicating the variable name of
the grouping variable in |
exact |
logical: if |
continuity |
logical: if |
ml |
logical: if |
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., |
alpha |
a numeric value between 0 and 1 indicating the significance
level at which correlation coefficients are are highlighted when
specifying the argument |
color |
a character string indicating the text color for highlighting
statistically significant correlation coefficients , i.e.,
|
style |
a character vector indicating the font style for
statistically significant correlation coefficients, i.e.,
|
p.adj |
a character string indicating an adjustment method for multiple
testing based on |
na.omit |
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 |
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 a modified copy of the polychor() function in the
polycor package by John Fox when requesting tetrachoric or 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.cor, multilevel.icc, na.auxiliary
## Not run:
#————————————————————————————————————————————————————————————————————————————
# Pearson Product-Moment Correlation Coefficient
# Example 1a: Pearson product-moment correlation matrix using pairwise deletion
cor.matrix(airquality, Ozone:Wind)
# Example 1b: Alternative specification without using the '...' argument
cor.matrix(airquality[, c("Ozone", "Solar.R", "Wind")])
# Example 2a: Highlight statistically significant result in bright red
cor.matrix(airquality, Ozone, Solar.R, Wind, color = "b.red")
# Example 2b: Highlight statistically significant result in boldface
cor.matrix(airquality, Ozone, Solar.R, Wind, color = "black", style = "bold")
# Example 3a: Print sample size, degrees of freedom, and significance values
cor.matrix(airquality, Ozone, Solar.R, Wind, print = "all")
# Example 3b: Listwise deletion
cor.matrix(airquality, Ozone, Solar.R, Wind, na.omit = TRUE)
# Example 3c: Significance values with Bonferroni correction
cor.matrix(airquality, Ozone, Solar.R, Wind, print = "all", p.adj = "bonferroni")
#————————————————————————————————————————————————————————————————————————————
# Spearman's Rank-Order Correlation Coefficient and Kendall's Tau
# Example 4a: Spearman's rank-order correlation matrix
cor.matrix(airquality, Ozone, Solar.R, Wind, method = "spearman")
# Example 4b: Kendall's Tau-c
cor.matrix(airquality, Ozone, Solar.R, Wind, method = "kendall-c")
#————————————————————————————————————————————————————————————————————————————
# Tetrachoric and Polychoric Correlation Coefficient
# Example 5a: Tetrachoric correlation matrix
cor.matrix(data.items, +ditem, method = "tetra")
# Example 5b: Polychoric correlation matrix
cor.matrix(data.items, +pitem, method = "poly")
#————————————————————————————————————————————————————————————————————————————
# Grouping Variable
# Example 6a: Results for group 'vs' = "0" and "1" separately
cor.matrix(mtcars, mpg:disp, group = "vs")
# Example 6b: Alternative specification without using the '...' argument
cor.matrix(mtcars[, c("mpg", "cyl", "disp")], group = mtcars$vs)
#————————————————————————————————————————————————————————————————————————————
# Write Results
# Example 7a: Write Results into a text file
cor.matrix(airquality, Ozone, Solar.R, Wind, print = "all", write = "Correlation.txt")
# Example 7b: Write Results into an Excel file
cor.matrix(airquality, Ozone, Solar.R, Wind, print = "all", write = "Correlation.xlsx")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.