Create an MVPA Model
mvpa_model.Rd
Create an MVPA model based on a caret-based classification or regression model.
Usage
mvpa_model(
model,
dataset,
design,
model_type = c("classification", "regression"),
crossval = NULL,
feature_selector = NULL,
tune_grid = NULL,
tune_reps = 15,
performance = NULL,
class_metrics = TRUE,
compute_performance = TRUE,
return_predictions = TRUE,
return_fits = FALSE
)
Arguments
- model
A caret-based classification or regression model.
- dataset
An `mvpa_dataset` instance.
- design
An `mvpa_design` instance.
- model_type
A character string indicating the problem type: "classification" or "regression".
- crossval
An optional `cross_validation` instance.
- feature_selector
An optional `feature_selector` instance.
- tune_grid
An optional parameter tuning grid as a `data.frame`.
- tune_reps
The number of replications used during parameter tuning. Only relevant if `tune_grid` is supplied.
- performance
An optional custom function for computing performance metrics.
- class_metrics
A logical flag indicating whether to compute performance metrics for each class.
- compute_performance
A
logical
indicating whether to compute and store performance measures for each voxel set (defaults to TRUE).- return_predictions
A
logical
indicating whether to return row-wise predictions for each voxel set (defaults to TRUE).- return_fits
A
logical
indicating whether to return the model fit for each voxel set (defaults to FALSE).
Details
If `performance` is supplied, it must be a function that takes one argument and returns a named list of scalar values. The argument the function takes is a class deriving from `classification_result` appropriate for the problem at hand. See example below.
Examples
mod <- load_model("sda")
traindat <- neuroim2::NeuroVec(array(rnorm(6*6*6*100), c(6,6,6,100)), neuroim2::NeuroSpace(c(6,6,6,100)))
mask <- neuroim2::LogicalNeuroVol(array(rnorm(6*6*6)>-.2, c(6,6,6)), neuroim2::NeuroSpace(c(6,6,6)))
mvdset <- mvpa_dataset(traindat,mask=mask)
#> Error in assert_that(inherits(train_data, "NeuroVec")): could not find function "assert_that"
design <- data.frame(fac=rep(letters[1:4], 25), block=rep(1:10, each=10))
cval <- blocked_cross_validation(design$block)
mvdes <- mvpa_design(design, ~ fac, block_var=~block)
#> Error in mvpa_design(design, ~fac, block_var = ~block): argument "y_train" is missing, with no default
custom_perf <- function(result) {
c(accuracy=sum(result$observed == result$predicted)/length(result$observed))
}
mvpmod <- mvpa_model(mod, dataset=mvdset, design=mvdes, crossval=cval, performance=custom_perf)
#> Error in assert_that(!is.null(model$fit)): could not find function "assert_that"
ret <- run_searchlight(mvpmod)
#> Error: object 'mvpmod' not found
stopifnot("accuracy" %in% names(ret))
#> Error: "accuracy" %in% names(ret) is not TRUE