# chiSquaredGoodnessOfFitTest

> **chiSquaredGoodnessOfFitTest**(`observed`, `probabilities`, `options?`): [`ChiSquaredGoodnessOfFitTestResult`](/reference/knotkit/hypothesis-test/interfaces/chisquaredgoodnessoffittestresult/)

Defined in: [packages/hypothesis-test/src/chi-squared-goodness-of-fit-test.ts:38](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/hypothesis-test/src/chi-squared-goodness-of-fit-test.ts#L38)

Compare category counts against probabilities scaled by the observed total. The probability sum must lie within 1e-12 of one. The calculation preserves the supplied probabilities. It drops categories with two zero counts and returns a zero p-value when any positive observation has zero expectation.

Pooling works inward from both tails and merges any remaining low interior categories toward larger indices. The p-value is the upper tail of the asymptotic chi-squared distribution. Time and working storage are linear in the category count.

## Parameters

### observed

`ArrayLike`<`number`>

### probabilities

`ArrayLike`<[`Probability`](/reference/knotkit/distribution/type-aliases/probability/)>

### options?

[`ChiSquaredGoodnessOfFitTestOptions`](/reference/knotkit/hypothesis-test/interfaces/chisquaredgoodnessoffittestoptions/)

## Returns

[`ChiSquaredGoodnessOfFitTestResult`](/reference/knotkit/hypothesis-test/interfaces/chisquaredgoodnessoffittestresult/)

## Throws

With `INVALID_COUNT` for an invalid count or unsafe total, `LENGTH_MISMATCH`, `TOO_FEW_CATEGORIES`, `INVALID_PROBABILITIES`, `ZERO_TOTAL_COUNT`, `INVALID_OPTION` for an invalid pooling threshold, or `INVALID_DEGREES_OF_FREEDOM`.

## Throws

With `INVALID_PARAMETER` when the degrees of freedom exceed the supported maximum.
