Skip to contents

Reads in fmriprep confound tables for one or more subjects.

Usage

# S3 method for class 'bids_project'
read_confounds(
  x,
  subid = ".*",
  task = ".*",
  session = ".*",
  run = ".*",
  cvars = DEFAULT_CVARS,
  npcs = -1,
  perc_var = -1,
  nest = TRUE,
  ...
)

Arguments

x

A bids_project object

subid

Subject ID regex

task

Task regex

session

Session regex

run

Run regex. If the run identifier cannot be extracted from the filename, the run value defaults to "1".

cvars

The names of the confound variables to select. Defaults to DEFAULT_CVARS. Canonical names such as "csf" are automatically mapped to any matching column names found in the dataset using CVARS_ALIASES.

npcs

Perform PCA reduction on confounds and return npcs PCs.

perc_var

Perform PCA reduction to retain perc_var% variance.

nest

If TRUE, nests confound tables by subject/session/run.

...

Additional arguments (not currently used)

Value

A nested tibble (if nest=TRUE) or a flat tibble (if nest=FALSE) of confounds.

Examples

# \donttest{
# Try to load a BIDS project with fMRIPrep derivatives
tryCatch({
  ds_path <- get_example_bids_dataset("ds000001-fmriprep")
  proj <- bids_project(ds_path, fmriprep=TRUE)
  
  # Read confounds with canonical names (automatically resolve to actual columns)
  conf <- read_confounds(proj, cvars = c("csf", "framewise_displacement"))
  
  # Read confounds for specific subjects and tasks
  conf_sub <- read_confounds(proj, subid="01", task="balloonanalogrisktask")
  
  # Get confounds as flat tibble
  conf_flat <- read_confounds(proj, nest=FALSE)
  
  # Clean up
  unlink(ds_path, recursive=TRUE)
}, error = function(e) {
  message("Example requires derivatives dataset with confounds: ", e$message)
})
#> Example requires derivatives dataset with confounds: participants.tsv is missing
# }