Skip to content

Commit

Permalink
fix(get_t_and_critical_t): avoid division by zero and optimize runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
this-is-sofia committed Oct 15, 2023
1 parent 3670b97 commit 2f3e158
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions causy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def sum_lists(*lists):
"""
:param lists: lists of numbers
:return: list (sum of$$ lists)
:return: list (sum of lists)
"""
return list(map(sum, zip(*lists)))

Expand Down Expand Up @@ -97,10 +97,10 @@ def get_correlation(x, y, other_nodes):


def get_t_and_critial_t(sample_size, nb_of_control_vars, par_corr, threshold):
# check if we have to normalize data
deg_of_freedom = sample_size - 2 - nb_of_control_vars

if abs(round(par_corr, 4)) == 1:
par_corr = 0.9999999999999999
t = par_corr * math.sqrt((deg_of_freedom) / (1 - par_corr**2))
return (1, 0)
critical_t = scipy_stats.t.ppf(1 - threshold / 2, deg_of_freedom)
t = par_corr * math.sqrt((deg_of_freedom) / (1 - par_corr**2))
return (t, critical_t)

0 comments on commit 2f3e158

Please sign in to comment.