Automatically computes the proper correlations between
continuous and categorical variables. NA values are not treated
as categories
auto_correlate(
data,
corr = c("kendall", "pearson", "spearman"),
ordinal_categories = 7,
forcePD = TRUE,
na_data = c("pairwise", "listwise"),
empty_method = c("none", "zero", "all"),
empty_value = c("none", "point_five", "one_over"),
forceReturn = FALSE,
verbose = FALSE,
...
)A symmetric numeric matrix of dimension \(p \times p\), where
\(p\) is the number of variables in data, with values in
\([-1, 1]\) and ones on the diagonal. The correlation method used for
each pair of variables depends on their types when corr = "pearson"
(the default): polychoric for ordinal-ordinal pairs, polyserial for
ordinal-continuous pairs, and Pearson's for continuous-continuous pairs,
where ordinal means having at most ordinal_categories unique
values. When corr is "kendall" or "spearman",
cor is used for all pairs regardless of variable
type. Row and column names are inherited from data. When
forcePD = TRUE (default) and the resulting matrix is not positive
definite, the nearest positive definite matrix is returned via
nearPD.
Matrix or data frame. Should consist only of variables to be used in the analysis
Character (length = 1).
The standard correlation method to be used.
Defaults to "pearson".
Using "pearson" will compute polychoric, tetrachoric, polyserial,
and biserial correlations for categorical and categorical/continuous correlations
by default. To obtain "pearson" correlations regardless, use cor.
Other options of "kendall" and "spearman" are provided for
completeness and use cor
Numeric (length = 1).
Up to the number of categories before a variable is considered continuous.
Defaults to 7 categories before 8 is considered continuous
Boolean (length = 1).
Whether positive definite matrix should be enforced.
Defaults to TRUE
Character (length = 1).
How should missing data be handled?
Defaults to "pairwise".
Available options:
"pairwise" --- Computes correlation for all available
cases between two variables
"listwise" --- Computes correlation for all complete
cases in the dataset
Character (length = 1).
Method for empty cell correction in polychoric_matrix.
Defaults to "none"
Available options:
"none" --- Adds no value (empty_value = "none")
to the empirical joint frequency table between two variables
"zero" --- Adds empty_value to the cells with
zero in the joint frequency table between two variables
"all" --- Adds empty_value to all
in the joint frequency table between two variables
Character (length = 1).
Value to add to the joint frequency table cells in polychoric_matrix.
Defaults to "none".
Accepts numeric values between 0 and 1 or specific methods:
"none" --- Adds no value (0) to the empirical
joint frequency table between two variables
"point_five" --- Adds 0.5 to the cells
defined by empty_method
"one_over" --- Adds 1 / n where n equals the
number of cells based on empty_method. For
empty_method = "zero", n equals the number of zero cells
Boolean (length = 1).
Whether correlation matrix should be forced to return.
Defaults to FALSE.
Set to TRUE to receive the correlation matrix "as is"
Boolean (length = 1).
Whether messages should be printed.
Defaults to FALSE
Not actually used but makes it easier for general functionality in the package
Alexander P. Christensen <alexpaulchristensen@gmail.com>
# Obtain correlations
R <- auto_correlate(basic_smallworld)
Run the code above in your browser using DataLab