-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeds_defog_analysis.py
137 lines (95 loc) · 5.18 KB
/
meds_defog_analysis.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 30 12:16:38 2023
@author: macbookpro
Analysis of time and accelerations of event with meds and no meds for defog
"""
import matplotlib.pyplot as plt
import numpy as np
from events_analysis import read_csv
import pandas as pd
def get_row(df_subjects, id_number):
row = df_subjects.loc[df_subjects['Id'] == id_number]
return row
def get_total_time(dataframe):
times = dataframe['Completion'] - dataframe['Init']
return times
def plot_times(dataframe, graph_title=None):
plt.figure()
plt.title(graph_title)
plt.ylabel('Time (s)')
plt.xlabel('Event Occurrence Count')
plt.plot(np.linspace(1, len(dataframe), len(dataframe)), dataframe)
plt.show()
if __name__ == "__main__":
events_file_path = '/Users/Documents/kaggle/parkinsons_fog/data/events.csv'
defog_file_path = '/Users/Documents/kaggle/parkinsons_fog/data/defog_metadata.csv'
events_df = read_csv(events_file_path)
defog_df = read_csv(defog_file_path)
# Sort df based on subjects
defog_subjects_df = defog_df.sort_values(by=['Subject'])
defog_subjects = defog_subjects_df.Subject.unique()
sh_events_med_on = pd.DataFrame()
w_events_med_on = pd.DataFrame()
t_events_med_on = pd.DataFrame()
sh_events_med_off = pd.DataFrame()
w_events_med_off = pd.DataFrame()
t_events_med_off = pd.DataFrame()
for subject_id in defog_subjects:
# Visit Ids for a subject
ids_list = defog_subjects_df.query("Subject == @subject_id")["Id"]
for ID in ids_list:
# Get 1 visit id of a subject
id_row = get_row(defog_subjects_df, ID)
if id_row['Medication'].values[0] == 'on':
# match visit id to visit id in events folder
id_events_df = events_df.query("Id == @id_row['Id'].values[0]")
sh_med_on = id_events_df.loc[id_events_df['Type'] == 'StartHesitation']
w_med_on = id_events_df.loc[id_events_df['Type'] == 'Walking']
t_med_on = id_events_df.loc[id_events_df['Type'] == 'Turn']
if not sh_med_on.empty:
sh_events_med_on = pd.concat([sh_events_med_on, sh_med_on])
if not w_med_on.empty:
w_events_med_on = pd.concat([w_events_med_on, w_med_on])
if not t_med_on.empty:
t_events_med_on = pd.concat([t_events_med_on, t_med_on])
if id_row['Medication'].values[0] == 'off':
# match visit id to visit id in events folder
id_events_df = events_df.query("Id == @id_row['Id'].values[0]")
sh_med_off = id_events_df.loc[id_events_df['Type'] == 'StartHesitation']
w_med_off = id_events_df.loc[id_events_df['Type'] == 'Walking']
t_med_off = id_events_df.loc[id_events_df['Type'] == 'Turn']
if not sh_med_off.empty:
sh_events_med_off = pd.concat([sh_events_med_off, sh_med_off])
if not w_med_off.empty:
w_events_med_off = pd.concat([w_events_med_off, w_med_off])
if not t_med_off.empty:
t_events_med_off = pd.concat([t_events_med_off, t_med_off])
sh_times_med_on = get_total_time(sh_events_med_on)
w_times_med_on = get_total_time(w_events_med_on)
t_times_med_on = get_total_time(t_events_med_on)
sh_times_med_off = get_total_time(sh_events_med_off)
w_times_med_off = get_total_time(w_events_med_off)
t_times_med_off = get_total_time(t_events_med_off)
plot_times(sh_times_med_on, 'Start Hesitation Times w/ Meds')
plot_times(sh_times_med_off, 'Start Hesitation Times w/out Meds')
plot_times(w_times_med_on, 'Walking Times w/ Meds')
plot_times(w_times_med_off, 'Walking Times w/out Meds')
plot_times(t_times_med_on, 'Turn Times w/ Meds')
plot_times(t_times_med_off, 'Turn Times w/out Meds')
print("The mean time for lab subjects for Start Hesitation with meds is "
+ str(np.mean(sh_times_med_on)) + " seconds +/- "
+ str(np.std(sh_times_med_on)) + " seconds and with meds off is "
+ str(np.mean(sh_times_med_off)) + " seconds +/- "
+ str(np.std(sh_times_med_off)) + " seconds \n")
print("The mean time for lab subjects for Walking with meds is "
+ str(np.mean(w_times_med_on)) + " seconds +/- "
+ str(np.std(w_times_med_on)) + " seconds and with meds off is "
+ str(np.mean(w_times_med_off)) + " seconds +/- "
+ str(np.std(w_times_med_off)) + " seconds \n")
print("The mean time for lab subjects for Walking with meds is "
+ str(np.mean(t_times_med_on)) + " seconds +/- "
+ str(np.std(t_times_med_on)) + " seconds and with meds off is "
+ str(np.mean(t_times_med_off)) + " seconds +/- "
+ str(np.std(t_times_med_off)) + " seconds \n")