Stats chi2contingencyresult - CyrilB1531/lodestar GitHub Wiki
Development build. This page describes
main, not a released package. The latest published Lodestar.Stats is 0.4.0 — read its documentation.
Home › Stats › Hypothesis tests
Chi2ContingencyResult
A contingency-table chi-square result.
public sealed record Chi2ContingencyResult(double Statistic, double PValue, int Dof, double[][] ExpectedFrequencies)
Properties — Statistic is the chi-square statistic. PValue is the upper-tail p-value.
Dof is the degrees of freedom, (rows - 1) * (columns - 1). ExpectedFrequencies is the table
expected under independence, row-major, the same shape as the input table.
Example — the table ChiSquare.Contingency tests for
independence.
using Lodestar.Stats;
double[][] table =
[
[30.0, 20.0],
[15.0, 35.0],
];
Chi2ContingencyResult result = ChiSquare.Contingency(table);
int dof = result.Dof; // => 1
double expected01 = result.ExpectedFrequencies[0][1]; // => 27.5
Remarks — ExpectedFrequencies is what the table would look like if the two factors were
independent, each cell rowTotal * columnTotal / grandTotal; comparing it against table
cell by cell is what the statistic itself does. It shares table's exact shape rather than a
flattened form, so result.ExpectedFrequencies[i][j] lines up directly with table[i][j].
Being a record, equality would otherwise compare double[][] by reference; Equals and
GetHashCode are written by hand instead, so two results holding the same expected frequencies
compare equal. the equality rule
has the rule.
Applies to — net10.0, netstandard2.0.
See also — ChiSquare.Contingency, TestResult,
the Python equivalence table.
Members
| member | what it does |
|---|---|
Chi2ContingencyResult.Equals |
Value equality, the table row by row. |
Chi2ContingencyResult.GetHashCode |
A hash consistent with it. |