Skip to contents

Performs a standard multiple regression analysis where all trial regressors are fitted simultaneously. This provides a reference comparison to the Least Squares Separate (LSS) approach.

Usage

lsa(Y, X, Z = NULL, Nuisance = NULL, method = c("r", "cpp"))

Arguments

Y

A numeric matrix where rows are timepoints and columns are voxels/features. This is the dependent variable data.

X

A numeric matrix where rows are timepoints and columns are trial-specific regressors. Each column represents a single trial or event.

Z

A numeric matrix of nuisance regressors (e.g., motion parameters, drift terms). Defaults to NULL.

Nuisance

An alias for Z, provided for consistency with LSS interface. If both Z and Nuisance are provided, Z takes precedence.

method

Character string specifying the computational method:

  • "r" - Pure R implementation using lm.fit

  • "cpp" - C++ implementation for better performance

Value

A numeric matrix of size T × V containing the beta estimates for each trial regressor (rows) and each voxel (columns).

Details

LSA fits the model: Y = X*beta + Z*gamma + error, where all trial regressors in X are estimated simultaneously. This is in contrast to LSS, which fits each trial separately while treating other trials as nuisance regressors.

Examples

# Generate example data
n_timepoints <- 100
n_trials <- 10
n_voxels <- 50

# Create trial design matrix
X <- matrix(0, n_timepoints, n_trials)
for(i in 1:n_trials) {
  start <- (i-1) * 8 + 1
  if(start + 5 <= n_timepoints) {
    X[start:(start+5), i] <- 1
  }
}

# Create data with some signal
Y <- matrix(rnorm(n_timepoints * n_voxels), n_timepoints, n_voxels)
true_betas <- matrix(rnorm(n_trials * n_voxels, 0, 0.5), n_trials, n_voxels)
for(i in 1:n_trials) {
  Y <- Y + X[, i] %*% matrix(true_betas[i, ], 1, n_voxels)
}

# Run LSA analysis
beta_estimates <- lsa(Y, X)