Applies a summary function to data within each ROI defined by an atlas. This is an S3 generic function.
Usage
reduce_atlas(atlas, data_vol, stat_func, ..., format = NULL)
# S3 method for class 'atlas'
reduce_atlas(atlas, data_vol, stat_func, ..., format = NULL)
Arguments
- atlas
An atlas object or another object for which a method is defined.
- data_vol
A
NeuroVol
(3D) orNeuroVec
(4D) with the data to be summarized. When a 3D volume is supplied the result contains a single row; 4D inputs yield one row per time point.- stat_func
The function to apply to the data within each ROI (e.g.,
mean
,sd
,sum
).- ...
Additional arguments passed to
stat_func
.- format
Character string specifying output format: "wide" or "long". If NULL (default), uses "long" for NeuroVol and "wide" for NeuroVec.
Value
A tibble
with format depending on the format
parameter:
"wide"
: Regions as columns. For NeuroVec, rows are time points."long"
: Columns areregion
andvalue
(NeuroVol) ortime
,region
, andvalue
(NeuroVec).
Examples
if (FALSE) { # \dontrun{
# Load an atlas
atlas <- get_schaefer_atlas(parcels = "200", networks = "7")
# Create example data (random values in brain space)
brain_data <- neuroim2::NeuroVol(rnorm(prod(dim(atlas$atlas))),
space = space(atlas$atlas))
# Compute mean values within each atlas region
region_means <- reduce_atlas(atlas, brain_data, mean)
# Compute standard deviation within each region
region_sds <- reduce_atlas(atlas, brain_data, sd, na.rm = TRUE)
} # }