Expand description
BIDS Statistical Models implementation.
This crate implements the BIDS-StatsModels
specification for defining reproducible neuroimaging analysis pipelines as
declarative JSON documents. It corresponds to PyBIDS’ bids.modeling module.
§Overview
A BIDS Stats Model defines a directed acyclic graph (DAG) of analysis nodes, each operating at a specific level of the BIDS hierarchy (run, session, subject, dataset). Data flows from lower levels to higher levels through edges, with contrasts propagating upward.
§Components
-
StatsModelsGraph— The top-level model graph loaded from a JSON file. Validates structure, wires edges between nodes, and executes the full analysis pipeline. Can export to Graphviz DOT format. -
StatsModelsNode— A single analysis node with a statistical model specification, variable transformations, contrasts, and dummy contrasts. Nodes group data by entity values and produceStatsModelsNodeOutputs. -
TransformSpecandapply_transformations()— Thepybids-transforms-v1transformer implementing Rename, Copy, Factor, Scale, Threshold, Select, Delete, Replace, Split, Concatenate, Orthogonalize, Lag, and more. -
HrfModel,spm_hrf(),glover_hrf()— Hemodynamic response function kernels (SPM and Glover canonical forms with optional time and dispersion derivatives). Uses a pure-Rustgammalnimplementation matching SciPy’s cephes to machine epsilon. -
auto_model()— Automatically generates a BIDS Stats Model JSON for each task in a dataset, with Factor(trial_type) at the run level and pass-through nodes at higher levels. -
GlmSpec,MetaAnalysisSpec— Statistical model specifications with design matrix construction, VIF computation, and formatted output.
§Example
use bids_modeling::StatsModelsGraph;
let mut graph = StatsModelsGraph::from_file(
std::path::Path::new("model-default_smdl.json")
).unwrap();
graph.validate().unwrap();
println!("DOT graph:\n{}", graph.write_graph());
// Execute the model
let outputs = graph.run();
for output in &outputs {
println!("Node: {}, Contrasts: {}", output.node_name, output.contrasts.len());
}Re-exports§
pub use auto_model::auto_model;pub use graph::StatsModelsGraph;pub use hrf::HrfModel;pub use hrf::compute_regressor;pub use hrf::glover_hrf;pub use hrf::spm_hrf;pub use node::ContrastInfo;pub use node::StatsModelsEdge;pub use node::StatsModelsNode;pub use node::StatsModelsNodeOutput;pub use node::build_groups;pub use spec::GlmSpec;pub use spec::MetaAnalysisSpec;pub use spec::Term;pub use spec::compute_vif;pub use spec::dummies_to_vec;pub use spec::format_correlation_matrix;pub use spec::format_design_matrix;pub use transformations::TransformSpec;pub use transformations::TransformerManager;pub use transformations::apply_transformations;pub use transformations::expand_wildcards;
Modules§
- auto_
model - Automatic BIDS Stats Model generation.
- graph
- BIDS-StatsModels directed acyclic graph.
- hrf
- Hemodynamic response functions for fMRI statistical modeling.
- node
- Analysis nodes and edges in a BIDS-StatsModels graph.
- spec
- Statistical model specifications for BIDS-StatsModels.
- transformations
- Variable transformations from the
pybids-transforms-v1specification.