2.1.1 • Published 2 years ago
chi-sq-test v2.1.1
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.