statsmodels_to_results problem

Hi,

I am following this code
https://mne.tools/mne-nirs/stable/auto_examples/general/plot_12_group_glm.html#id9
to obtain a similar Group topographic visualisation with my fNIRS data.

I typed this code:

ch_model = smf.mixedlm("theta ~ -1 + ch_name:Chroma:subject",grp_results, groups=grp_results['ID']).fit(method='nm')

ch_model_df = statsmodels_to_results(ch_model.summary)

but when I use statsmodels_to_results I have this error

ch_model_df = statsmodels_to_results(ch_model)
Traceback (most recent call last):

File “/var/folders/vk/yv_5r9997_n9mr3vt6gw0vwh0000gn/T/ipykernel_7881/1169074141.py”, line 1, in
ch_model_df = statsmodels_to_results(ch_model)

File “/opt/anaconda3/envs/mlaroccaenv/lib/python3.7/site-packages/mne_nirs/statistics/_statsmodels.py”, line 103, in statsmodels_to_results
df.iloc[sl, df.columns == ‘Std.Err.’] = stderr

File “/opt/anaconda3/envs/mlaroccaenv/lib/python3.7/site-packages/pandas/core/indexing.py”, line 670, in setitem
iloc._setitem_with_indexer(indexer, value)

File “/opt/anaconda3/envs/mlaroccaenv/lib/python3.7/site-packages/pandas/core/indexing.py”, line 1745, in _setitem_with_indexer
isetter(ilocs[0], value)

File “/opt/anaconda3/envs/mlaroccaenv/lib/python3.7/site-packages/pandas/core/indexing.py”, line 1676, in isetter
ser = self.obj._ixs(loc, axis=1)

File “/opt/anaconda3/envs/mlaroccaenv/lib/python3.7/site-packages/pandas/core/frame.py”, line 2846, in _ixs
values = self._mgr.iget(i)

File “/opt/anaconda3/envs/mlaroccaenv/lib/python3.7/site-packages/pandas/core/internals/managers.py”, line 988, in iget
block = self.blocks[self.blknos[i]]

TypeError: only integer scalar arrays can be converted to a scalar index

[SpyderKernelApp] ERROR | Error in message handler
Traceback (most recent call last):
File “/opt/anaconda3/envs/mlaroccaenv/lib/python3.7/site-packages/ipykernel/kernelbase.py”, line 461, in dispatch_queue
await self.process_one()
File “/opt/anaconda3/envs/mlaroccaenv/lib/python3.7/site-packages/ipykernel/kernelbase.py”, line 450, in process_one
await dispatch(*args)
TypeError: object NoneType can’t be used in ‘await’ expression

this is my grp_results if this can help

Could you help me, please, @rob-luke ? I think you worked at that example.

Thank you.

Can you please reformat your first post with appropriate code blocks etc.

And can you please report the output of mne.sys_info()

Hi @rob-luke,

this is the output required:

mne.sys_info()
/var/folders/vk/yv_5r9997_n9mr3vt6gw0vwh0000gn/T/ipykernel_7881/3389385014.py:1: RuntimeWarning: macOS users should use PyQt5 >= 5.10 for GUIs, got 5.9.2. Please upgrade e.g. with:

pip install "PyQt5>=5.10,<5.14"

mne.sys_info()
Platform: macOS-10.16-x86_64-i386-64bit
Python: 3.7.9 (default, Aug 31 2020, 07:22:35) [Clang 10.0.0 ]
Executable: /opt/anaconda3/envs/mlaroccaenv/bin/python
CPU: i386: 16 cores
Memory: 64.0 GB

