statinfer
    Preparing search index...

    statinfer

    statinfer

    CI

    Statistical inference for modern JavaScript and TypeScript.

    statinfer provides classic hypothesis tests with one consistent result format, full TypeScript types, and results checked against SciPy and statsmodels. It has no runtime dependencies, and bundlers only include the tests you import.

    Try every test in your browser at statinfer.vercel.app, with plain-language explanations of the results.

    npm install statinfer
    

    Requires Node.js 22 or newer.

    import { tTest, summarize } from "statinfer";

    const result = tTest({ x: [5.1, 4.9, 5.6, 5.8, 6.0, 5.5, 5.3, 6.2], mu: 5 });
    console.log(summarize(result));
    One-sample t-test
    =================
    statistic 3.504
    p-value 0.009944
    df 7
    estimate 5.55
    95% CI [5.179, 5.921]
    alternative two-sided
    Function What it tests
    tTest Means: one-sample, paired, or two-sample (Welch by default, or pooled)
    proportionTest Proportions: one-sample, or the difference between two
    chiSquareTest Tables of counts: independence, or goodness-of-fit
    correlationTest Association: Pearson or Spearman
    anova Means of three or more groups (one-way)
    fishersExactTest 2×2 tables, including small counts

    Every test takes a single options object and returns a TestResult:

    Field Meaning
    method The name of the test
    statistic The test statistic (t, z, chi-square, F, …)
    pValue The p-value
    df Degrees of freedom: a number, a pair, or null
    estimate The estimated effect, or null
    confidenceInterval [lower, upper], or null
    confidenceLevel For example 0.95, or null
    alternative "two-sided", "less", "greater", or null

    Full details of every function and option are in the API documentation.

    Fields that don't apply to a test are null, so every result has the same shape. One-sided tests can have an infinite interval end; note that JSON.stringify saves Infinity as null.

    flowchart TD
      A{What kind of data?} -->|Measurements, like heights or scores| B{What are you comparing?}
      A -->|Counts, or yes/no outcomes| C{What are you comparing?}
      B -->|One group with a target value| T1[tTest: one-sample]
      B -->|The same subjects measured twice| T2[tTest: paired]
      B -->|Two separate groups| T3[tTest: Welch]
      B -->|Three or more groups| AN[anova]
      B -->|Whether two measurements move together| CO[correlationTest]
      C -->|One proportion with a target value| P1[proportionTest: one sample]
      C -->|Two groups' proportions| P2{Small counts?}
      P2 -->|No| P3[proportionTest: two samples]
      P2 -->|Yes| F[fishersExactTest]
      C -->|A table of counts| TB{A 2×2 table with small counts?}
      TB -->|No| CS[chiSquareTest: independence]
      TB -->|Yes| F
      C -->|Counts against expected proportions| GF[chiSquareTest: goodness-of-fit]
    

    "Small counts" roughly means fewer than 10 successes or failures in a group, or any cell of a table below about 5. There's also an interactive version of this guide on the demo site.

    Every test is checked against SciPy or statsmodels to about 10 decimal places. The reference values live in test/fixtures and are generated by scripts/generate_fixtures.py.

    • wilcoxonTest: rank-sum and signed-rank
    • kruskalWallisTest
    • linearRegression
    • Tukey HSD post-hoc tests for anova
    • Conditional odds ratio and exact confidence interval for fishersExactTest
    • Wilson confidence intervals for proportionTest
    pnpm install
    pnpm check # run all checks (lint, build, typecheck, test, docs)
    pnpm test # run tests
    pnpm lint # check code style
    pnpm typecheck # type-check the tests
    pnpm docs:api # build API docs into api-docs/
    pnpm fixtures # regenerate reference values (needs uv)

    Contributions are welcome! See CONTRIBUTING.md for how to set up, test and submit changes, and SECURITY.md for reporting vulnerabilities.

    Apache-2.0