corr_pair()

Description

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.

Parameters

Input

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” [1] (the default if nothing is passed), “spearman” [2], or “kendall” [3].

Examples

Loading Packages and Data

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'])

Pearson r

# 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