Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chipbell4/chi-squared-test
Node module for calculating a Chi-Squared probability
https://github.com/chipbell4/chi-squared-test
Last synced: 9 days ago
JSON representation
Node module for calculating a Chi-Squared probability
- Host: GitHub
- URL: https://github.com/chipbell4/chi-squared-test
- Owner: chipbell4
- Created: 2015-01-29T02:10:21.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-16T00:40:30.000Z (over 9 years ago)
- Last Synced: 2024-10-28T17:33:10.333Z (19 days ago)
- Language: JavaScript
- Size: 154 KB
- Stars: 3
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Chi-Squared Test
This package provides a small function for calculating a chi-squared test on a given dataset. Given an observed set of
frequencies `observations`, an expected set of frequencies `expectations`, and the number of degrees of freedom reduced
in the measurement, calculates the probability that the observations came from the same probability distribution.For example, let's check a die for fairness:
```
var chiSquaredTest = require('chi-squared-test');// We expect a fair die
var expected = [2, 2, 2, 2, 2, 2];// Looks pretty unfair...
var observed = [6, 3, 3, 0, 0, 0];// Reduction in degrees of freedom is 1, since knowing 5 categories determines the 6th
var reduction = 1;var probability = chiSquaredTest(observed, expected, reduction).probability;
// Gives 0.010362, which indicates that it's unlikely the die is fair// However, something a little more likely
observed = [1, 2, 4, 4, 2, 1];
probability = chiSquaredTest(observed, expected, reduction).probability;
// Gives back 0.415881, which is indicates that they did come from the same distribution (by most statistical standards)
```