Skip to content

A correlation matrix with stars and the option to mix Pearson and Spearman correlations in R

License

Notifications You must be signed in to change notification settings

karl-an/corstars_ordinal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

corstars_ordinal

A correlation matrix with asterisks and the option to mix Pearson and Spearman correlations in R

corstars is an R function that computes a correlation matrix for a given dataset, supporting both Pearson and Spearman correlations. Specific indices can be used to denote different correlation methods.

Usage

corstars(x, ordinal_vars=NULL, removeTriangle=c("upper", "lower"),
         result=c("none", "html", "latex"), indecies=c(pearson="", spearman="(s)"))

Parameters

  • x: Your data matrix.
  • ordinal_vars: Vector of column indices for ordinal variables that require Spearman correlation.
  • removeTriangle: Specifies whether to remove the upper or lower triangle of the correlation matrix. Options include "upper" or "lower".
  • result: Specifies the output format. Options include "none", "html", and "latex". "none" returns the result as a data frame, whereas "html" and "latex" print the result in the corresponding formats.
  • indecies: Named list containing specific indices for Pearson and Spearman correlations, e.g. c(pearson="", spearman="(s)").

Example

Here's an example of how to use the function with a dataset that contains both continuous and ordinal variables:

# Simulate some data with multiple continuous and ordinal variables
set.seed(123)
data <- data.frame(
  continuous_var1 = rnorm(100),
  continuous_var2 = rnorm(100),
  continuous_var3 = rnorm(100),
  ordinal_var1 = sample(1:5, 100, replace = TRUE),
  ordinal_var2 = sample(1:5, 100, replace = TRUE)
)

# Use the corstars function, specifying that the fourth and fifth columns are ordinal
result <- corstars(data, ordinal_vars = c(4, 5), removeTriangle = "upper", result = "none")

# Print the result
print(result)

About

A correlation matrix with stars and the option to mix Pearson and Spearman correlations in R

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages