MIR.statistical_analysis.GLM

MIR.statistical_analysis.GLM(X, Y, mask=None)[source]

Perform voxel-wise General Linear Model (GLM) fitting by ordinary least squares.

betas = pinv(X^T X) X^T Y; the residual variance uses df = N - rank(X) (at least 1) and the t-statistic of coefficient j is beta_j / sqrt(sigma2 * pinv(X^T X)[j, j]).

Parameters:
  • X (torch.Tensor) – (N, P) design matrix.

  • Y (torch.Tensor) – (N, V) data matrix.

  • mask (torch.Tensor | None) – (H, W, D) boolean mask to select voxels (optional); if given, V must equal H*W*D and only masked columns of Y are fitted.

Returns:

Tuple (betas, t_maps) – betas (P, V’) estimated coefficients and t_maps, a list of P tensors (V’,) with the t-statistic of each coefficient (V' = number of fitted voxels).

Return type:

Tuple[torch.Tensor, List[torch.Tensor]]