Title: Generalized Correlation and Related Measures
Version: 0.1.0
Depends: R (≥ 4.0.0)
Description: Generalized correlation and related measures for assessing nonlinear relationships between variables, including mixed-type data. For methodological background, see https://r-suzuki.github.io/gcor/method.html.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.3
URL: https://github.com/r-suzuki/gcor-r
BugReports: https://github.com/r-suzuki/gcor-r/issues
NeedsCompilation: no
Packaged: 2026-03-17 07:43:15 UTC; ryota
Author: Ryota Suzuki [aut, cre]
Maintainer: Ryota Suzuki <suzuki@ef-prime.com>
Repository: CRAN
Date/Publication: 2026-03-20 11:40:02 UTC

Estimate generalized correlation and related measures

Description

Estimate generalized correlation and related measures, which includes:

Usage

gcor(
  x,
  y = NULL,
  data = NULL,
  dropNA = "none",
  k = NULL,
  max_levels = 100,
  simplify = TRUE
)

dgcor(
  x,
  y = NULL,
  data = NULL,
  dropNA = "none",
  k = NULL,
  max_levels = 100,
  simplify = TRUE
)

gdis(x, dropNA = "none", k = NULL, max_levels = 100, ...)

Arguments

x

a vector, matrix, data frame or formula. If formula, data should be specified. gdis requires a matrix or data frame.

y

NULL (default) or a vector, matrix or data frame with compatible dimensions to x.

data

NULL (default) or a data frame. Required if x is a formula.

dropNA

a character specifying how to handle missing values. It should be one of the following:

"none"

(default) Treat missing values as observations of a single categorical value, namely NA. Recommended for reflecting missing patterns in the analysis.

"casewise"

Casewise deletion; rows containing any missing value are removed. Similar to use = "complete.obs" in cor.

"pairwise"

Pairwise deletion; for any pair of columns (x,y), the i-th row is removed if x[i] or y[i] is missing. This process is applied per pair; the same row is not removed with another pair (w,z), if both w[i] and z[i] are not missing. Similar to use = "pairwise.complete.obs" in cor.

k

NULL (default) or an integer specifying the number of groups for discretization. Numerical data are divided into k groups using k-quantiles. If NULL, it is determined automatically.

max_levels

an integer specifying the maximum number of levels allowed when converting non-numeric variables to factors.

simplify

a logical. If TRUE, the returned value is coerced to a vector when one of its dimensions is one.

...

additional arguments (diag and upper) passed to as.dist function. See as.dist for details.

Value

For gcor and dgcor, a numeric matrix is returned (or a vector if simplify = TRUE). For gdis, an object of class "dist" is returned.

References

Suzuki, R. (2026). Method Overview of gcor. https://r-suzuki.github.io/gcor/method.html

Examples

# Generalized correlation measure
gcor(iris)

# Dependency of Species on other variables
dgc <- dgcor(Species ~ ., data = iris)
dotchart(sort(dgc), main = "Dependency of Species")

# Clustering
gd <- gdis(iris)
hc <- hclust(gd, method = "ward.D2")
plot(hc)

# Multidimensional scaling
mds <- cmdscale(gd, k = 2)
plot(mds, type = "n", xlab = "", ylab = "", asp = 1, axes = FALSE,
     main = "cmdscale with gdis(iris)")
text(mds[,1], mds[,2], rownames(mds))