osl_dynamics.glm.ols#

Ordinary least squares fitting for a GLM.

Functions#

get_residuals(X, y, predictor)

Get residuals from a linear model.

get_degree_of_freedom(X)

Get degree of freedom.

get_varcopes(X, y, contrasts, predictor)

Get the variance of the copes.

osl_fit(X, y, contrasts)

Fit Ordinary Least Squares (OLS) model.

remove_nan_rows(X, y)

Remove rows with NaN values.

Module Contents#

osl_dynamics.glm.ols.get_residuals(X, y, predictor)[source]#

Get residuals from a linear model.

Parameters:
  • X (np.ndarray) – Design matrix. Shape is (n_samples, n_features).

  • y (np.ndarray) – Target variable. Shape is (n_samples, n_targets).

  • predictor (sklearn.linear_model.LinearRegression) – Sklearn LinearRegression object.

Returns:

residuals – Residuals. Shape is (n_samples, n_targets).

Return type:

np.ndarray

osl_dynamics.glm.ols.get_degree_of_freedom(X)[source]#

Get degree of freedom.

Parameters:

X (np.ndarray) – Design matrix. Shape is (n_samples, n_features).

Returns:

dof – Degree of freedom.

Return type:

int

osl_dynamics.glm.ols.get_varcopes(X, y, contrasts, predictor)[source]#

Get the variance of the copes.

Parameters:
  • X (np.ndarray) – Design matrix. Shape is (n_samples, n_features).

  • y (np.ndarray) – Target variable. Shape is or (n_samples, n_targets).

  • contrasts (np.ndarray) – Contrasts matrix. Shape is (n_contrasts, n_features).

  • predictor (sklearn.linear_model.LinearRegression) – Sklearn LinearRegression object.

Returns:

varcopes – Variance of the copes. Shape is (n_contrasts, n_targets).

Return type:

np.ndarray

osl_dynamics.glm.ols.osl_fit(X, y, contrasts)[source]#

Fit Ordinary Least Squares (OLS) model.

Parameters:
  • X (np.ndarray) – Design matrix. Shape is (n_samples, n_features).

  • y (np.ndarray) – Target variable. Shape is (n_samples, n_targets).

  • contrasts (np.ndarray) – Contrasts matrix. Shape is (n_contrasts, n_features).

Returns:

  • betas (np.ndarray) – Betas (regression coefficients). Shape is (n_features, n_targets).

  • copes (np.ndarray) – Contrast parameter estimates. Shape is (n_contrasts, n_targets).

  • varcopes (np.ndarray) – Variance of the copes. Shape is (n_contrasts, n_targets).

Return type:

Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]

osl_dynamics.glm.ols.remove_nan_rows(X, y)[source]#

Remove rows with NaN values.

Parameters:
  • X (np.ndarray) – Design matrix. Shape is (n_samples, n_features).

  • y (np.ndarray) – Target variable. Shape is (n_samples, n_targets).

Returns:

  • X_copy (np.ndarray) – Design matrix without NaN rows. Shape is (n_samples’, n_features).

  • y_copy (np.ndarray) – Target variable without NaN rows. Shape is (n_samples’, n_targets).

Return type:

Tuple[numpy.ndarray, numpy.ndarray]