# pingouin.pcorr

pingouin.pcorr(self)[source]

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. The pingouin.pcorr() function uses the inverse of the variance-covariance matrix to calculate the partial correlation matrix and is therefore much faster than the two latter functions which are based on the residuals.

References

1

https://cran.r-project.org/web/packages/ppcor/index.html

Examples

>>> import pingouin as pg
>>> data.pcorr()
X         M         Y      Mbin      Ybin
X     1.000000  0.392251  0.059771 -0.014405 -0.149210
M     0.392251  1.000000  0.545618 -0.015622 -0.094309
Y     0.059771  0.545618  1.000000 -0.007009  0.161334
Mbin -0.014405 -0.015622 -0.007009  1.000000 -0.076614
Ybin -0.149210 -0.094309  0.161334 -0.076614  1.000000


On a subset of columns

>>> data[['X', 'Y', 'M']].pcorr().round(3)
X      Y      M
X  1.000  0.037  0.413
Y  0.037  1.000  0.540
M  0.413  0.540  1.000