# NextStat — High-Performance Statistical Inference Engine # https://nextstat.io > NextStat is a Rust-powered statistical inference engine with Python bindings. > It covers 12+ statistical verticals: HistFactory (HEP), GLM regression, Bayesian > NUTS/MAMS sampling, survival analysis, econometrics, causal inference, hierarchical > models, ordinal regression, PK/PD, EVT, meta-analysis, insurance reserving, churn > analytics, and more. GPU acceleration (CUDA/Metal) and browser-based WASM playground. ## Documentation - [Docs home](https://nextstat.io/docs): Getting started, architecture, API references - [Installation](https://nextstat.io/docs/installation): pip, cargo, source - [Quickstart](https://nextstat.io/docs/quickstart): 5-minute guide with expected outputs and troubleshooting - [HEP Full Workflow Tutorial](https://nextstat.io/docs/hep-tutorial): Comprehensive 1200-line tutorial — workspace construction, all modifier types, MLE fitting, CLs hypothesis testing, upper limits (Brazil band), NP ranking, pulls, correlation matrix, profile likelihood scans, workspace combination, mass scans, GPU acceleration - [Python API](https://nextstat.io/docs/python-api): from_pyhf, fit, hypotest, upper_limit, ranking, scan - [Rust API](https://nextstat.io/docs/rust-api): ns-translate, ns-inference, ns-ad, ns-compute, ns-root - [R Bindings](https://nextstat.io/docs/r-bindings): R bindings via extendr — fit, hypotest, upper_limit, scan, ranking - [CLI](https://nextstat.io/docs/cli): fit, hypotest, upper-limit, scan, report, import, export - [HistFactory](https://nextstat.io/docs/histfactory): Workspace format, modifiers, pyhf compatibility - [GPU](https://nextstat.io/docs/gpu): CUDA/Metal batch toys, differentiable NLL - [Bayesian](https://nextstat.io/docs/bayesian): NUTS sampler, HMC diagnostics - [WASM](https://nextstat.io/docs/wasm): Browser-based inference playground - [Playground: HEP](https://nextstat.io/playground): Brazil band, profile scan, MLE fit, hypo test, GLM — all in WASM - [Playground: Bayes](https://nextstat.io/playground/bayes): NUTS/MAMS sampling in the browser (Eight Schools, GLM, std normal) - [Playground: Pop PK](https://nextstat.io/playground/pk): 1-compartment oral PK tutorial — synthetic data + FOCE/SAEM estimation in WASM - [Inference Server](https://nextstat.io/docs/server): REST API for shared GPU inference - [Differentiable](https://nextstat.io/docs/differentiable): Canonical spec — CUDA zero-copy NLL, profiled q₀/qμ on GPU, envelope theorem gradients ## ML / Data Science - [ML Overview](https://nextstat.io/docs/ml-overview): Terminology bridge for ML engineers - [ML Training](https://nextstat.io/docs/ml-training): SignificanceLoss, SoftHistogram, PyTorch - [MLOps](https://nextstat.io/docs/ml-ops): W&B, MLflow, ranking, Optuna - [Agentic Tools](https://nextstat.io/docs/agentic-tools): OpenAI, LangChain, MCP tool definitions - [NextStat for Claude Science](https://nextstat.io/docs/claude-science): verification oracle for Claude Science's actor-critic reviewer — recompute any LLM-claimed statistic (hazard ratio, p-value, ATE, CLs limit, PopPK parameter) under the 1e-12 parity contract and return a signed validation_report. MCP connector + capability routing table. Machine-readable manifest: https://nextstat.io/nextstat-capabilities.json - [Surrogate Distillation](https://nextstat.io/docs/surrogate-distill): Neural surrogate training - [Arrow / Polars](https://nextstat.io/docs/arrow-polars): Zero-copy columnar interchange - [Differentiable](https://nextstat.io/docs/differentiable): Canonical spec — what is differentiable, CUDA zero-copy NLL, profiled q₀/qμ on GPU, envelope theorem gradients, DifferentiableSession native API, validation (FD error 2.07e⁻⁹), architecture decisions, Phase 2 implicit differentiation ## Statistical Models - [Regression & GLM](https://nextstat.io/docs/regression): Linear, logistic, Poisson, NB, Gamma, Tweedie - [Bayesian Sampling](https://nextstat.io/docs/bayesian): NUTS, MAMS, LAPS (GPU), unified sample() dispatcher, ArviZ integration, any model - [Survival Analysis](https://nextstat.io/docs/survival): Cox PH, Weibull, Log-Normal AFT, Exponential, interval-censored, KM, log-rank - [Hierarchical Models](https://nextstat.io/docs/hierarchical): Random intercepts/slopes, correlated RE, LMM - [Ordinal Regression](https://nextstat.io/docs/ordinal): Ordered logit, ordered probit - [Time Series](https://nextstat.io/docs/timeseries): Kalman filter/smoother, EM, forecasting, simulation - [Econometrics](https://nextstat.io/docs/econometrics): Panel FE, DiD TWFE, Event Study, IV/2SLS - [Causal Inference](https://nextstat.io/docs/causal): AIPW (ATE/ATT), propensity scores, Rosenbaum bounds, E-value - [PK/PD & Pharmacometrics](https://nextstat.io/docs/pkpd): 1/2/3-compartment IV & oral PK, population NLME (FOCE/FOCEI/FO/ITS/IMP/SAEM), PD models (Emax, Sigmoid-Emax, IDR I–IV), VPC, GoF, SCM, NPDE, bootstrap NLME, bioequivalence, CDISC .xpt, NONMEM parity - [NLP for Pharma](https://nextstat.io/docs/pkpd): nextstat-nlp — GLiNER2-based text-to-stats for clinical text extraction (survival records, priors, dosing regimens) - [Volatility Models](https://nextstat.io/docs/python-api): GARCH(1,1), EGARCH(1,1), GJR-GARCH(1,1), Stochastic Volatility - [Competing Risks](https://nextstat.io/docs/survival): Aalen–Johansen CIF, Gray's test, Fine–Gray regression - [EVT](https://nextstat.io/docs/evt): GEV (block maxima), GPD (peaks over threshold) - [Meta-Analysis](https://nextstat.io/docs/meta-analysis): Fixed effects, random effects (DL), I², Q, τ² - [Insurance](https://nextstat.io/docs/insurance): Chain ladder, Mack chain ladder - [Churn Analytics](https://nextstat.io/docs/churn): Retention, uplift, cohort matrix, bootstrap HR - [Profile CI](https://nextstat.io/docs/python-api): Bisection-based profile likelihood CI with warm-start, any LogDensityModel - [Fault Tree Analysis](https://nextstat.io/docs/python-api): CE-IS (multi-level, p~1e-16), vanilla MC (CPU/Metal/CUDA), all failure modes ## Use Cases (Persona Guides) - [For Data Scientists](https://nextstat.io/docs/for-data-scientists): sklearn → NextStat concept translation, Arrow/Polars ingest, SignificanceLoss training - [For Quants & Risk](https://nextstat.io/docs/for-quants): Panel FE, DiD, IV/2SLS, Kalman, SR 11-7 validation - [For Biologists & Pharma](https://nextstat.io/docs/for-biologists): Cox PH, Weibull, PK/PD NLME, GxP validation artifacts - [Glossary](https://nextstat.io/docs/glossary): HEP ↔ DS ↔ Quant ↔ Bio terminology mapping table ## Benchmarks & Validation - [Parity Contract](https://nextstat.io/docs/parity-contract): 7-tier numerical tolerance hierarchy (1e-12 per-bin to 0.05 toy stats), Parity vs Fast mode, Kahan summation, CI integration - [ROOT Comparison](https://nextstat.io/docs/root-comparison): 3-way ROOT vs pyhf vs NextStat comparison — sub-1e-5 on q(μ), timing (37×–880× vs ROOT), root cause analysis of ROOT divergences - [Optimizer Convergence](https://nextstat.io/docs/optimizer): L-BFGS-B vs SLSQP philosophy, best-NLL by default, warm-start for pyhf reproducibility, mismatch scale on large models - [Public Benchmarks](https://nextstat.io/docs/public-benchmarks): Canonical spec for reproducible benchmarks: protocols, correctness gates, environment pinning, artifacts, and suite structure across 6 verticals. - [Benchmark Results](https://nextstat.io/docs/benchmark-results): Published GPU/CPU snapshots with DOI artifacts, replication bundles, and CI-produced archives across HEP, Pharma, Bayesian, ML suites. - [Snapshot Registry](https://nextstat.io/docs/snapshot-registry): All published snapshots and replication bundles — snapshot IDs, CI run links, archive SHA-256 hashes, DOIs, runner environments. - [Validation Report](https://nextstat.io/docs/validation-report): Unified validation artifact (JSON+PDF) with Apex2, dataset SHA-256, model spec, per-suite pass/fail ## Blog - [Numerical Accuracy](https://nextstat.io/blog/numerical-accuracy): 3-way ROOT vs pyhf vs NextStat comparison - [Differentiable Layer](https://nextstat.io/blog/differentiable-layer): How NextStat makes HistFactory differentiable in PyTorch - [Trust Offensive](https://nextstat.io/blog/trust-offensive): Why we publish reproducible benchmarks for scientific software - [End of Scripting Era](https://nextstat.io/blog/end-of-scripting-era): From scripts to benchmark snapshots — abstract, artifact sets (manifest + correctness gates + index), concrete snapshot directory layout, replication as endgame - [Third-Party Replication](https://nextstat.io/blog/third-party-replication): Replication artifact set (snapshot_index.json, replication_report.json, validation pack), schema references, minimal 6-step replication loop, signed reports (GPG/Sigstore) - [Benchmark Snapshots](https://nextstat.io/blog/benchmark-snapshots-ci-artifacts): Snapshot = product artifact set — definitions, anatomy (validation pack + manifest + correctness gates), determinism (bit-identical hashing), CI as publisher, baselines + DOI/Zenodo - [HEP Benchmark Harness](https://nextstat.io/blog/hep-benchmark-harness): Threat model (5 failure modes: model/optimizer/warm-start/environment/reporting mismatch), correctness gates, parameter mapping by name, convergence metadata, pyhf + ROOT/RooFit - [Bayesian Benchmarks](https://nextstat.io/blog/bayesian-benchmarks-ess-per-sec): ESS/sec + health metrics (divergence rate, R̂, E-BFMI), correctness gates (NUTS quality smoke + SBC), runnable commands, cargo bench - [Pharma Benchmarks](https://nextstat.io/blog/pharma-benchmarks-pk-nlme): Threat model (6 failure modes), Apex2 pharma reference gate, seed harness (run.py + suite.py), correctness gates, scaling protocols - [JAX Compile vs Execution](https://nextstat.io/blog/jax-compile-vs-execution): Two-regime measurement (TTFR + warm throughput), component timings (t_import, t_first_call, t_second_call, t_steady_state), 3 cache policy modes - [Unbinned Event-Level Analysis](https://nextstat.io/blog/unbinned-event-level-analysis): Extended unbinned likelihood, PDF catalog, EventStore, resonance search workflow - [Compiler vs Hybrid GPU Fits](https://nextstat.io/blog/compiler-vs-hybrid-gpu-fits): MoreFit (symbolic JIT) vs NextStat (CUDA kernels + ONNX flows + reverse-mode AD) - [NUTS Progressive Sampling](https://nextstat.io/blog/nuts-progressive-sampling): NUTS v10 — progressive sampling at top-level tree join, ESS/leapfrog diagnostic, reproducible multi-seed benchmarks vs CmdStan 2.38, 3.2× ESS/sec on hierarchical posteriors ## Demos - [Physics Assistant](https://nextstat.io/docs/physics-assistant): End-to-end demo — ROOT ingest → anomaly scan → discovery p-values → CLs limits → plot artifacts. Local, server, and Docker transport modes. ## Project - [White Paper](https://nextstat.io/docs/whitepaper): Technical overview — motivation, architecture, inference algorithms, validation methodology, scope, performance highlights - [Changelog](https://nextstat.io/docs/changelog): Release history ## Key facts - Version: 0.10.1 - Language: Rust core + Python (PyO3) bindings + R (extendr) bindings - License: AGPL-3.0-or-later OR LicenseRef-Commercial - Install: pip install nextstat - GPU backends: CUDA (f64), Metal (f32) — unified device="cpu"|"cuda"|"metal" dispatch - Interpolation: Code4/Code4p (default), Code1/Code0 (HistFactory/pyhf compat) - Optimizer: L-BFGS-B with reverse-mode AD - Formats: pyhf JSON, HS3 v0.2 (ROOT 6.37+), HistFactory XML, Arrow IPC, Parquet, CDISC .xpt, ROOT TTree - pyhf parity: 7-tier tolerance contract (1e-12 per-bin to 0.05 toy stats) - Performance: 37x-880x faster than ROOT/RooFit on profile scans - Agentic tools: 31 tools (HEP + GLM + Bayesian + Survival + Econometrics + Causal + Kalman + Meta + Churn + Insurance + Pharma + Reliability + Ads) - IDE stubs: _core.pyi (2900+ lines) — full TypedDict returns, model signatures, function types for PyCharm/VS Code/Pylance/pyright ## Python Submodules (41 lazy-loaded) - **nextstat** — core: fit, hypotest, profile_scan, upper_limit, ranking, sample, cls_curve + 20 model classes - **nextstat.remote** — GPU inference server client: fit, ranking, batch_fit, batch_toys, model pool, health - **nextstat.tools** — 31 agentic tools: OpenAI function calling, LangChain StructuredTool, MCP protocol - **nextstat.bayes** — Bayesian sampling: NUTS, MAMS, LAPS (GPU), ArviZ InferenceData export - **nextstat.glm** — GLM: linear, logistic, Poisson, negative binomial, robust SE, cross-validation - **nextstat.survival** — Survival: Cox PH, Weibull, Log-Normal AFT, Exponential, Schoenfeld residuals, PH test - **nextstat.econometrics** — Panel FE (1/2-way HDFE), DiD TWFE, staggered DiD, event study, IV/2SLS - **nextstat.causal** — AIPW (ATE/ATT), propensity scores - **nextstat.ordinal** — Ordered logit/probit - **nextstat.hier** — Hierarchical/mixed models - **nextstat.timeseries** — Kalman filter/smoother/EM/forecast/simulate - **nextstat.volatility** — GARCH(1,1), EGARCH(1,1), GJR-GARCH(1,1), Stochastic Volatility - **nextstat.ode** — ODE solvers: RK4, LSODA (stiff auto-switching), DDE, forward sensitivity analysis - **nextstat.torch** — PyTorch: SignificanceLoss, SoftHistogram, differentiable NLL, signal_jacobian - **nextstat.distill** — Neural surrogate distillation: Sobol sampling, MLP training, NPZ/Parquet export - **nextstat.gym** — Gymnasium RL env: HistFactoryEnv with Z₀/qμ/NLL rewards, Stable Baselines3 compatible - **nextstat.sklearn** — sklearn wrappers: NextStatLinearRegression, LogisticRegression, PoissonRegression - **nextstat.mlops** — MLOps: metrics_dict() for W&B/MLflow, significance_metrics(), StepTimer - **nextstat.interpret** — ML interpretability: rank_impact() (feature importance for HEP systematics) - **nextstat.viz** — Visualization: matplotlib plotting (pulls, ranking, CLs, profile, correlation) - **nextstat.viz_render** — Pure Rust SVG renderer: 17 plot types, 4 themes, sub-millisecond - **nextstat.ppc** — Posterior predictive checks: GLM, NegBin, Ordinal - **nextstat.missing** — Missing data: drop_rows, impute_mean policies - **nextstat.formula** — R-style formula parser: y ~ x1 + x2 + region, design matrices, categorical encoding - **nextstat.robust** — Robust statistics: Huber M-estimator, HC0-HC3 standard errors - **nextstat.summary** — Descriptive statistics - **nextstat.panel** — Panel data convenience wrappers - **nextstat.data** — Toy data generators - **nextstat.arrow_io** — Arrow/Polars zero-copy I/O - **nextstat.unbinned** — Unbinned model helpers - **nextstat.report** — Publication-quality matplotlib report renderer - **nextstat.validation_report** — Audit-ready PDF validation report (21 CFR Part 11) - **nextstat.audit** — Workspace audit - **nextstat.trex_config** — TRExFitter .config parser/importer - **nextstat.analysis** — Preprocessing: smoothing, pruning, symmetrization, hygiene checks - **nextstat.ads** — Ads/marketing: BetaBinomialModel, DelayCorrectionModel, hill(), adstock_geometric(), weekly Kalman builders - **nextstat.bayes_design** — Bayesian trial design: A/B sample size calculator, power analysis, sequential testing (O'Brien-Fleming, Pocock), CUPED - **nextstat.hep** — HEP measurement combination: GVM (scalar), build_measurement_combination_spec(), calibration, campaign studies - **nextstat.m15_report** — ICH M15 regulatory reporting: assessment-table, MAP, MAR, profile-diff, bundle with jurisdiction profiles - **nextstat.infer** — Inference dispatch helpers - **nextstat.sample** — Sampling utilities ## New in 0.10.1 - CUDA WALNUTS sampling — GPU leapfrog via CudaWalnutsPotential trait (feature-gated, diagonal metric) - HEP stable-surface matrix — 141-entry surface matrix with validation bundle - HistFactory + HEPData stable-surface gates in release-candidate workflow - Release gate scripts: local wheelhouse install (no PyPI during pre-release) - Apex2 prerelease gate governance/performance split (exit codes 20/21/22) - pharma_fit cross-platform tolerance — structural-only comparison for SAEM outputs ## New in 0.10.0 - ICH M15 stable reporting surface — assessment-table, MAP, MAR, profile-diff, bundle - Ads-native conversion modeling — BetaBinomialModel, DelayCorrectionModel, hill, adstock - Ads + weekly time-series stable-surface gate and benchmark harness - GVM stable-first verification lane — scalar measurement combination - Bayesian PyMC/CmdStan backend provisioning hardened - MAMS stable CPU defaults retuned for repeatability-grade convergence - Host-backed benchmark runners: local wheels without PyPI deps ## New in 0.9.9 - TRExFitter template morphing (ghost samples) — GHOST Type with Template: POI:value, Lagrange polynomial signal templates - viz PNG/PDF rendering fix — png/pdf features were silently broken since 0.9.8 ## New in 0.9.8 - ns-cli-py standalone CLI Python package - nextstat-nlp remote workflow runner for reproducible NLP pipeline verification - Validation-pack pharma determinism fix - pip extras: added missing [all] extra - Benchmark artifact sanitization (replaced internal hostnames/paths) ## New in 0.9.7 - PD models Python API: emax_predict(), sigmoid_emax_predict(), idr_simulate() + NLL functions - FO / ITS / IMP estimation methods for population PK - SAEM covariance step (sandwich SE, RSE%, condition number) - NPDE diagnostics (pk_npde()) - 3-compartment PK models (IV bolus + oral) with SAEM support - Per-subject dosing for FOCE/SAEM/VPC/GoF - Bootstrap NLME with percentile/BCa confidence intervals - SCM (Stepwise Covariate Modeling) Python API - CDISC .xpt reader/writer for FDA-submission datasets - NONMEM parity whitepaper + benchmark suite - IQ/OQ/PQ validation protocol v2 (85 test cases) - Bioequivalence testing (TOST, RSABE) - MAP estimation, Monte Carlo trial simulation, dose optimization - ODE-based PK (transit compartments, Michaelis-Menten, TMDD) - nextstat-nlp 0.2.0–0.2.1: GLiNER2-based clinical text extraction (survival, priors, dosing regimens) - EGARCH/GJR-GARCH Python API - LAPS GLM expansion (linear, Poisson, NegBin, composed logistic) - NUTS Pathfinder dense metric initialization - NUTS vs CmdStan benchmark ## New in 0.9.6 - Pure Rust visualization engine (ns-viz-render) — 17 plot types, SVG/PDF/PNG - Unified Python API with runtime dispatch (device="cpu"|"cuda"|"metal") - TypedDict return types (~25 structured definitions) - LAPS Metal backend for Apple Silicon (M1–M5) - BCa confidence interval engine - Competing risks (Aalen-Johansen, Gray's test, Fine-Gray) - EGARCH(1,1) and GJR-GARCH(1,1) - Group sequential testing (O'Brien-Fleming, Pocock, Lan-DeMets) - Interval-censored Weibull AFT - Cabinetry config reader - Zero-JIT-Tax blog post: https://nextstat.io/blog/zero-jit-tax ## New in 0.9.5 - PyPI wheel coverage fix — pip install nextstat works on all major platforms - manylinux_2_17 compatibility ## Optional: full docs For full documentation content see: https://nextstat.io/llms-full.txt