mne: 1.0.dev0
numpy: 1.21.5 {blas=openblas, lapack=openblas}
scipy: 1.4.1
matplotlib: 3.3.1 {backend=module://matplotlib_inline.backend_inline}

sklearn: 0.22.1
numba: Not found
nibabel: 3.2.2
nilearn: 0.9.0
dipy: Not found
cupy: Not found
pandas: 1.1.3
pyvista: Not found
pyvistaqt: Not found
ipyvtklink: Not found
vtk: Not found
PyQt5: 5.9.2
ipympl: Not found
pooch: v1.6.0

mne_bids: Not found
mne_nirs: 0.3.0 dev
mne_features: Not found
mne_qt_browser: Not found
mne_connectivity:Not found

What do you mean with code blocks? My whole code or the code of the link that I am referring to?

Thank you,

@rob-luke or anyone else, any suggestion to fix that issue? I am stuck there and cannot go ahead with the analysis.

I am looking forward to hearing from you,

thank you

Your pandas is out of date by three minor versions, so as a first step, I might try upgrading that.

Also if you use three ticks (`) before and after code, it formats it nicely like so

import pandas as pd

Thank you @alexrockhill , now that works. Only I cannot understand why the figure (see image) is not well centred. Any thought?

This is the code that I used

                         gridspec_kw=dict(width_ratios=[1, 1]))
grp_results = df.query("Condition in ['Tapping']")
grp_results = grp_results.query("Chroma in ['hbo']")
ch_model = smf.mixedlm("theta ~ -1 + ch_name:Chroma:subject",grp_results, groups=grp_results['ID']).fit(method='nm')


ch_model_df = statsmodels_to_results(ch_model)

plot_glm_group_topo(raw_haemo.copy().pick(picks="hbo"),
                    ch_model_df.query("subject in ['1']"),
                    colorbar=False, axes=axes[0, 0],
                    vmin=0, vmax=20, cmap=mpl.cm.Oranges)

plot_glm_group_topo(raw_haemo.copy().pick(picks="hbo"),
                    ch_model_df.query("subject in ['2']"),
                    colorbar=True, axes=axes[0, 1],
                    vmin=0, vmax=20, cmap=mpl.cm.Oranges)

grp_results = df.query("Condition in ['Tapping']")
grp_results = grp_results.query("Chroma in ['hbr']")

ch_model = smf.mixedlm("theta ~ -1 + ch_name:Chroma:subject",grp_results, groups=grp_results['ID']).fit(method='nm')


ch_model_df = statsmodels_to_results(ch_model)

plot_glm_group_topo(raw_haemo.copy().pick(picks="hbr"),
                    ch_model_df.query("subject in ['1']"),
                    colorbar=False, axes=axes[1, 0],
                    vmin=-10, vmax=0, cmap=mpl.cm.Blues_r)

plot_glm_group_topo(raw_haemo.copy().pick(picks="hbr"),
                    ch_model_df.query("subject in ['2']"),
                    colorbar=True, axes=axes[1, 1],
                    vmin=-10, vmax=0, cmap=mpl.cm.Blues_r)```

Looks like maybe you’re channel positions are in the wrong coordinate frame. Maybe try mne.viz.plot_alignment or mne.viz.Brain and mne.viz.Brain.add_sensors (I made the second one so shameless plug :slight_smile: ). I would guess that your coordinates are in voxels (all positive) and in terms on head. Here’s the example I would follow: Importing data from fNIRS devices — MNE 1.0.0 documentation

I am following this code. Is subjects_dir the path of the directory fsaverage of free surfer?


brain = mne.viz.Brain(
    'fsaverage', subjects_dir=subjects_dir, background='w', cortex='0.5')
brain.add_sensors(
    raw_intensity.info, trans='fsaverage',
    fnirs=['channels', 'pairs', 'sources', 'detectors'])
brain.show_view(azimuth=20, elevation=60, distance=400)```


How can I obtain  raw_intensity.info? I am reading this 

```info = mne.create_info(ch_names=ch_names, ch_types=ch_types, sfreq=sfreq)
raw = mne.io.RawArray(data, info, verbose=True)```

but I am not sure what is info and data in my case. I tried to create info like in the example. Is data my fNIRS file that I import with mne.io.read_raw_nirx? I tried with that, but I have an error.

Isn't there an easier way to obtain that figure aligned?

subjects_dir is where the FreeSurfer subject reconstructions are to be found; this is typically a folder named subjects inside your FreeSurfer installation folder, and will contain the fsaverage subject by default.

I also have to admit I lost track … are we still talking about the problem with statsmodels? Or has this been resolved?

Please try to create new postings for new / followup questions to make things easier to navigate, both mentally and in the browser :slight_smile: Thank you!

Ok I created a new topic here Topographic visualisation is not well centred trying to summarise the discussion about the topographic visualisation problem.

I really appreciate any help,

Thank you

1 Like