corr_pair()

Conducts Pearson (default method), Spearman rank, or Kendall’s Tau-b correlation analysis using pair wise deletion. Returns the relevant information and results in 1 DataFrame for easy exporting.

DataFrame 1 contains the variables being compared in the index, followed by the corresponding r value, p-value, and N for the groups being compared.

Arguments

corr_pair(dataframe, method= “pearson”)

  • dataframe can either be a single Pandas Series or multiple Series/an entire DataFrame.

  • method takes the values of “pearson” [2] (the default if nothing is passed), “spearman” [3], or “kendall” [1].

Examples

import researchpy, numpy, pandas


numpy.random.seed(12345)

df = pandas.DataFrame(numpy.random.randint(10, size= (100, 4)),
                  columns= ['mental_score', 'physical_score', 'emotional_score',
                           'happiness_index'])
# Can pass the entire DataFrame or multiple Series

researchpy.correlation.corr_pair(df)
r value p-value N
mental_score & physical_score 0.0557 0.5823 100
mental_score & emotional_score -0.0237 0.8153 100
mental_score & happiness_index 0.1360 0.1773 100
physical_score & emotional_score 0.0580 0.5663 100
physical_score & happiness_index -0.1366 0.1754 100
emotional_score & happiness_index -0.0632 0.5323 100
# Demonstrating how the output looks if there are different Ns for groups
df['happiness_index'][0:30] = numpy.nan

researchpy.correlation.corr_pair(df)
r value p-value N
mental_score & physical_score 0.0557 0.5823 100
mental_score & emotional_score -0.0237 0.8153 100
mental_score & happiness_index 0.0933 0.4423 70
physical_score & emotional_score 0.0580 0.5663 100
physical_score & happiness_index -0.0268 0.8254 70
emotional_score & happiness_index -0.0873 0.4726 70

References

1

scipy.stats.kendalltau. 2018. Retrieved when last updated on May 5, 2018. URL: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.kendalltau.html.

2

scipy.stats.pearsonr. The SciPy community, 2018. Retrieved when last updated on May 11, 2014. URL: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.pearsonr.html.

3

scipy.stats.spearmanr. The SciPy community, 2018. Retrieved when last updated on May 11, 2014. URL: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.spearmanr.html.