nx_survey_stats.nx
buildroot/runtime/nx_survey_stats.nx
about
nx_survey_stats.nx -- the INSIGHTS engine over survey responses (operator 2026-07-10: "we have the survey
front end but we dont have any of the statistics or all the capabilities that power meaningful insights").
CONSUMES nx_survey_engine's effective ballots (se_ballots -> vout[i]/lout[i] = ballot record bytes) and
question records; turns raw responses into the analytics a real survey product delivers:
- descriptive: n/min/max/mean/median/mode/stddev (fixed-point permille, integer isqrt)
- CX metrics: NPS (promoters-detractors), top/bottom-box, 95% confidence margin on a proportion
- cross-tabulation: r x c contingency of one question by another
- significance: chi-square test of independence vs a DATA-DRIVEN critical table (alpha .05), FAIL-CLOSED
past df 10 (never a false "significant") -- the adversary's own guard
- key drivers: Pearson correlation of every scale question against a chosen outcome, ranked by |r|
- segment analysis: mean of a target question within each level of a segment question
- trend: before/after split on real ballot timestamps
- welfare triage rollup: composes nx_survey's sv_triage/sv_band to count crisis/strained/stable
- open text: sovereign tokenized theme frequency (honest: frequency-based, NOT neural topic/sentiment)
100% integer / fixed-point, no floats, no hardware writes. Every stat is hand-KAT'd in the gate and carries
an adversarial neg-control (a fabricated significance / correlation must be rejected). license_tier: ORIGINAL
dependencies 1 imports · 2 importers
imports: nx_survey_engine.nx
imported by: nx_survey_quality.nxnx_survey_stats_gate.nx
structs
| none |
consts
| 18 | const ST_MAGIC_3841: i64 = 3841 |
| 19 | const ST_MAGIC_5991: i64 = 5991 |
| 20 | const ST_MAGIC_7815: i64 = 7815 |
| 21 | const ST_MAGIC_9488: i64 = 9488 |
| 22 | const ST_MAGIC_11070: i64 = 11070 |
| 23 | const ST_MAGIC_12592: i64 = 12592 |
| 24 | const ST_MAGIC_14067: i64 = 14067 |
| 25 | const ST_MAGIC_15507: i64 = 15507 |
| 26 | const ST_MAGIC_16919: i64 = 16919 |
| 27 | const ST_MAGIC_18307: i64 = 18307 |
| 28 | const ST_MAGIC_9223372036854775807: i64 = 9223372036854775807 |
| 29 | const ST_MAGIC_4096: i64 = 4096 |
| 31 | const ST_SCALE: i64 = 1000 // permille fixed-point |
| 32 | const ST_Z95SQ: i64 = 3841600 // (1.96 * 1000)^2 = 3841600, the 95% two-tailed z^2 in permille^2 |
functions
| 35 | func st_isqrt(n: i64) -> i64 |
| 45 | func st_answer_int(vp: *u8, vl: i64, qid: *u8) -> i64 called by 8: sq_attentionsq_longstringsq_consistencyst_collectst_collect_pairsst_xtab+2 calls 2: se_answer_ofse_digits |
| 53 | func st_ballot_usec(vp: *u8, vl: i64) -> i64 |
| 63 | func st_collect(vout: *i64, lout: *i64, nb: i64, qid: *u8, xs: *i64) -> i64 |
| 74 | func st_collect_pairs(vout: *i64, lout: *i64, nb: i64, qx: *u8, qy: *u8, xs: *i64, ys: *i64) -> i64 |
| 86 | func st_sortcopy(xs: *i64, m: i64, dst: *i64) -> i64 called by 1: st_desc |
| 105 | func st_desc(xs: *i64, m: i64, out: *i64) -> i64 |
| 145 | func st_nps(xs: *i64, m: i64, prom_min: i64, det_max: i64, out: *i64) -> i64 |
| 160 | func st_topbox(xs: *i64, m: i64, maxval: i64, boxsize: i64) -> i64 |
| 169 | func st_ci_margin(k: i64, n: i64) -> i64 |
| 180 | func st_xtab(vout: *i64, lout: *i64, nb: i64, qa: *u8, qb: *u8, ra: i64, cb: i64, table: *i64) -> i64 |
| 198 | func st_crit05_pm(df: i64) -> i64 |
| 212 | func st_chisq(table: *i64, r: i64, c: i64, out: *i64) -> i64 |
| 255 | func st_corr(xs: *i64, ys: *i64, m: i64) -> i64 |
| 284 | func st_segment_means(vout: *i64, lout: *i64, nb: i64, seg_qid: *u8, tgt_qid: *u8, seg_n: i64, out_n: *i64, out_meanpm: *i64) -> i64 |
| 306 | func st_trend_split(vout: *i64, lout: *i64, nb: i64, qid: *u8, split_usec: i64, out: *i64) -> i64 |
| 335 | func st_triage_rollup(vout: *i64, lout: *i64, nb: i64, wqids: *i64, weights: *i64, nw: i64, t_str: i64, t_cri: i64, out: *i64) -> i64 |
| 356 | func st_stopword(t: *u8) -> i64 |
| 381 | func st_text_themes(vout: *i64, lout: *i64, nb: i64, qid: *u8, terms_out: *i64, freq_out: *i64, cap: i64) -> i64 called by 2: sv2_ins_themesst_term_freq calls 5: ss_tok_tablese_answer_ofss_tok_next2st_stopwordse_seq |
| 424 | func st_term_freq(vout: *i64, lout: *i64, nb: i64, qid: *u8, term: *u8) -> i64 |