-
Notifications
You must be signed in to change notification settings - Fork 0
/
BurstFreq_AcrossCNS_Stats.py
88 lines (73 loc) · 3.42 KB
/
BurstFreq_AcrossCNS_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
86
87
# Plotting some initial images about the relation between frequency in different subjects
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib as mpl
import pingouin as pg
import os
mpl.rcParams['pdf.fonttype'] = 42
if __name__ == '__main__':
srmr_nr = 1
high_freq = 800
ttest_type = 'across_cns' # 'across_cns' 'med_v_tib'
if srmr_nr == 1:
subjects = np.arange(1, 37)
cond_names = ['median', 'tibial']
data_types = ['Spinal', 'Thalamic', 'Cortical']
excel_fname = f'/data/pt_02718/tmp_data/Peak_Frequency_400_{high_freq}_ccabroadband_filter.xlsx'
elif srmr_nr == 2:
subjects = np.arange(1, 25)
cond_names = ['med_mixed', 'tib_mixed']
data_types = ['Spinal', 'Thalamic', 'Cortical']
excel_fname = f'/data/pt_02718/tmp_data_2/Peak_Frequency_400_{high_freq}_ccabroadband_filter.xlsx'
# Compute difference between CNS levels for median and tibial nerve stimulation
if ttest_type == 'across_cns':
for cond_name in cond_names:
df_combination = pd.DataFrame()
# df_combination['Subject'] = subjects
col_name = f'Peak_Frequency_{cond_name}'
for data_type in data_types:
sheetname = data_type
df_freq = pd.read_excel(excel_fname, sheetname)
df_combination[f"{data_type}"] = df_freq[col_name]
df_combination.dropna(inplace=True)
print(cond_name)
print(df_combination.describe())
print(df_combination.sem())
aov = df_combination.rm_anova()
print('ANOVA result')
print(aov)
# If rm_anova was significant, perform post-hoc t-tests
if aov['p-unc'].loc[aov.index[0]] < 0.05:
# Two-sided
ptest_mat = df_combination.ptests(paired=True, padjust='bonf', stars=False, alternative='two-sided')
print('two-sided ttest result')
print(ptest_mat)
# Less than - testing if spinal > thalamic etc.
ptest_mat = df_combination.ptests(paired=True, padjust='bonf', stars=False, alternative='less')
print('one-sided ttest result')
print(ptest_mat)
elif ttest_type == 'med_v_tib':
for data_type in data_types:
df_combination = pd.DataFrame()
# df_combination['Subject'] = subjects
sheetname = data_type
df_freq = pd.read_excel(excel_fname, sheetname)
df_combination[f"{data_type}_{cond_names[0]}"] = df_freq[f'Peak_Frequency_{cond_names[0]}']
df_combination[f"{data_type}_{cond_names[1]}"] = df_freq[f'Peak_Frequency_{cond_names[1]}']
df_combination.dropna(inplace=True)
print(df_combination.describe())
print(df_combination.sem())
# Two-sided
ptest_mat = df_combination.ptests(paired=True, padjust='bonf', stars=False, alternative='two-sided')
print('two-sided')
print(ptest_mat)
# Less than
ptest_mat = df_combination.ptests(paired=True, padjust='bonf', stars=False, alternative='less')
print('less')
print(ptest_mat)
# More than
ptest_mat = df_combination.ptests(paired=True, padjust='bonf', stars=False, alternative='greater')
print('greater')
print(ptest_mat)