论文信息 ¶
无
具体代码 ¶
evoked_list = [CCC_evoked, CCU_evoked, CUC_evoked, CUU_evoked, NCO_evoked, NUN_evoked, CLC_evoked, CLU_evoked]
evoked_names = ['CCC', 'CCU', 'CUC', 'CUU', 'NCO', 'NUN', 'CLC', 'CLU']
csv_file_path = 'sub3mean.csv'
for epo,epo_names in zip(evoked_list,evoked_names):
epo = epo.copy().crop(tmin=0.35,tmax=0.45)
mean_amp_all = epo.data.mean(axis=1)
mean_amp_all_df = pd.DataFrame({"ch_name": epo.info["ch_names"], "mean_amp": mean_amp_all})
mean_amp_all_df["tmin"] = 0.35
mean_amp_all_df["tmax"] = 0.45
mean_amp_all_df["condition"] = epo_names
file_exists = pd.io.common.file_exists(csv_file_path)
if not file_exists:
# 如果文件不存在,写入列名
mean_amp_all_df.to_csv(csv_file_path, header = True, index=False)
else:
# 如果文件已存在,追加数据而不写入列名
mean_amp_all_df.to_csv(csv_file_path, mode='a', header = False, index=False)
#定义一个函数,判断 ch_name 是否在指定列表中,并返回相应的 ROI 值
all_data_df = pd.read_csv("sub3mean.csv")
def assign_roi(ch_name):
P_ROI_list = ['E27', 'E28', 'E30', 'E42', 'E44', 'E45', 'E31', 'E33', 'E38', 'E40']
F_ROI_list=['E13','E18','E19','E56','E58','E59','E9','E11','E12','E2','E3','E60']
C_ROI_list=['E22','E25','E48','E49','E16','E20','E21','E41','E50','E51']
if ch_name in P_ROI_list:
return 'P'
elif ch_name in F_ROI_list:
return 'F'
elif ch_name in C_ROI_list:
return 'C'
# 将函数应用到 DataFrame 的 ch_name 列上,创建一个新的 ROI 列
all_data_df['ROI'] = all_data_df['ch_name'].apply(assign_roi)
#保存!
csv_file_path = 'sub3mean.csv'
all_data_df.to_csv(csv_file_path,index = False)
import pandas as pd
import statsmodels.api as sm
from statsmodels.formula.api import ols
from statsmodels.stats.anova import anova_lm
from statsmodels.stats.multicomp import pairwise_tukeyhsd
df = pd.read_csv('sub3mean.csv')#根据文件名更改
formula = 'mean_amp ~ condition*sen'#根据变量更改
model = ols(formula, data=df).fit()
anova_table = anova_lm(model, typ=2)
print(anova_table)
result = pairwise_tukeyhsd(df['mean_amp'], df['condition:sen'])
print(result)
# 检验交互作用的显著性
interaction_p_value = sm.stats.anova_lm(model, typ=3)['sen:condition']['PR(>F)'][0]
print(f'Interaction p-value: {interaction_p_value}')