Dataset Viewer
Auto-converted to Parquet Duplicate
Search is not available for this dataset
retrieval_hit@5
float64
stat_correctness
float64
injection_guard
float64
tool_call_accuracy
float64
1
1
1
0.8

StatAgent

Typing SVG

Code Dataset Author

R Shiny Python FastAPI MCP Groq Docker

Ask a plain-English question about experiment or manufacturing data. The agent retrieves FDA and PubMed evidence, runs validated R statistics, states the uncertainty, and proposes the next experiment for a human to approve.

Features How it works Results Documentation Disclaimer Author

Screen recording of the app: a drift question, the answer with citations, the R tool trace and the approval queue

Recorded from the running app on the built-in SECOM dataset (first sample question).

125 8 / 8 4 / 4 16
cited regulatory and PubMed passages retrieval hit@5 on the eval set statistical checks passing automated tests (9 R, 7 Python)

Features

Capability Detail
Statistical tools in R Control-chart drift with bootstrap changepoint CI, four-parameter dose-response (EC50 CI), mixed-model batch variance, power and factorial design
Retrieval with citations BM25 and LSA hybrid over 21 CFR Parts 11, 211 and 820 and PubMed abstracts; answers cite passage ids
Human approval gate The agent cannot run experiments; proposals wait in a queue for Approve or Reject
Audit trail Every question, tool call and decision is stored in SQLite with a hash of each tool result
MCP server The same tools are exposed as typed MCP tools for any MCP client
Resilience Model fallback, retries, prompt-injection sanitiser, and a replayed saved run if the LLM is rate-limited

How it works

Architecture: Shiny UI to FastAPI agent, which calls the Groq LLM, the RAG index and the R stats tools; proposals go to human approval and the audit log

Results

Evaluation scores

Measured with python eval/run_eval.py. The eval sets are small (8 retrieval queries, 4 statistical checks, 5 tool-call questions; one tool-call run hit the Groq free-tier rate limit and is counted as a miss), so treat the scores as a regression guard, not a benchmark.

Documentation

Getting started
pip install -r requirements.txt
Rscript -e 'install.packages(c("shiny","bslib","httr2","commonmark","DT","ggplot2","lme4","drc","pwr","plumber","jsonlite"))'
cp .env.example .env            # add GROQ_API_KEY
Rscript r/run_api.R &           # stats tools, port 8001
python -m uvicorn statagent.api:app --port 8000 &
Rscript scripts/run_app.R       # UI, port 7860

Docker: docker build -t statagent . && docker run -p 7860:7860 -e GROQ_API_KEY=... statagent

Engineering decisions
Decision Reason
Statistics in R, orchestration in Python Reference-quality packages (lme4, drc) stay the single source of numbers; the LLM never computes statistics
Residual bootstrap for the changepoint CI Resampling raw values would destroy the shift being estimated
BM25 and LSA instead of a neural embedder Small corpus, no model download, runs on a laptop CPU
Tools return units notes An early run misread the shift size; explicit units fixed it
Real public data only Synthetic data is used only in tests with a known truth
Limitations
  • The statistical tools run on three built-in datasets; upload mode is not implemented.
  • The Bayesian (brms) model from the plan is not included.
  • The corpus holds U.S. regulations and PubMed abstracts, not the ICH guideline texts.
  • SECOM sensors are anonymised, so a detected drift has no physical explanation here.
  • There is no hosted demo: Hugging Face now requires a PRO plan for Docker Spaces, so the app is run locally or with the Dockerfile. The Hugging Face dataset repository is a mirror of the code.
  • The free Groq tier limits tokens per minute; a saved example run is shown when it is exceeded.
  • No automated check that the model's prose matches the tool numbers; review answers against the Tool trace tab.
Configuration
Variable Default Purpose
GROQ_API_KEY none Required for live answers
GROQ_MODEL openai/gpt-oss-120b Primary model; gpt-oss-20b is the fallback
R_API_URL http://127.0.0.1:8001 R plumber service
STATAGENT_API http://127.0.0.1:8000 Agent service used by the UI
STATAGENT_DB audit.db SQLite audit and proposal store
API

POST /ask, GET /datasets, GET /series/{dataset}/{column}, GET /proposals, POST /proposals/{id}, GET /audit, GET /health. MCP: python -m statagent.mcp_server.

Tests and project structure
cd r/tests && Rscript -e 'testthat::test_dir(".")'   # includes known-truth coverage tests
python -m pytest tests
python eval/run_eval.py --offline
r/R/            drift, dose-response, mixed model, design
r/plumber.R     HTTP wrapper for the R tools
statagent/      rag, tools, agent loop, audit, FastAPI, MCP server
app/app.R       Shiny UI
corpus/         fetched 21 CFR and PubMed passages
data/           small real datasets (see data/README.md)
eval/           evaluation harness

Disclaimer

A portfolio demonstration. It is not validated for GxP use, and its output is not regulatory or medical advice. Do not enter confidential data. A qualified statistician should review any result before it is acted on.

Author

mnoorchenar mnoorchenar
Data science, biostatistics and AI engineering
GitHub Hugging Face
Downloads last month
79