cor.table {petersenlab}R Documentation

Correlation Matrix.

Description

Function that creates a correlation matrix similar to SPSS output.

Usage

cor.table(x, y, type = "none", dig = 2, correlation = "pearson")

Arguments

x

Variable or set of variables in the form of a vector or dataframe to correlate with y (if y is specified) in an any asymmetric correlation matrix or with itself in a symmetric correlation matrix (if y is not specified).

y

(optional) Variable or set of variables in the form of a vector or dataframe to correlate with x.

type

Type of correlation matrix to print. One of:

  • "none" = correlation matrix with r, n, p-values

  • "latex" = generates latex code for correlation matrix with only r-values

  • "latexSPSS" = generates latex code for full SPSS-style correlation matrix

  • "manuscript" = only r-values, 2 digits; works with x only (cannot enter variables for y)

  • "manuscriptBig" = only r-values, 2 digits, no asterisks; works with x only (cannot enter variables for y)

  • "manuscriptLatex" = generates latex code for: only r-values, 2 digits; works with x only (cannot enter variables for y)

  • "manuscriptBigLatex" = generates latex code for: only r-values, 2 digits, no asterisks; works with x only (cannot enter variables for x)

dig

Number of decimals to print.

correlation

Method for calculating the association. One of:

  • "pearson" = Pearson product moment correlation coefficient

  • "spearman" = Spearman's rho

  • "kendall" = Kendall's tau

Details

Co-created by Angela Staples (astaples@emich.edu) and Isaac Petersen (isaac-t-petersen@uiowa.edu). For a partial correlation matrix, see partialcor.table.

Value

A correlation matrix.

See Also

Other correlations: addText(), crossTimeCorrelation(), crossTimeCorrelationDF(), partialcor.table(), vwReg()

Examples

# Prepare Data
data("mtcars")

# Correlation Matrix
cor.table(mtcars[,c("mpg","cyl","disp")])
cor.table(mtcars[,c("mpg","cyl","disp")])
cor.table(mtcars[,c("mpg","cyl","disp")], dig = 3)
cor.table(mtcars[,c("mpg","cyl","disp")], dig = 3, correlation = "spearman")

cor.table(mtcars[,c("mpg","cyl","disp")], type = "manuscript", dig = 3)
cor.table(mtcars[,c("mpg","cyl","disp")], type = "manuscriptBig")

table1 <- cor.table(mtcars[,c("mpg","cyl","disp")], type = "latex")
table2 <- cor.table(mtcars[,c("mpg","cyl","disp")], type = "latexSPSS")
table3 <- cor.table(mtcars[,c("mpg","cyl","disp")], type = "manuscriptLatex")
table4 <- cor.table(mtcars[,c("mpg","cyl","disp")], type = "manuscriptBigLatex")

cor.table(mtcars[,c("mpg","cyl","disp")], mtcars[,c("drat","qsec")])
cor.table(mtcars[,c("mpg","cyl","disp")], mtcars[,c("drat","qsec")], type = "manuscript", dig = 3)

[Package petersenlab version 1.0.0 Index]