pingouin.pcorr

pingouin.pcorr(self)

Partial correlation matrix (pandas.DataFrame method).

Returns
pcormatpandas.DataFrame

Partial correlation matrix.

Notes

This function calculates the pairwise partial correlations for each pair of variables in a pandas.DataFrame given all the others. It has the same behavior as the pcor function in the ppcor R package.

Note that this function only returns the raw Pearson correlation coefficient. If you want to calculate the test statistic and p-values, or use more robust estimates of the correlation coefficient, please refer to the pingouin.pairwise_corr() or pingouin.partial_corr() functions.

Examples

>>> import pingouin as pg
>>> data = pg.read_dataset('mediation')
>>> data.pcorr().round(3)
          X      M      Y   Mbin   Ybin     W1     W2
X     1.000  0.359  0.074 -0.019 -0.147 -0.148 -0.067
M     0.359  1.000  0.555 -0.024 -0.112 -0.138 -0.176
Y     0.074  0.555  1.000 -0.001  0.169  0.101  0.108
Mbin -0.019 -0.024 -0.001  1.000 -0.080 -0.032 -0.040
Ybin -0.147 -0.112  0.169 -0.080  1.000 -0.000 -0.140
W1   -0.148 -0.138  0.101 -0.032 -0.000  1.000 -0.394
W2   -0.067 -0.176  0.108 -0.040 -0.140 -0.394  1.000

On a subset of columns

>>> data[['X', 'Y', 'M']].pcorr()
          X         Y         M
X  1.000000  0.036649  0.412804
Y  0.036649  1.000000  0.540140
M  0.412804  0.540140  1.000000