Skip to content

Commit

Permalink
Fix typing
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Li <[email protected]>
  • Loading branch information
adam2392 committed Apr 11, 2023
1 parent 0600eca commit c7db6d6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
12 changes: 6 additions & 6 deletions pywhy_stats/fisherz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
10 changes: 5 additions & 5 deletions pywhy_stats/p_value_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 10 additions & 10 deletions tests/test_fisherz_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit c7db6d6

Please sign in to comment.