FisherZ#

class pgmpy.ci_tests.FisherZ(data: DataFrame)[source]#

Bases: _BaseCITest

Fisher’s Z test for conditional independence on continuous data.

This test first computes the Pearson or partial correlation coefficient \(\rho_{XY \mid Z}\) using Pearsonr. It then applies the Fisher transformation and computes the test statistic as:

\[Z = \sqrt{n - |Z| - 3} \cdot \operatorname{arctanh}(\rho_{XY \mid Z}),\]

where \(n\) is the sample size and \(|Z|\) is the number of conditioning variables. Under the null hypothesis \(X \perp Y \mid Z\), \(Z\) is approximately standard normal.

Parameters:
datapandas.DataFrame

The dataset in which to test the independence condition.

Attributes:
statistic_float

The Fisher Z test statistic. Set after calling the test.

p_value_float

The two-sided p-value for the test. Set after calling the test.

Examples

>>> import numpy as np
>>> import pandas as pd
>>> from pgmpy.ci_tests import FisherZ
>>> rng = np.random.default_rng(seed=42)
>>> data = pd.DataFrame(data=rng.standard_normal(size=(1000, 3)), columns=["X", "Y", "Z"])
>>> test = FisherZ(data=data)
>>> test(X="X", Y="Y", Z=["Z"], significance_level=0.05)
np.True_
>>> round(test.statistic_, 2)
np.float64(0.17)
>>> round(test.p_value_, 2)
np.float64(0.87)
run_test(X: str, Y: str, Z: list)[source]#

Compute the Fisher Z statistic and p-value.

Sets self.statistic_, self.transformed_statistic_, and self.p_value_.