cedalion.models.glm.solve

Solve the GLM model.

Functions

fit(ts, design_matrix[, noise_model, ...])

Fit design matrix to data.

predict(ts, thetas, design_matrix)

Predict time series from design matrix and thetas.

predict_with_uncertainty(ts, fit_results, ...)

Predict time series from design matrix, fitted parameters and uncertainties.

cedalion.models.glm.solve.fit(
ts: cdt.NDTimeSeries,
design_matrix: DesignMatrix,
noise_model: str = 'ols',
ar_order: int = 30,
max_jobs: int = -1,
verbose: bool = False,
)[source]

Fit design matrix to data.

Parameters:
  • ts – the time series to be modeled

  • design_matrix – DataArray with dims time, regressor, chromo

  • noise_model

    specifies the linear regression model

    • ols: ordinary least squares

    • rls: recursive least squares

    • wls: weighted least squares

    • ar_irls: autoregressive iteratively reweighted least squares (Barker et al. [BAH13])

    • gls: generalized least squares

    • glsar: generalized least squares with autoregressive covariance structure

  • ar_order – order of the autoregressive model

  • max_jobs – controls the number of jobs in parallel execution. Set to -1 for all available cores. Set it to 1 to disable parallel execution.

  • verbose – display progress information if True.

Returns:

thetas as a DataArray

cedalion.models.glm.solve.predict(
ts: cdt.NDTimeSeries,
thetas: DataArray,
design_matrix: DesignMatrix,
) cdt.NDTimeSeries[source]

Predict time series from design matrix and thetas.

Parameters:
  • ts (cdt.NDTimeSeries) – The time series to be modeled.

  • thetas (xr.DataArray) – The estimated parameters.

  • design_matrix (xr.DataArray) – DataArray with dims time, regressor, chromo

  • channel_wise_regressors (list[xr.DataArray]) – Optional list of design matrices,

  • dimension. (with additional channel)

Returns:

The predicted time series.

Return type:

prediction (xr.DataArray)

cedalion.models.glm.solve.predict_with_uncertainty(
ts: cdt.NDTimeSeries,
fit_results: DataArray,
design_matrix: DesignMatrix,
regressors: list[str],
nsample: int = 10,
)[source]

Predict time series from design matrix, fitted parameters and uncertainties.

Using the covariance matrix of the fitted parameters and a multivariate normal distribution, nsample set of parameters are sampled around the best fit value. From this ensemble of predictions the mean and std are returned.

Parameters:
  • ts – The time series to be modeled.

  • fit_results – xr.DataArray of statsmodels fit results (from glm.fit)

  • design_matrix – design matrix, probably from glm.design_matrix.hrf_extract_regressors

  • regressors – list of regressors to compute

  • nsample – the size of the sampled parameter set

Returns:

The predicted time series.

Return type:

prediction (xr.DataArray)