association function

Measures of association

Measures of association

Function returns the matrix of measures of association for different types of variables.

association(x, y = NULL, use = c("na.or.complete", "complete.obs", "everything", "all.obs"), method = c("auto", "pearson", "spearman", "kendall", "cramer")) assoc(x, y = NULL, use = c("na.or.complete", "complete.obs", "everything", "all.obs"), method = c("auto", "pearson", "spearman", "kendall", "cramer"))

Arguments

  • x: Either data.frame or a matrix

  • y: The numerical variable.

  • use: What observations to use. See cor function for details. The only option that is not available here is "pairwise.complete.obs".

  • method: Which method to use for the calculation of measures of association. By default this is "auto", which means that the function will use: cor , mcor or cramer - depending on the scales of variables. The other options force the function to use one and the same method for all the variables:

    • "pearson" - Pearson's correlation coefficient using cor ;
    • "spearman" - Spearman's correlation coefficient based on cor ;
    • "kendall" - Kendall's correlation coefficient via cor ;
    • "cramer" - Cramer's V using cramer ;

    Be aware that the wrong usage of measures of association might give misleading results.

Returns

The following list of values is returned:

  • value - Matrix of the coefficients of association;
  • p.value - The p-values for the parameters;
  • type - The matrix of the types of measures of association.

Details

The function looks at the types of the variables and calculates different measures depending on the result:

  • If both variables are numeric, then Pearson's correlation is calculated;
  • If both variables are categorical, then Cramer's V is calculated;
  • Finally, if one of the variables is categorical, and the other is numeric, then multiple correlation is returned.

After that the measures are wrapped up in a matrix.

Function also calculates the p-values associated with the respective measures (see the return).

See details in the vignette "Marketing analytics with greybox": vignette("maUsingGreybox","greybox")

assoc() is just a short name for the association{}.

Examples

association(mtcars)

See Also

table, tableplot, spread, cramer, mcor

Author(s)

Ivan Svetunkov, ivan@svetunkov.com

  • Maintainer: Ivan Svetunkov
  • License: LGPL-2.1
  • Last published: 2025-04-04