Skip to contents

Returns estimated coefficients from a fitted fmri_lm model. Every form of the result has one orientation: voxels x terms, with one row per voxel (or latent component) and one column per coefficient or contrast, and the term names on the column margin. This matches stats(), standard_error() and p_values(), so results from the accessor family line up element-wise (for example coef(fit) / standard_error(fit)).

Usage

# S3 method for class 'fmri_lm'
coef(
  object,
  type = c("betas", "contrasts"),
  include_baseline = FALSE,
  recon = FALSE,
  ...
)

Arguments

object

A fitted fmri_lm object.

type

"betas" (default) for regression coefficients, or "contrasts" for the estimates of the simple contrasts defined in the model.

include_baseline

Logical. For type = "betas", also return the baseline (drift, block intercept and nuisance) coefficients, in design matrix column order. The default, FALSE, returns event coefficients only.

recon

Logical; used by latent-space fits to reconstruct voxel-space coefficients. Ignored for ordinary fits.

...

Unused.

Value

For type = "betas", a numeric matrix with one row per voxel and one column per coefficient, columns named after the design matrix (see coef_names()). For type = "contrasts", a tibble with one row per voxel and one column per contrast.

Orientation change in fmrireg 0.3.0

Before 0.3.0 the default call (type = "betas", include_baseline = FALSE) returned the transpose, terms x voxels, while the other forms were voxels x terms. Code written for the old default that indexed coef(fit)[term, ] must now use coef(fit)[, term].

Examples

X <- matrix(rnorm(50 * 3), 50, 3)
edata <- data.frame(
  condition = factor(c("A", "B", "A", "B")),
  onsets = c(1, 12, 25, 38),
  run = 1
)
dset <- matrix_frame(X, TR = 2, run_length = 50, event_table = edata)
fit <- fmri_lm(onsets ~ hrf(condition), block = ~run, dataset = dset)
b <- coef(fit) # 3 voxels x 2 event coefficients
dim(b)
#> [1] 3 2
colnames(b)
#> [1] "condition_condition.A" "condition_condition.B"
dim(coef(fit, include_baseline = TRUE))
#> [1] 3 6