Skip to contents

Run a separate MVPA analysis for multiple disjoint regions of interest.

Usage

run_regional(model_spec, region_mask, ...)

Arguments

model_spec

A mvpa_model instance containing the model specifications

region_mask

A NeuroVol or NeuroSurface object where each region is identified by a unique integer

...

Extra arguments passed to specific regional analysis methods

Value

A named list containing:

performance

Performance metrics for each region

prediction_table

Predictions for each region

fits

Model fits if return_fits=TRUE

Examples

# \donttest{
  # Generate sample dataset (3D volume with categorical response)
  dataset <- gen_sample_dataset(
    D = c(10,10,10),       # Small 10x10x10 volume
    nobs = 100,            # 100 observations
    nlevels = 3,           # 3 classes
    response_type = "categorical",
    data_mode = "image",
    blocks = 3             # 3 blocks for cross-validation
  )
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'i' in selecting a method for function '[<-': could not find function "coords"
  
  # Create region mask with 5 ROIs
  region_mask <- NeuroVol(
    sample(1:5, size=length(dataset$dataset$mask), replace=TRUE),
    space(dataset$dataset$mask)
  )
#> Error in NeuroVol(sample(1:5, size = length(dataset$dataset$mask), replace = TRUE),     space(dataset$dataset$mask)): could not find function "NeuroVol"
  
  # Create cross-validation specification
  cval <- blocked_cross_validation(dataset$design$block_var)
  
  # Load SDA classifier (Shrinkage Discriminant Analysis)
  model <- load_model("sda_notune")
  
  # Create MVPA model
  mspec <- mvpa_model(
    model = model,
    dataset = dataset$dataset,
    design = dataset$design,
    model_type = "classification",
    crossval = cval,
    return_fits = TRUE    # Return fitted models
  )
#> Error in assert_that(!is.null(model$fit)): could not find function "assert_that"
  
  # Run regional analysis
  results <- run_regional(mspec, region_mask)
#> Error in UseMethod("run_regional"): no applicable method for 'run_regional' applied to an object of class "c('vector_rsa_model', 'model_spec', 'list')"
  
  # Access results
  head(results$performance)           # Performance metrics
#> # A tibble: 3 × 3
#>   roinum mse       correlation
#>    <int> <list>    <list>     
#> 1      1 <dbl [1]> <dbl [1]>  
#> 2      2 <dbl [1]> <dbl [1]>  
#> 3      3 <dbl [1]> <dbl [1]>  
  head(results$prediction_table)      # Predictions
#> NULL
  first_roi_fit <- results$fits[[1]]  # First ROI's fitted model
# }