# Averaging and plot multiple mean_spectrums

Dear MNE users,

I calculated the power spectrum for multiple conditions, across multiple subjects, using the following code.

``````spectrum = epochs_cleaned.compute_psd(fmin=2, fmax=40., n_fft = 500, n_overlap = int(0.50 * 500), method = 'welch',  n_jobs=-1)
# average across epochs first
mean_spectrum = spectrum.average()
``````

I would like now to average the mean_spectrums calculated as below, across participants, and then plot each averaged condition as I was doing at the single subject / single condition level using

``````mean_spectrum.plot_topomap(cmap = 'RdBu_r')
``````

How can I achieve this? As in, how can I aggregate different mean_spectrums and visualise the results?

Best,
Davide

Dear Davide,
Have you solved your problem? I’ve been confused about group analysis lately. If possible, I hope you can tell me the solution.

Best,

Hi,

Assuming that the conditionality of the data is the same across subjects (same number of channels, and same frequency axis) I see two ways around it:

1. (Probably discouraged) Get the “spectrum” or “mean_spectrum” (not sure if one of the two options would not work; I’ll assume that the 2nd works and use it in the example below) as you do for each subject and aggregate the results like
``````all_sub_data = []
all_sub_data.append([mean_spectrum.get_data() for sub in subjects])
all_sub_data = np.array(all_sub_data)
# average across subjects
all_sub_average = np.mean(all_sub_data, axis=0)
``````

Then use one subject and replace its data in-place with the across-subjects averaged data `mean_spectrum._data = all_sub_average`.

1. The other way around it would be to get the data from each subject before computing the PSD, creating an EpochsArray object with the data from all subjects, then using the functions as in your example.

Hope this helps.

Have you solved your problem? I’ve been confused about group analysis lately. If possible, I hope you can tell me the solution.

Hi, could you please describe the second method in detail? i really need your help to deal with this problem