How to Use Nilearn to Obtain GLM Beta Values for fnirs Data

I am trying to fit a General Linear Model (GLM) to a segment of fnirs data using the nilearn package, with the goal of obtaining beta values that relate my fnirs data to a hemodynamic response function (HRF) curve. I want to estimate these beta values similarly to how one might with fMRI data.

Command used:

python

events = pd.DataFrame({"trial_type": ['stim'],"onset": [marker], "duration": [duration]})

design_matrix = make_first_level_design_matrix(
    frame_times,
    events,
    hrf_model="spm",
    drift_model=None,
)

data = pd.DataFrame(filtered_data['value']).to_numpy()

labels, estimates = run_glm(data, design_matrix.to_numpy())

This is based on this example: Example of surface-based first-level analysis - Nilearn

Version:

nilearn version: 0.10.4

Environment:

Custom Python installation

Data formatted according to a validatable standard?

The data used is fnirs, preprocessed and formatted as numpy arrays. No BIDS validator was applied.

Screenshots / relevant information:

I am referencing this tutorial: The GLM, part 1: estimation — NI-edu, and my aim is to achieve the following:

python

est_betas = inv(X_with_icept.T @ X_with_icept) @ X_with_icept.T @ y

I would like to know if it is possible to obtain beta values by fitting the fnirs data using the nilearn package’s GLM tools.

Currently my code is this, but I’m not sure if it’s correct.

betas_conv = inv(design_matrix.to_numpy().T @ design_matrix.to_numpy()) @ design_matrix.to_numpy().T @ filtered_data['value'].to_numpy()

Is it possible for nilearn to output beta values ​​directly?

See this post: How to save beta maps from the first level GLM? - #5 by Steven

Thank you very much for your reply.

I have seen this post before
It seems that most researchers want a beta fmri map to draw
But I want something more like an effect size
I have tried

labels, estimates = run_glm(data, design_matrix.to_numpy())

from nilearn.glm.contrasts import compute_contrast
contrast_matrix = np.eye(design_matrix.shape[1])

contrast = compute_contrast(labels, estimates, contrast_matrix[0], stat_type='t')

But the contrast obtained here is very different from the result of my direct calculation
est_betas = inv(X_with_icept.T @ X_with_icept) @ X_with_icept.T @ y

What I want to ask is whether there is a place in nilearn that can directly generate the beta value between each vowel (np array) and hrf curve.
Currently, the results obtained by various contrast parameters are very different from those obtained by directly calculating beta.