correlation_matrix function

correlation matrix

correlation matrix

Creates a correlation matrix

correlation_matrix( data = NULL, var_names = NULL, row_var_names = NULL, col_var_names = NULL, round_r = 2, round_p = 3, output_type = "rp", numbered_cols = NULL )

Arguments

  • data: a data object (a data frame or a data.table)
  • var_names: names of the variables for which to calculate all pairwise correlations
  • row_var_names: names of the variables that will go on the rows of the correlation matrix
  • col_var_names: names of the variables that will go on the columns of the correlation matrix
  • round_r: number of decimal places to which to round correlation coefficients (default = 2)
  • round_p: number of decimal places to which to round p-values (default = 3)
  • output_type: which value should be filled in cells of the correlation matrix? If output_type = "r", correlation coefficients; if output_type = "p", p-values; if output_type = "rp", correlation coefficients with significance symbols based on p-values; if output_type = "n", sizes of the samples used to calculate the correlation coefficients. By default, output_type = "rp"
  • numbered_cols: logical. If numbered_cols == TRUE and if identical(row_var_names, col_var_names) == TRUE, then the columns will be numbered instead of containing variable names.

Returns

the output will be a correlation matrix in a data.table format

Examples

correlation_matrix(data = mtcars, var_names = c("mpg", "cyl", "wt")) correlation_matrix(data = mtcars, row_var_names = c("mpg", "cyl", "hp"), col_var_names = c("wt", "am")) correlation_matrix( data = mtcars, var_names = c("mpg", "cyl", "wt"), numbered_cols = FALSE) correlation_matrix( data = mtcars, var_names = c("mpg", "cyl", "wt"), output_type = "r")