This package contains functions to calculate Chi-Square critical values as well as performing a Chi-Square statistical test.
npm install @folge3/chi-square
import {chiSquare, DistributionData, Distribution, ChiSquareTestResult, chiSquareCriticalValue, ChiSquareOptions} from "@folge3/chi-square";
const data: DistributionData = {
rows: ['row1', 'row2'],
columns: ['column1', 'column2'],
data: [
[52, 27],
[23, 56]
]
}
const distribution: Distribution = new Distribution(data);
const options: ChiSquareOptions = {
rowImpactWeightExponent: 0.3
}
// Run chi-square test with 5% uncertainty
const result: ChiSquareTestResult = chiSquare(distribution, 0.05, options);
console.log(result);
// Get critical value for significance level 0.05 and 1 degree of freedom.
const criticalValue = chiSquareCriticalValue(0.05, 1);
// ~3.841
console.log(criticalValue)
Here are the available options for the ChiSquareOptions:
Option | Type | Description |
---|---|---|
rowImpactWeightExponent | number | Exponent modifier for weights in row impact rating. Must lie in [0.1, 1]. Default: 1. |
normalizeRows | boolean | Flag to decide if data shall be normalized by its rows. Takes precedence over columns. |
normalizeColumns | boolean | Flag to decide if data shall be normalized by its columns. Is preceded by row normalization. |
normalizationMarginalTarget | number | Target value for marginals for normalization. Must be greater than 0. Default: 100. |
npm run test
- Commit changes
- npm version [patch|minor|major]
- npm run build
- npm publish --access public