ab-test-result
Advanced tools
Comparing version 1.0.5 to 1.1.0
17
index.js
@@ -19,4 +19,10 @@ const BigNumber = require('bignumber.js'); | ||
const B_rate = calcConversionRate(B_visits, B_conversions); | ||
const B_improvement = B_rate.sub(A_rate).div(A_rate); | ||
let B_improvement; | ||
if (A_rate.isZero() || B_rate.isZero()) { | ||
B_improvement = new BigNumber(0); | ||
} else { | ||
B_improvement = B_rate.sub(A_rate).div(A_rate); | ||
} | ||
const A_stdErr = calcStandardError(A_visits, A_conversions); | ||
@@ -44,2 +50,5 @@ const B_stdErr = calcStandardError(B_visits, B_conversions); | ||
function calcConversionRate(visits, conversions) { | ||
if (conversions.isZero()) { | ||
return new BigNumber(0); | ||
} | ||
return conversions.div(visits); | ||
@@ -49,2 +58,5 @@ } | ||
function calcStandardError(visits, conversions) { | ||
if (visits.isZero()) { | ||
return new BigNumber(0); | ||
} | ||
const rate = calcConversionRate(visits, conversions); | ||
@@ -58,2 +70,5 @@ const dividend = rate.mul( new BigNumber(1).sub(rate) ); | ||
const stdErrOfDiff = A_stdErr.pow(2).add(B_stdErr.pow(2)).sqrt(); | ||
if (stdErrOfDiff.isZero()) { | ||
return new BigNumber(0); | ||
} | ||
return (rateDiff).div(stdErrOfDiff); | ||
@@ -60,0 +75,0 @@ } |
{ | ||
"name": "ab-test-result", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "Returns the improvement rate of your AB-test and answers if it's statistically significant", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,2 +5,90 @@ const abTestResult = require('..'); | ||
describe('when some values are zero', () => { | ||
describe('when all values are zero', () => { | ||
var result; | ||
before(() => { | ||
result = abTestResult.calcResult({ | ||
controlVisits: 0, | ||
controlConversions: 0, | ||
challengerVisits: 0, | ||
challengerConversions: 0 | ||
}); | ||
}); | ||
it('should return result without any NaN values', () => { | ||
expect(result).to.eql({ | ||
controlConversionRate: 0, | ||
challengerConversionRate: 0, | ||
challengerImprovement: 0, | ||
isSignificant: false, | ||
statistics: { | ||
controlStandardError: 0, | ||
challengerStandardError: 0, | ||
zScore: 0, | ||
pValue: 0.5 | ||
} | ||
}); | ||
}); | ||
}); | ||
describe('when controlConversions is zero', () => { | ||
var result; | ||
before(() => { | ||
result = abTestResult.calcResult({ | ||
controlVisits: 0, | ||
controlConversions: 0, | ||
challengerVisits: 10, | ||
challengerConversions: 5 | ||
}); | ||
}); | ||
it('should return result without any NaN values', () => { | ||
expect(result).to.eql({ | ||
controlConversionRate: 0, | ||
challengerConversionRate: 0.5, | ||
challengerImprovement: 0, | ||
isSignificant: true, | ||
statistics: { | ||
controlStandardError: 0, | ||
challengerStandardError: 0.15811388300841897, | ||
zScore: 3.1622776601683795, | ||
pValue: 0.0010000000000000009 | ||
} | ||
}); | ||
}); | ||
}); | ||
describe('when challengerConversions is zero', () => { | ||
var result; | ||
before(() => { | ||
result = abTestResult.calcResult({ | ||
controlVisits: 10, | ||
controlConversions: 5, | ||
challengerVisits: 0, | ||
challengerConversions: 0 | ||
}); | ||
}); | ||
it('should return result without any NaN values', () => { | ||
expect(result).to.eql({ | ||
controlConversionRate: 0.5, | ||
challengerConversionRate: 0, | ||
challengerImprovement: 0, | ||
isSignificant: true, | ||
statistics: { | ||
controlStandardError: 0.15811388300841897, | ||
challengerStandardError: 0, | ||
zScore: -3.1622776601683795, | ||
pValue: 0.999 | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('when challenger performs better than or equal to control', () => { | ||
@@ -7,0 +95,0 @@ describe('when no min confidense is provided', () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19590
597
11