[go: up one dir, main page]

@folge3/chi-square
TypeScript icon, indicating that this package has built-in type declarations

1.4.3 • Public • Published

Chi-Square

This package contains functions to calculate Chi-Square critical values as well as performing a Chi-Square statistical test.

Installation

npm install @folge3/chi-square

Usage

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)

Options

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.

Development

Testing

npm run test

Deployment

  1. Commit changes
  2. npm version [patch|minor|major]
  3. npm run build
  4. npm publish --access public

Package Sidebar

Install

npm i @folge3/chi-square

Weekly Downloads

1

Version

1.4.3

License

ISC

Unpacked Size

82 kB

Total Files

8

Last publish

Collaborators

  • cff3
  • steffen-f3