knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7,
  fig.height = 5,
  warning = FALSE,
  message = FALSE
)

pkgs <- c("correlation", "ggplot2", "ggraph", "poorman")
successfully_loaded <- vapply(pkgs, requireNamespace, FUN.VALUE = logical(1L), quietly = TRUE)
can_evaluate <- all(successfully_loaded)

if (can_evaluate) {
  knitr::opts_chunk$set(eval = TRUE)
  vapply(pkgs, require, FUN.VALUE = logical(1L), quietly = TRUE, character.only = TRUE)
} else {
  knitr::opts_chunk$set(eval = FALSE)
}

This vignette can be referred to by citing the package:

citation("see")

Introduction

correlation is an easystats package focused on correlation analysis. It's lightweight, easy to use, and allows for the computation of many different types of correlation, including:

Pearson's correlation
Spearman's rank correlation
Kendall's rank correlation
Biweight midcorrelation
Distance correlation
Percentage bend correlation
Shepherd's Pi correlation
Blomqvist’s coefficient
Hoeffding’s D
Gamma correlation
Gaussian rank correlation
Point-Biserial and biserial correlation
Winsorized correlation
Polychoric correlation
Tetrachoric correlation
Multilevel correlation

An overview and description of these correlations types is available here. Moreover, many of these correlation types are available as partial or within a Bayesian framework.

Setup

library(correlation)
library(see)
library(ggplot2)

Correlation Scatterplot

(related function documentation)

It is easy to visualize correlation tests with correlation and see.

result <- cor_test(iris, "Sepal.Length", "Petal.Width")

plot(result)

We can even customize that to make it more beautiful:

plot(result,
  point = list(
    aes = list(color = "Petal.Width", size = "Sepal.Length"),
    alpha = 0.66
  ),
  smooth = list(color = "black", se = FALSE)
) +
  see::theme_modern() +
  see::scale_color_material_c(palette = "rainbow", guide = "none") +
  scale_size_continuous(guide = "none")

Correlation Matrix

(related function documentation)

The default output for correlation() is a detailed overview including test statistic, p-values and confidence intervals. A shorter summary in matrix-layout can be obtained by using summary().

result <- correlation(iris)

result

summary(result)

The result from summary() can be used to create a plot.

s <- summary(result)
plot(s)

To change the style of geoms, use the show_data-argument.

plot(s, show_data = "points")

And a "redundant" summary can be plotted as well:

s <- summary(result, redundant = TRUE)

s

plot(s)

The corrlation function also provides a convenient way to change names for selected variables:

plot(summary(correlation(
  data = mtcars[c("wt", "mpg", "drat")],
  rename = c("weight", "miles per gallon", "rear axle ratio")
)))

Gaussian Graphical Models (GGMs)

To create a Gaussian Graphical Models plot, the library ggraph needs to be loaded first.

library(ggraph)
result <- correlation(mtcars, partial = TRUE)

result

plot(result)


easystats/see documentation built on March 1, 2025, 3:54 p.m.