utils.stats.partial_correlation_test
utils.stats.partial_correlation_test(x, y, z, method= 'pearson' )
The partial correlation coefficient between x and y given z. x and y should be arrays (vectors) of the same length, and z should be a data frame (matrix).
Parameters
x
array - like
The first variable as a 1-dimensional array or list.
required
y
array - like
The second variable as a 1-dimensional array or list.
required
z
pandas .DataFrame
A data frame containing other conditional variables.
required
method
str
Correlation method, one of ‘pearson’, ‘kendall’, or ‘spearman’.
'pearson'
Returns
dict
dict
A dictionary with the partial correlation estimate, p-value, statistic, sample size (n), number of given parameters (gp), and method used.
References
Kim, S. ppcor: An R package for a fast calculation to semi-partial correlation coefficients. Commun Stat Appl Methods 22, 6 (Nov 2015), 665–674.
Examples
>>> from spotpython.utils.stats import pairwise_partial_correlation
>>> import pandas as pd
>>> x = [1 , 2 , 3 ]
>>> y = [4 , 5 , 6 ]
>>> z = pd.DataFrame({'C' : [7 , 8 , 9 ]})
>>> pairwise_partial_correlation(x, y, z)
{'estimate' : - 1.0 , 'p_value' : 0.0 , 'statistic' : - inf, 'n' : 3 , 'gp' : 1 , 'method' : 'pearson' }