diff --git a/pywhy_stats/fisherz.py b/pywhy_stats/fisherz.py index 1e7ea8f..986289d 100644 --- a/pywhy_stats/fisherz.py +++ b/pywhy_stats/fisherz.py @@ -8,7 +8,7 @@ from .p_value_result import PValueResult -def ind(X: ArrayLike, Y: ArrayLike, correlation_matrix: Optional[ArrayLike] = None): +def ind(X: ArrayLike, Y: ArrayLike, correlation_matrix: Optional[ArrayLike] = None) -> PValueResult: """Perform an independence test using Fisher-Z's test. Works on Gaussian random variables. This test is also known as the @@ -38,7 +38,7 @@ def condind( Y: ArrayLike, condition_on: ArrayLike, correlation_matrix: Optional[ArrayLike] = None, -): +) -> PValueResult: """Perform an independence test using Fisher-Z's test. Works on Gaussian random variables. This test is also known as the @@ -70,7 +70,7 @@ def _fisherz( Y: ArrayLike, condition_on: Optional[ArrayLike] = None, correlation_matrix: Optional[ArrayLike] = None, -): +) -> PValueResult: """Perform an independence test using Fisher-Z's test. Works on Gaussian random variables. This test is also known as the @@ -111,6 +111,6 @@ def _fisherz( Z = 0.5 * log((1 + r) / (1 - r)) # compute the test statistic - X = sqrt(sample_size - condition_on.shape[1] - 3) * abs(Z) - p = 2 * (1 - norm.cdf(abs(X))) - return PValueResult(X, p) + statistic = sqrt(sample_size - condition_on.shape[1] - 3) * abs(Z) + p = 2 * (1 - norm.cdf(abs(statistic))) + return PValueResult(statistic, p) diff --git a/pywhy_stats/p_value_result.py b/pywhy_stats/p_value_result.py index a1b11a8..60b5469 100644 --- a/pywhy_stats/p_value_result.py +++ b/pywhy_stats/p_value_result.py @@ -10,16 +10,16 @@ class PValueResult: Attributes ---------- - p_value: float + pvalue : float The p-value represents the probability of observing the given test statistic, or more extreme results, under a certain null hypothesis. - test_statistic: float or numpy.ndarray or None + statistic : float or ArrayLike or None The test statistic of the hypothesis test, which might not always be available. - additional_information: object or None + additional_information : object or None Any additional information or metadata relevant to the specific test conducted. These could also be a state of the method to re-use it. """ - p_value: float - test_statistic: Optional[Union[float, ArrayLike]] = None + pvalue: float + statistic: Optional[Union[float, ArrayLike]] = None additional_information: Optional[object] = None diff --git a/tests/test_fisherz_test.py b/tests/test_fisherz_test.py index f90a4f1..cc5e052 100644 --- a/tests/test_fisherz_test.py +++ b/tests/test_fisherz_test.py @@ -17,10 +17,10 @@ def test_fisherz_marg_ind(): Y = X + X1 + 0.5 * rng.standard_normal((300, 1)) Z = Y + 0.1 * rng.standard_normal((300, 1)) - _, pvalue = fisherz.ind(X, X1) - assert pvalue > 0.05 - _, pvalue = fisherz.ind(X, Z) - assert pvalue < 0.05 + res = fisherz.ind(X, X1) + assert res.pvalue > 0.05 + res = fisherz.ind(X, Z) + assert res.pvalue < 0.05 @flaky.flaky(max_runs=3, min_passes=1) @@ -36,9 +36,9 @@ def test_fisherz_cond_ind(): Y = X + X1 + 0.5 * rng.standard_normal((300, 1)) Z = Y + 0.1 * rng.standard_normal((300, 1)) - _, pvalue = fisherz.condind(X, X1, Z) - assert pvalue < 0.05 - _, pvalue = fisherz.condind(X, X1, Y) - assert pvalue < 0.05 - _, pvalue = fisherz.condind(X, Z, Y) - assert pvalue > 0.05 + res = fisherz.condind(X, X1, Z) + assert res.pvalue < 0.05 + res = fisherz.condind(X, X1, Y) + assert res.pvalue < 0.05 + res = fisherz.condind(X, Z, Y) + assert res.pvalue > 0.05