Permalink
Browse files

Merge pull request #50 from elliotcm/master

A refactor of the confidence helper
  • Loading branch information...
2 parents e2c7074 + af5bd61 commit 7a539b56b59a973db998f832b64138917d531749 @andrew andrew committed Apr 24, 2012
Showing with 21 additions and 24 deletions.
  1. +12 −23 lib/split/dashboard/helpers.rb
  2. +9 −1 spec/dashboard_helpers_spec.rb
@@ -19,30 +19,19 @@ def round(number, precision = 2)
def confidence_level(z_score)
return z_score if z_score.is_a? String
- z = round(z_score.to_s.to_f, 3)
- if z > 0.0
- if z < 1.96
- 'no confidence'
- elsif z < 2.57
- '95% confidence'
- elsif z < 3.29
- '99% confidence'
- else
- '99.9% confidence'
- end
- elsif z < 0.0
- if z > -1.96
- 'no confidence'
- elsif z > -2.57
- '95% confidence'
- elsif z > -3.29
- '99% confidence'
- else
- '99.9% confidence'
- end
+ z = round(z_score.to_s.to_f, 3).abs
+
+ if z == 0.0
+ 'No Change'
+ elsif z < 1.96
+ 'no confidence'
+ elsif z < 2.57
+ '95% confidence'
+ elsif z < 3.29
+ '99% confidence'
else
- "No Change"
+ '99.9% confidence'
end
end
end
-end
+end
@@ -8,5 +8,13 @@
it 'should handle very small numbers' do
confidence_level(Complex(2e-18, -0.03)).should eql('No Change')
end
+
+ it "should consider a z-score of 1.96 < z < 2.57 as 95% confident" do
+ confidence_level(2.12).should eql('95% confidence')
+ end
+
+ it "should consider a z-score of -1.96 > z > -2.57 as 95% confident" do
+ confidence_level(-2.12).should eql('95% confidence')
+ end
end
-end
+end

0 comments on commit 7a539b5

Please sign in to comment.