Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ab-test-result

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ab-test-result - npm Package Compare versions

Comparing version 1.0.1 to 1.0.3

57

index.js

@@ -1,3 +0,3 @@

var BigNumber = require('bignumber.js');
var simpleStatistics = require('simple-statistics');
const BigNumber = require('bignumber.js');
const simpleStatistics = require('simple-statistics');

@@ -12,17 +12,17 @@ module.exports = {

var A_visits = new BigNumber(test.controlVisits);
var A_conversions = new BigNumber(test.controlConversions);
var B_visits = new BigNumber(test.challengerVisits);
var B_conversions = new BigNumber(test.challengerConversions);
const A_visits = new BigNumber(test.controlVisits);
const A_conversions = new BigNumber(test.controlConversions);
const B_visits = new BigNumber(test.challengerVisits);
const B_conversions = new BigNumber(test.challengerConversions);
var A_rate = calcConversionRate(A_visits, A_conversions);
var B_rate = calcConversionRate(B_visits, B_conversions);
var B_improvement = B_rate.sub(A_rate).div(A_rate);
const A_rate = calcConversionRate(A_visits, A_conversions);
const B_rate = calcConversionRate(B_visits, B_conversions);
const B_improvement = B_rate.sub(A_rate).div(A_rate);
var A_stdErr = calcStandardError(A_visits, A_conversions);
var B_stdErr = calcStandardError(B_visits, B_conversions);
const A_stdErr = calcStandardError(A_visits, A_conversions);
const B_stdErr = calcStandardError(B_visits, B_conversions);
var zScore = calcZScore(A_rate, B_rate, A_stdErr, B_stdErr);
var pValue = calcPValue(A_rate, B_rate, zScore);
var isSignificant = determineSignificance(zScore, pValue, confidence);
const zScore = calcZScore(A_rate, B_rate, A_stdErr, B_stdErr);
const pValue = calcPValue(A_rate, B_rate, zScore);
const isSignificant = determineSignificance(zScore, pValue, confidence);

@@ -48,4 +48,4 @@ return {

function calcStandardError(visits, conversions) {
var rate = calcConversionRate(visits, conversions);
var dividend = rate.mul( new BigNumber(1).sub(rate) );
const rate = calcConversionRate(visits, conversions);
const dividend = rate.mul( new BigNumber(1).sub(rate) );
return dividend.div(visits).sqrt();

@@ -55,4 +55,4 @@ }

function calcZScore(A_rate, B_rate, A_stdErr, B_stdErr) {
var rateDiff = B_rate.sub(A_rate);
var stdErrOfDiff = A_stdErr.pow(2).add(B_stdErr.pow(2)).sqrt();
const rateDiff = B_rate.sub(A_rate);
const stdErrOfDiff = A_stdErr.pow(2).add(B_stdErr.pow(2)).sqrt();
return (rateDiff).div(stdErrOfDiff);

@@ -62,4 +62,4 @@ }

function calcPValue(A_rate, B_rate, zScore) {
var zScoreAbs = zScore.abs().toNumber();
var csnp = simpleStatistics.cumulativeStdNormalProbability(zScoreAbs);
const zScoreAbs = zScore.abs().toNumber();
const csnp = simpleStatistics.cumulativeStdNormalProbability(zScoreAbs);
if (A_rate > B_rate) {

@@ -79,6 +79,6 @@ return csnp;

function validateInput(test, confidence) {
validatePropertyDefined(test, 'controlVisits');
validatePropertyDefined(test, 'controlConversions');
validatePropertyDefined(test, 'challengerVisits');
validatePropertyDefined(test, 'challengerConversions');
validateInputNumber(test, 'controlVisits');
validateInputNumber(test, 'controlConversions');
validateInputNumber(test, 'challengerVisits');
validateInputNumber(test, 'challengerConversions');
if (test.controlVisits < test.controlConversions) {

@@ -95,6 +95,9 @@ throw new Error('controlVisits must be greater than or equal to controlConversions');

function validatePropertyDefined(test, propName) {
if (!test[propName]) {
throw new Error(propName + ' must be defined in test');
function validateInputNumber(test, propName) {
if (!Number.isInteger(test[propName])) {
throw new Error(propName + ' must be a number');
}
if (test[propName] < 0) {
throw new Error(propName + ' cannot be negative');
}
}
{
"name": "ab-test-result",
"version": "1.0.1",
"version": "1.0.3",
"description": "Returns the improvement rate of your AB-test and answers if it's statistically significant",

@@ -20,3 +20,4 @@ "main": "index.js",

"test": "istanbul cover _mocha",
"coveralls": "cat ./coverage/lcov.info | coveralls"
"coveralls": "cat ./coverage/lcov.info | coveralls",
"postversion”": "git push && git push --tags"
},

@@ -23,0 +24,0 @@ "repository": {

@@ -22,5 +22,5 @@ # ab-test-result

};
var confidense = 0.9; // optional, defaults to 0.95
var confidence = 0.9; // optional, defaults to 0.95
var result = abTestResult.calcResult(test, confidense);
var result = abTestResult.calcResult(test, confidence);
/*

@@ -27,0 +27,0 @@ result = {

@@ -22,3 +22,3 @@ const abTestResult = require('..');

it('should throw error', () => {
expect(errorMessage).to.equal('controlVisits must be defined in test');
expect(errorMessage).to.equal('controlVisits must be a number');
});

@@ -43,3 +43,3 @@ });

it('should throw error', () => {
expect(errorMessage).to.equal('controlConversions must be defined in test');
expect(errorMessage).to.equal('controlConversions must be a number');
});

@@ -64,3 +64,3 @@ });

it('should throw error', () => {
expect(errorMessage).to.equal('challengerVisits must be defined in test');
expect(errorMessage).to.equal('challengerVisits must be a number');
});

@@ -85,5 +85,89 @@ });

it('should throw error', () => {
expect(errorMessage).to.equal('challengerConversions must be defined in test');
expect(errorMessage).to.equal('challengerConversions must be a number');
});
});
describe('when controlConversions property is less than zero', () => {
var errorMessage;
before(() => {
try {
abTestResult.calcResult({
controlVisits: 1,
controlConversions: -1,
challengerVisits: 1,
challengerConversions: 1
});
} catch (e) {
errorMessage = e.message;
}
});
it('should throw error', () => {
expect(errorMessage).to.equal('controlConversions cannot be negative');
});
});
describe('when challengerVisits property is less than zero', () => {
var errorMessage;
before(() => {
try {
abTestResult.calcResult({
controlVisits: 1,
controlConversions: 1,
challengerVisits: -1,
challengerConversions: 1
});
} catch (e) {
errorMessage = e.message;
}
});
it('should throw error', () => {
expect(errorMessage).to.equal('challengerVisits cannot be negative');
});
});
describe('when challengerConversions property is less than zero', () => {
var errorMessage;
before(() => {
try {
abTestResult.calcResult({
controlVisits: 1,
controlConversions: 1,
challengerVisits: 1,
challengerConversions: -1
});
} catch (e) {
errorMessage = e.message;
}
});
it('should throw error', () => {
expect(errorMessage).to.equal('challengerConversions cannot be negative');
});
});
describe('when controlVisits property is less than zero', () => {
var errorMessage;
before(() => {
try {
abTestResult.calcResult({
controlVisits: -1,
controlConversions: 1,
challengerVisits: 1,
challengerConversions: 1
});
} catch (e) {
errorMessage = e.message;
}
});
it('should throw error', () => {
expect(errorMessage).to.equal('controlVisits cannot be negative');
});
});
});

@@ -138,3 +222,3 @@

describe('confidense interval', () => {
var test = {
const test = {
controlVisits: 1,

@@ -141,0 +225,0 @@ controlConversions: 1,

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc