phys2cvr.stats.ols

phys2cvr.stats.ols(Ymat, Xmat, r2model='full', residuals=False, demean=False)[source]

Perform Ordinary Least Squares (OLS) regression.

Axis 0 must be time for both matrices.

This is barebone OLS computation, for full regression workflows, see stats.regression.

Parameters:
Ymatnp.ndarray

Dependent variable, 1D or 2D. Time must be axis 0.

Xmatnp.ndarray

Independent variables, 1D or 2D. The regressor of interest MUST be the last dimension. The columns must represent the regressors over time, i.e., time axis must be axis 0.

r2model{‘full’, ‘partial’, ‘intercept’, ‘adj_full’, ‘adj_partial’, ‘adj_intercept’}, optional

R^2 model to compute in OLS. Possible models are:

  • ‘full’ (default)

    Use all regressors in the model, i.e., compare all regressors versus a baseline of 0

  • ‘partial’

    Consider only the first vector of Xmat as regressor of interest in the model, i.e. compare the first vector with a baseline which is composed of all other vectors of Xmat beside the first.

  • ‘intercept’

    Use all regressors in the model, except for the intercept, i.e., compare all regressors versus a baseline which is the intercept (Legendre polynomial order 0, a.k.a., average signal)

  • ‘adj_full’, adj_partial, adj_intercept

    Adjusted R^2 models of any simple R^2 model

Under normal conditions, although the R^2 values will vary between the different options, a lagged regression based on any R^2 model will provide the same results independent of the chosen option. This WILL NOT be the case if orthogonalisations are applied between the first vector of Xmat and the others vectors. In this case, a lagged regression based on partial might hold different results from the others. The original AFNI implementation used partial. Default: full

residualsbool, optional

If True, outputs only the residuals of the model - to be mainly used for orthogonalisation If False, outputs betas, tstats, and R^2 (default).

demeanbool, optional

If True, demean Xmat before running OLS. Default is False.

Returns:
betasnp.ndarray

Beta values

t_statsnp.ndarray

T-statistic values

r_squarenp.ndarray

R^2 values

Raises:
NotImplementedError

If Ymat has more than 2 dimensions. If Xmat has more than 2 dimensions. If “poly” R^2 is declared (as it’s not implemented yet).

ValueError

If a non-valid R^2 value is declared.