Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a numerical issue in fisherz #108

Merged
merged 2 commits into from
Apr 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions causallearn/utils/cit.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def __call__(self, X, Y, condition_set=None):
except np.linalg.LinAlgError:
raise ValueError('Data correlation matrix is singular. Cannot run fisherz test. Please check your data.')
r = -inv[0, 1] / sqrt(inv[0, 0] * inv[1, 1])
if abs(r) >= 1: r = (1. - np.finfo(float).eps) * np.sign(r) # may happen when samplesize is very small or relation is deterministic
Z = 0.5 * log((1 + r) / (1 - r))
X = sqrt(self.sample_size - len(condition_set) - 3) * abs(Z)
p = 2 * (1 - norm.cdf(abs(X)))
Expand Down Expand Up @@ -382,6 +383,7 @@ def __call__(self, X, Y, condition_set=None):
except np.linalg.LinAlgError:
raise ValueError('Data correlation matrix is singular. Cannot run fisherz test. Please check your data.')
r = -inv[0, 1] / sqrt(inv[0, 0] * inv[1, 1])
if abs(r) >= 1: r = (1. - np.finfo(float).eps) * np.sign(r) # may happen when samplesize is very small or relation is deterministic
Z = 0.5 * log((1 + r) / (1 - r))
X = sqrt(len(test_wise_deletion_XYcond_rows_index) - len(condition_set) - 3) * abs(Z)
p = 2 * (1 - norm.cdf(abs(X)))
Expand Down