glm_lss | R Documentation |
A convenience wrapper around estimate_betas
for least squares separate (LSS) estimation.
This is primarily designed for single trial estimation, where each individual trial/event
gets its own separate beta estimate rather than averaging across trials of the same condition.
glm_lss(
dataset,
model_obj,
basis_obj,
basemod = NULL,
block = ~1,
use_cpp = TRUE,
progress = TRUE,
...
)
dataset |
A |
model_obj |
An |
basis_obj |
An HRF basis object (e.g., from |
basemod |
A |
block |
A formula specifying the block factor (default: ~ 1 for single block) |
use_cpp |
Logical; whether to use C++ implementation for speed (default: TRUE) |
progress |
Logical; show progress bar (default: TRUE) |
... |
Additional arguments passed to |
Primary Use Case - Single Trial Estimation:
Trial-wise beta estimation: Each trial gets its own beta coefficient
Single trial analysis: Useful for decoding, representational similarity analysis (RSA)
Trial-by-trial variability: Captures individual trial responses rather than condition averages
Avoiding trial averaging: Preserves trial-specific information that would be lost in standard GLM
Method Details: LSS (Least Squares Separate) fits a separate model for each trial, where the trial of interest gets its own regressor while all other trials of the same condition are modeled together. This approach avoids the collinearity issues that would arise from including separate regressors for every trial simultaneously.
For standard condition-level estimation (averaging trials within conditions), use glm_ols()
instead.
A list of class "fmri_betas" containing the estimated trial-wise coefficients
estimate_betas
for the underlying estimation function,
glm_ols
for condition-level estimation
## Not run:
# Create event model and data
event_data <- data.frame(
onset = c(10, 30, 50, 70),
condition = factor(c("A", "B", "A", "B")),
run = rep(1, 4)
)
sframe <- fmrihrf::sampling_frame(blocklens = 100, TR = 2)
model_obj <- event_model(onset ~ hrf(condition),
data = event_data,
block = ~ run,
sampling_frame = sframe)
# Create data matrix (100 timepoints, 10 voxels)
Y <- matrix(rnorm(1000), 100, 10)
# Create matrix_dataset with event table
dset <- matrix_dataset(Y, TR = 2, run_length = 100, event_table = event_data)
# Fit with LSS - estimates separate beta for each individual trial
fit <- glm_lss(dset, model_obj, fmrihrf::HRF_SPMG1)
dim(fit$betas_ran) # 4 trials x 10 voxels (NOT averaged by condition)
# This is useful for:
# - Decoding analysis (predicting condition from single trial patterns)
# - RSA (representational similarity analysis)
# - Studying trial-by-trial variability
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.