Hello,
I obtained the following figure, which highlights a significant cluster. However, I have a question: why is the significant cluster located where there appears to be the least visual difference? This pattern is repeated across multiple figures. I would have understood if there were no difference, but finding a difference where none is visually apparent seems strange.
here is the figure (in grey the signigicative cluster, at about 100 to 200 ms, why not at 50 ms??? it would have been clearer)
here is the code:
Alpha = 0.05
N_Conditions = 2
N_Observations = len(EpochsCondition1[0])
DegreeOfFreedomNumerator = N_Conditions - 1
DegreeOdFreedomDenominator = N_Observations - N_Conditions
Threshold = scipy.stats.f.ppf(1 - Alpha, dfn = DegreeOfFreedomNumerator, dfd = DegreeOdFreedomDenominator)
T_Obs, Clusters, Clusters_P_Values, H0 = mne.stats.permutation_cluster_test([EpochsCondition1, EpochsCondition2],
n_permutations = 1000,
threshold = Threshold,
tail = 0,
seed = 1)
print(Clusters, Clusters_P_Values)
# Now I want to plot the stats
Color = {Condition2: "Blue", Condition1: "red"}
Linestyles = {Condition2: "-", Condition1: "--"}
EvokedsToCompare_List = []
for Evoked in Condition2Evokeds:
EvokedsToCompare_List.append(Evoked)
for Evoked in Condition1Evokeds:
EvokedsToCompare_List.append(Evoked)
EvokedsToCompare_List = [Evoked[0] for Evoked in EvokedsToCompare_List]
EvokedsToCompare_Dict = {Condition2: [], Condition1: []}
for Evoked in EvokedsToCompare_List:
if Evoked.comment == Condition2:
EvokedsToCompare_Dict[Condition2].append(Evoked)
else:
EvokedsToCompare_Dict[Condition1].append(Evoked)
plt.style.use('default')
fig, ax = plt.subplots()
LengthOfData = len(EvokedsToCompare_Dict[Condition1][0].get_data()[0])
# each point is for 0.002 s
StartTime = - 1000 # ms
X_Axis = []
for i in range(len(EvokedsToCompare_Dict[Condition1][0].get_data()[0])):
X_Axis.append(StartTime + (i * 2))
continue
ChannelList = []
for Channel in ROI:
ChannelList.append(EvokedsToCompare_Dict[Condition1][0].info["ch_names"].index(Channel))
continue
DataCondition2 = []
for Index in ChannelList:
DataCondition2.append(EvokedsToCompare_Dict[Condition2][0].get_data()[Index])
continue
DataCondition2 = np.array(DataCondition2)
DataCondition2 = DataCondition2 * 1000000
DataCondition1 = []
for Index in ChannelList:
DataCondition1.append(EvokedsToCompare_Dict[Condition1][0].get_data()[Index])
continue
DataCondition1 = np.array(DataCondition1)
DataCondition1 = DataCondition1 * 1000000
MeanCondition2 = np.mean(DataCondition2, axis = 0)
MeanCondition1 = np.mean(DataCondition1, axis = 0)
SEMCondition2 = scipy.stats.sem(DataCondition2[0])
SEMCondition1 = scipy.stats.sem(DataCondition1[0])
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines.bottom.set_bounds(-1000, 1500)
ax.spines.left.set_bounds(-10, 10)
Ticks = [-10.0, -7.5, -5.0, -2.5, 0.0, 2.5, 5.0, 7.5, 10.0]
ax.set_yticks(Ticks)
ax.plot(X_Axis, MeanCondition2, 'r')
ax.plot(X_Axis, MeanCondition1, 'b')
ax.fill_between(X_Axis, DataCondition2[0] + SEMCondition2, DataCondition2[0] - SEMCondition2, color='r', alpha=.1)
ax.fill_between(X_Axis, DataCondition1[0] + SEMCondition1, DataCondition1[0] - SEMCondition1, color='b', alpha=.1)
ax.axhline(y = 0, color = 'k', linestyle = '-')
ax.axvline(x = 0, color = 'k', linestyle = '--')
ClustersToHighlight = []
for i in range(len(Clusters_P_Values)):
if Clusters_P_Values[i] < 0.05:
ClustersToHighlight.append(Clusters[i])
continue
else:
continue
for i in range(len(ClustersToHighlight)):
Inf = min(ClustersToHighlight[i][0]) * 2 # each point is 2 ms
print("Inferior time limit for the cluster {} = {}".format(i, Inf))
InfBorder = -1000 + Inf
Up = max(ClustersToHighlight[i][0]) * 2
print("Superior time limit for the cluster {} = {}".format(i, Up))
UpBorder = -1000 + Up
Ymin, Ymax = ax.get_ylim()
ax.fill_betweenx((Ymin, Ymax), InfBorder, UpBorder, color = 'grey', alpha = 0.5)
continue
ax.legend([Condition2Title, Condition1Title], loc = "lower right")
plt.xlabel("Duration of the epoch (in ms)")
plt.ylabel("$\mu$V")