This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
rMVPA is an R package for Multivoxel Pattern Analysis (MVPA) of neuroimaging data. It provides infrastructure for machine learning analyses on neuroimaging datasets, supporting both programmatic R usage and command-line interfaces.
# Install package locally
R CMD INSTALL .
# Run R CMD check
R CMD check .
# Run specific tests
Rscript -e "testthat::test_file('tests/testthat/test_mvpa_searchlight.R')"
# Run all tests
Rscript -e "testthat::test_local()"
# Build documentation
Rscript -e "devtools::document()"
# Build vignettes
Rscript -e "devtools::build_vignettes()"
# Install with dependencies
Rscript -e "devtools::install(dependencies = TRUE)"
# Run lintr (if available)
Rscript -e "lintr::lint_package()"
# Check code coverage
Rscript -e "covr::package_coverage()"
S3 Object System: The package uses S3 classes extensively for model types (mvpa_model
, rsa_model
, contrast_rsa_model
, etc.) with generic functions (train_model
, predict_model
, performance
).
Model Registry: All machine learning models are stored in the MVPAModels
environment (R/classifiers.R). Models follow a standard interface:
type
: "Classification" or "Regression"library
: Required packagesparameters
: Tunable hyperparametersgrid
: Function to generate parameter gridsfit
: Model training functionpredict
: Prediction functionprob
: Probability estimation (for classification)
Analysis Workflows: Two main analysis approaches:
Searchlight: Sliding sphere analysis across the brain
Cross-validation Infrastructure: Custom cross-validation system in R/crossval.R supports various schemes (k-fold, blocked, bootstrap).
mvpa_dataset
: Core data container with neuroimaging data, labels, and metadatamvpa_design
: Experimental design specificationModel-specific designs: rsa_design
, manova_design
, feature_rsa_design
Model Types:
MS-ReVE: Multi-Scale Representational Variance Explained (in contrast_rsa_model.R
)
Feature Selection: Modular system supporting F-test, categorical scores, and custom methods
Performance Metrics: Extensible performance evaluation supporting accuracy, AUC, RMSE, R², and custom metrics
Caret Removal: The package is undergoing a major refactoring to remove the caret
dependency (see caret_removal_plan.md
). Key changes:
- Replacing caret::train
with custom tuning loops using rsample
and yardstick
- Model loading now exclusively uses the internal MVPAModels
registry
- Performance metrics transitioning from caret
to yardstick
functions
Current branch remaining-codex-integration
contains work-in-progress changes.
The scripts/
directory contains CLI tools:
- MVPA_Searchlight.R
: Searchlight analysis
- MVPA_Regional.R
: Regional/ROI analysis
- MVPA_Cluster.R
: Cluster-based analysis
- MVPA_Predict.R
: Prediction on new data
tests/testthat/
helper-mock_cv_spec.R
neuroim2
, neurosurf
(custom packages by the same author)rsample
(resampling), yardstick
(metrics) from tidymodels ecosystemdplyr
, purrr
, tibble
future
, future.apply
, furrr
glmnet
, sda
, randomForest
, e1071
The package uses a centralized model registry called MVPAModels
(an environment in R/classifiers.R
). All built-in models are registered here with a consistent structure:
type
: "Classification" or "Regression"library
: Required R packages for the modellabel
: Display nameparameters
: data.frame of tunable parametersgrid
: Function to generate parameter tuning gridfit
: Function to train the modelpredict
: Function for predictionsprob
: Function for class probabilities (classification only)
Loading models: Use load_model(name)
to retrieve a model specification
register_mvpa_model(name, spec)
to add new modelspurrr
future
frameworkfutile.logger
for debuggingR/contrast_rsa_model.R
(not contrast_rsa.R
)caret
- all model management is handled internallyR/caret_models.R
sda
→ sda_notune
, glmnet
→ glmnet_opt
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.