This function gives a list of all pairwise correlations between quantitative variables in a dataframe. Alternatively, it can provide all pairwise correlations with just a particular variable.
all_correlations(X,type="pearson",interest=NA,sorted="none")
A data frame
Either pearson
, spearman
, or both
. If pearson
, the Pearson correlations are returned. If spearman
, the Spearman's rank correlations are returned.
If specified, returns only pairwise correlations with this variable. Argument should be in quotes and must give the exact name of the column of the variable of interest.
Either none
, strength
, significance
, or magnitude
. If strength
, sorts the list from most negative correlation to most positive (remember, correlations are stronger the farther they are from 0 (positive or negative). If significance
, sorts the list by p-value. If none
, no sorting takes place. Note: if both
is requested, no sorting takes place and an error message is output.
This function filters out any non-numerical variables in the data frame and provides correlations only between quantitative variables. It is useful for quickly glancing at the size of the correlations between many pairs of variables or all correlations with a particular variable. Further analysis should be done on pairs of interest using associate
.
Note: if Spearmans' rank correlations are computed, warnings message result indicating that the exact p-value cannot be computed with ties. Running associate
will give you an approximate p-value using the permutation procedure.
Introduction to Regression and Modeling
# NOT RUN {
#all pairwise (Pearson) correlations between all quantitative variables
data(STUDENT)
all_correlations(STUDENT)
#Spearman correlations between all quantitative variables and CollegeGPA, sorted by pvalue.
#Gives warnings due to ties
all_correlations(STUDENT,interest="CollegeGPA",type="spearman",sorted="significance")
# }
Run the code above in your browser using DataLab