Elamur GroupantsโŒ•
โ˜ฐ

mlab-builtins-stats-contingency

The groupant beside mlab/src/builtins/stats.rs in the Mova repository: what the code computes, what it never does, how to go back from its outputs, its invariants, cost and checks.

Facts

Implementation material. A Mova code model describes this code at one source revision: partial models, finite checks and their stated scope. It is not a reviewed general exposition, and its labels are shown as written, never raised.

Components

componentlabelwhere
approximantpartialapproximant
astpartial../syntax.json
costsymbolic source derivedinvariant
descriptantpresentdescriptant
invariantpartialinvariant
testspartial bounded parent evidencetests

Obernants

The typed relations around the forward model: the behaviour complement (what the code never does), the reverse reconstruction (every input compatible with an output) and specialised views.

idtypelabelwhere
behavior_complementbehavior_complementpartial source derived modelbehavior_complement
reverse_reconstructionreverse_reconstructionpartial source derived modelreverse_reconstruction
marginal_transportmarginal_transportpartial source derived modelmarginal_transport
category_missingcategory_missingpartial source derived modelcategory_missing
branch_relationbranch_relationpartial source derived modelbranch_relation
resource_costresource_costpartial source derived modelresource_cost

Model text

descriptant

mlab-builtins-stats-contingency

chi2_ind takes rectangular nonempty counts, computes marginals and rejects <=0 totals; Eij=ri*cj/N, statistic sum(O-E)^2/E, df=(r-1)(c-1)+fault. crosstab categorizes using table groups, counting missing category as group.

Epoch 2026-10-31: isolated source-bound fragment over bytes [25404,29854); includes no claim beyond this relation. Source hash bdc3772b09d9113e108afa29e391fee97a5372caf9052bb1689996c41c94116f.

approximant

contingency: forward relation

chi2_ind takes rectangular nonempty counts, computes marginals and rejects <=0 totals; Eij=ri*cj/N, statistic sum(O-E)^2/E, df=(r-1)(c-1)+fault. crosstab categorizes using table groups, counting missing category as group.

Domain: Finite, well-shaped bounded observations unless branch explicitly describes NaN/Inf. Direct public chi2/OLS helpers assume dimensions not checked at every index; wrappers add validation.

Executable surrogate gap: no measured cheaper implementation with a useful scoped metric is supplied. Categorical/error/effect relations are exact obligations, not percent losses. Future numeric caps only1/2/5/10%.

invariant

contingency: invariant and cost

Expected row/column sums reproduce observed marginals under finite arithmetic up to rounding.

NaN categories group, unlike missing join keys; wrapper chi2test requires>=2x2 before options.

Scope-specific cost: O(r*c) time and expected matrix storage, plus category sorting O(n log n); invalid marginals fail before matrix fill.

models

behavior_complement

Positive marginals do not ensure nonnegative cells; direct core does not validate that. crosstab degenerate category dimensions returns chi2=0,p=1.

reverse_reconstruction

Expected table admits many observed tables with same marginals; chi2 scalar further collapses dimensional arrangement. Category indices admit all value relabelings preserving sort order.

marginal_transport

Expected row/column sums reproduce observed marginals under finite arithmetic up to rounding.

category_missing

NaN categories group, unlike missing join keys; wrapper chi2test requires>=2x2 before options.

branch_relation

chi2_ind takes rectangular nonempty counts, computes marginals and rejects <=0 totals; Eij=ri*cj/N, statistic sum(O-E)^2/E, df=(r-1)(c-1)+fault. crosstab categorizes using table groups, counting missing category as group.

resource_cost

O(r*c) time and expected matrix storage, plus category sorting O(n log n); invalid marginals fail before matrix fill.

tests

Evidence boundary

See ../tests.md for the actual selected source test and mutant. These tests sample the file, not every fragment branch. Positive marginals do not ensure nonnegative cells; direct core does not validate that. crosstab degenerate category dimensions returns chi2=0,p=1. Other branches here are source-derived and unexecuted unless the parent test explicitly calls them.

This page in Markdown โ†’ https://md.groupants.elamur.ai/free/en/mova/mlab/src/builtins/stats.rs.groupant/contingency.groupant/