Skip to content

Commit

Permalink
Calculate p_value in .paired_test like we do in .perform
Browse files Browse the repository at this point in the history
  • Loading branch information
ylansegal committed Apr 17, 2023
1 parent 74f48b7 commit 6918daa
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/statistics/statistical_test/t_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ def self.paired_test(alpha, tails, left_group, right_group)

t_score = (differences.mean - 0)/down.to_r

probability = Distribution::TStudent.new(degrees_of_freedom).cumulative_function(t_score)
t_distribution = Distribution::TStudent.new(degrees_of_freedom)
probability = t_distribution.cumulative_function(t_score)

p_value = 1 - probability
p_value *= 2 if tails == :two_tail
p_value = if tails == :two_tail
2 * (1 - t_distribution.cumulative_function(t_score.abs))
else
1 - probability
end

{ t_score: t_score,
probability: probability,
Expand Down

0 comments on commit 6918daa

Please sign in to comment.