2.1.1 • Published 2 years ago

chi-sq-test v2.1.1

Weekly downloads
5
License
MIT
Repository
github
Last release
2 years ago

This package helps run Chi-Squared hypothesis tests for testing distributions on numerical data. Details follow.

How to install

This library can easily be integrated in to your project manually. Alternatively, the library can be included using npm/GitHub packages.

npm install chi-sq-test

How to use

To run chi-squared test for a given dataset

ChiSqTest.gof(fObs, fExp, ddof)

Example:

const ChiSqTest = require('chi-sq-test');

const obs = [2, 3, 4]; // observed frequencies 
const exp = [3, 4, 5]; // expected frequencies    
const ddof = 0;       // delta degree of freedom (Degree Of Freedom  = 3-1 = 2)

const testres1 = ChiSqTest.gof(obs, exp, ddof);
console.log(testres1);

/*
=> { value: 0.7833333333333332, pValue: 0.6759293959125221 }
*/

const testres2 = ChiSqTest.gof(obs); // mean fObs is used as fExp by default
console.log(testres2);

/*
=> { value: 0.6666666666666666, pValue: 0.7165313783925148 }
*/

Output:

Function gof returns a JSON object, which contains Chi-Square value and the pValue for the given dataset.

Chi-square statistics for independence

ChiSqTest.independence(fObs, ddof)

Example

const ChiSqTest = require('chi-sq-test');
const obs = [
    [160, 240],
    [140, 460]
];

console.log(
    ChiSqTest.independence(obs, 0)
);

/*
=> { value: 31.746031746031747, pValue: 1.7570790822318827e-8 }
*/

Output:

Function independence returns a JSON object, which contains Chi-Square value and the pValue for the hypothesis for indpendence.

2.1.1

2 years ago

2.0.2

2 years ago

2.1.0

2 years ago

1.0.10-beta

2 years ago

2.0.1

2 years ago

1.0.9-beta

2 years ago

1.1.0

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

0.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago