-
Notifications
You must be signed in to change notification settings - Fork 0
/
osc_erp_stats.py
85 lines (76 loc) · 2.77 KB
/
osc_erp_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import mne
import matplotlib.pyplot as plt
plt.ion()
import numpy as np
import statsmodels.formula.api as smf
import pandas as pd
from os.path import isdir
if isdir("/home/jev"):
root_dir = "/home/jev/hdd/sfb/"
elif isdir("/home/jeff"):
root_dir = "/home/jeff/hdd/jeff/sfb/"
proc_dir = root_dir+"proc/"
time_win = (-0.025, 0.025)
sham = True
chan = "central"
df_SO = pd.read_pickle("{}phase_amp_{}".format(proc_dir, "SO"))
df_deltO = pd.read_pickle("{}phase_amp_{}".format(proc_dir, "deltO"))
df = pd.concat([df_SO, df_deltO])
sub_inds = df["Subj"].values.astype(int) >= 31
df["Synchron"] = sub_inds
df = df[df["Synchron"]]
#df = df.query("Cond=='eig30s' or Cond=='fix30s' or Cond=='sham'")
if sham:
# # all oscillations
# this_df = df.copy()
# #md = smf.mixedlm("Amp ~ C(OscType, Treatment('deltO'))*C(Cond, Treatment('sham'))", this_df, groups=this_df["Subj"])
# md = smf.mixedlm("Amp ~ C(OscType, Treatment('deltO')) * PureIndex * C(Cond, Treatment('sham'))", this_df, groups=this_df["Subj"])
# res_all = md.fit(reml=True)
# print(res_all.summary())
# SO only
this_df = df.query("OscType=='SO'")
md = smf.mixedlm("Amp ~ C(PrePost, Treatment('Pre'))*Index*C(Cond, Treatment('sham'))", this_df,
groups=this_df["Subj"])
res_SO = md.fit(reml=False)
print(res_SO.summary())
#
# # deltO only
# this_df = df.query("OscType=='deltO'")
# md = smf.mixedlm("Amp ~ C(PrePost, Treatment('Pre'))*Index*C(Cond, Treatment('sham'))", this_df,
# groups=this_df["Subj"])
# res_deltO = md.fit(reml=False)
# print(res_deltO.summary())
else:
df = df.query("Cond != 'sham'")
stim_arts = []
stim_lens = []
for cond in list(df["Cond"].values):
stim_art = "eig" if "eig" in cond else "fix"
for sl in ["30s", "2m", "5m"]:
if sl in cond:
stim_len = sl
break
else:
stim_len = None
stim_arts.append(stim_art)
stim_lens.append(stim_len)
df["StimArt"] = pd.Series(stim_arts, index=df.index)
df["StimLen"] = pd.Series(stim_lens, index=df.index)
# all oscillations
this_df = df.copy()
md = smf.mixedlm("Amp ~ OscType*PrePost*Index*StimArt*StimLen", this_df,
groups=this_df["Subj"])
res_all = md.fit()
print(res_all.summary())
# SO only
this_df = df.query("OscType=='SO'")
md = smf.mixedlm("Amp ~ PrePost*Index*StimArt*StimLen", this_df,
groups=this_df["Subj"])
res_SO = md.fit()
print(res_SO.summary())
# deltO only
this_df = df.query("OscType=='deltO'")
md = smf.mixedlm("Amp ~ PrePost*Index*StimArt*StimLen", this_df,
groups=this_df["Subj"])
res_deltO = md.fit()
print(res_deltO.summary())