T- test on ERFs using numpy & scipy

  • MNE version: e.g. 0.24.0
  • operating system: Windows 10

Hello! I am a I am a bachelor student and I am doing a t-test to compare evoked responses between two conditions, using a script I got from my supervisor. However, there is a problem with extracting the data from a list of evokeds to create an array and I don’t understand how to solve it. Greatfull for the help. Thank you!

First, I create two lists of evokedes for all the participants.

#list of the participants 
ls = ['0121', '0122', '0125', '0127', '0129']

#empty lists for all evoked responses for condition "200" and "201"
all_evoked_200 = []
all_evoked_201 = []


for i in range(0, len(ls)):
    pname= ls[i]
    
    #define main data path
    data_path = 'C:/Users/test/Documents/Karin_kandidat/'
    
    #define path for evoked_200 and load files
    evoked_200_fname = os.path.join(data_path, 'Evoked', 'All_evoked', '221-200', 'evoked_200_{0}.fif'.format(pname))
    evoked_200 = mne.read_evokeds(evoked_200_fname, baseline=None, proj=True)
    
    print(evoked_200)
    
    
    #define path for evoked_201 and load files
    evoked_201_fname = os.path.join(data_path, 'Evoked', 'All_evoked','221-201', 'evoked_201_{0}.fif'.format(pname))
    evoked_201 = mne.read_evokeds(evoked_201_fname, baseline=None, proj=True)
    
    #append singel evokeds to all_evoked_201 and all_evoked_201
    all_evoked_200.append(evoked_200)
    all_evoked_201.append(evoked_201)
#extract all evoked_200 and evoked_201 data
X200 = numpy.array([p.data for p in all_evoked_201])
X201 = numpy.array([p.data for p in all_evoked_200])

This gives error message:

AttributeError Traceback (most recent call last)
Input In [33], in <cell line: 7>()
3 print(all_evoked_200)
5 #från Carine
6 #extract all evoked_200 and evoked_201 data
----> 7 X200 = np.array([p.data for p in all_evoked_201])
8 X201 = np.array([p.data for p in all_evoked_200])

Input In [33], in (.0)
3 print(all_evoked_200)
5 #från Carine
6 #extract all evoked_200 and evoked_201 data
----> 7 X200 = np.array([p.data for p in all_evoked_201])
8 X201 = np.array([p.data for p in all_evoked_200])

AttributeError: ‘list’ object has no attribute ‘data’

Hello,

the problem is in these two lines:

mne.read_evokeds() returns a list of evokeds, so you end up with a list of a list of evokeds in your code (i.e., all_evoked_200 and all_evoked_201 are not lists of evokeds, but lists of lists of evokeds).

If there’s only a single evoked signal in the file, you can pass condition=0, and read_evokeds() will only return an evoked for the first condition instead of a list. So …

    evoked_200 = mne.read_evokeds(
        evoked_200_fname,
        baseline=None,
        proj=True,
        condition=0
    )

and the equivalent for evoked_201.

Best wishes,
Richard