Bayesian EC50 Curve Fitting Tool
A high-performance Rust implementation for fitting dose-response curves using Bayesian MCMC methods. Supports both Metropolis-Hastings and Stan backends with an interactive terminal interface for real-time parameter exploration.
- Bayesian EC50 curve fitting using 4-parameter logistic (LL4) model
- Multiple MCMC backends: Custom Metropolis-Hastings and Stan/BridgeStan
- Multi-chain MCMC with convergence diagnostics (R-hat statistics)
- JSON configuration system for reproducible analysis
- Web API server for remote curve fitting
- Real-time plotting with ratatui-based TUI
- Interactive parameter editing with live curve updates
- Multiple plot modes: dose-response curves, MCMC traces, posterior distributions, diagnostics
- Zoom, pan, and navigation controls
- Live confidence interval visualization
- High-quality plots: dose-response curves with 95% confidence intervals
- MCMC diagnostics: trace plots, posterior distributions, log-likelihood traces
- Multiple output formats: PNG plots, CSV/JSON results
- Convergence assessment with detailed R-hat reporting
- Rust 1.70+ (install via rustup)
- Stan (for Stan backend, automatically downloaded)
git clone https://github.com/nithishbn/fit-rs.git
cd fit-rs
cargo build --release
cargo install --path .
For production deployment or containerized environments:
# Using Docker Compose (recommended)
docker-compose up --build
# Using Docker directly
docker build -t fitrs-htmx-server .
docker run -p 3001:3000 fitrs-htmx-server
Docker Features:
- Multi-stage optimized builds
- Non-root user security
- Built-in health checks
- Production-ready with Nginx reverse proxy
- Kubernetes deployment support
For detailed production configuration, monitoring, scaling, and troubleshooting, see the comprehensive Docker deployment guide.
fit-rs --generate-config
This creates parameters.json
with sensible defaults.
Create a CSV file with concentration
and response
columns:
concentration,response
1000,0.95
5000,1.05
10000,1.15
25000,1.25
50000,1.30
# Basic fitting with plots
fit-rs --config parameters.json
# Interactive terminal interface
fit-rs --config parameters.json --interactive
# Use Stan backend for better sampling
fit-rs --config parameters.json --backend stan
The tool uses JSON configuration for all parameters:
{
"input": {
"file": "data/data.csv",
"output_dir": "ec50_output"
},
"mcmc": {
"samples": 4000,
"burnin": 1000,
"chains": 4,
"sigma": 0.05,
"backend": "mh"
},
"priors": {
"emin": {
"type": "normal",
"mean": 0.98,
"std": 0.1,
"description": "Lower asymptote"
},
"emax": {
"type": "normal",
"mean": 1.31,
"std": 0.1,
"description": "Upper asymptote"
},
"ec50": {
"type": "normal",
"mean": 4.0,
"std": 1.0,
"description": "EC50 on log10 scale"
},
"hillslope": {
"type": "normal",
"mean": 1.0,
"std": 1.0,
"description": "Hill slope"
}
}
}
# Override specific parameters
fit-rs --samples 8000 --chains 6 --backend stan
# Override input/output
fit-rs --file my_data.csv --output results/
# Validate configuration
fit-rs --validate
# Show current configuration
fit-rs --show-config
Launch the interactive interface with:
fit-rs --interactive
- Plot Modes:
[d]
Dose-Response,[t]
MCMC Traces,[p]
Posteriors,[i]
Diagnostics,[e]
Parameter Editor - Navigation:
[k/j]
or[↑/↓]
select parameters or pan,[←/→]
pan horizontally - Zoom:
[+/-]
zoom in/out,[r]
reset view - Parameter Editing:
[e]
mode →[Enter]
edit →[f]
refit curve - Help:
[h]
toggle help,[q]
quit
- Edit prior distributions in real-time
- See immediate curve updates
- Refit with new parameters using
[f]
- Compare different parameter scenarios
Launch the interactive web interface:
# Build and run the HTMX server
cargo build --bin htmx-server
cargo run --bin htmx-server
Server URL: http://localhost:3001
Features:
- Drag-and-drop file upload: CSV data and JSON configuration
- Interactive parameter editing: Real-time form updates
- Live curve fitting: HTMX-powered dynamic updates
- Responsive design: Works on desktop and mobile
- Download results: Export fitted parameters as CSV/JSON
Usage Workflow:
- Upload CSV data file (concentration, response columns)
- Upload JSON configuration file or use defaults
- Adjust priors and MCMC settings in the web form
- Run curve fitting and view results
- Download results
Start the JSON API server:
fit-server
API Endpoints:
- POST /fit: Upload CSV data and get fitted curves
- GET /health: Health check
- POST /fit-with-config: Fit with custom JSON configuration
Example Usage:
curl -X POST -F "[email protected]" http://localhost:3000/fit
- Fast, lightweight implementation
- Good for quick analysis and testing
- Built-in adaptive proposal tuning
- High-quality NUTS sampling
- Better convergence for complex models
- Automatic compilation and caching
- Superior for final analysis
# Use Stan backend
fit-rs --backend stan
Response = Emin + (Emax - Emin) / (1 + (concentration/EC50)^(-hillslope))
Where:
- Emin: Lower asymptote (baseline response)
- Emax: Upper asymptote (maximum response)
- EC50: Half-maximal effective concentration
- hillslope: Steepness of the dose-response curve
All parameters use Normal priors by default, configurable via JSON:
- Flexible prior specification (Normal, Uniform, etc.)
- Informative or non-informative priors
- Parameter bounds support
The tool generates comprehensive output in the specified directory:
- dose_response_curve.png: Main fitted curve with confidence bands
- mcmc_traces.png: Parameter convergence diagnostics
- posterior_distributions.png: Parameter uncertainty
- log_likelihood_trace.png: Sampling efficiency
- coefficients.csv: Fitted parameters summary
- coefficients.json: Detailed results with diagnostics
- Multi-threaded: Parallel MCMC chains
- Memory efficient: Streaming data processing
- Fast compilation: Stan model caching
- Large datasets: Efficient for 1000+ data points
- R-hat statistics: Automated convergence assessment
- Effective sample size: Sampling efficiency metrics
- Visual diagnostics: Trace plots and posterior distributions
- Multi-chain comparison: Between/within chain variance analysis
# Generate config and run analysis
fit-rs --generate-config
fit-rs
# Use Stan with more samples
fit-rs --backend stan --samples 8000 --chains 6
# Launch interactive interface
fit-rs --interactive
# Start web server
fit-server &
# Submit job via API
curl -X POST -F "[email protected]" http://localhost:3000/fit
MIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
If you use fit-rs in your research, please cite:
@software{fit-rs,
title = {fit-rs: Bayesian EC50 Curve Fitting Tool},
author = {Nithish Narasimman},
url = {https://github.com/nithishbn/fit-rs},
year = {2024}
}
- Issues: GitHub Issues
- Discussions: GitHub Discussions
fit-rs - Fast, accurate, and interactive Bayesian curve fitting for dose-response analysis.