File size: 21,192 Bytes
000de75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
"""
Derive features from PRO responses for multiple time windows and select time window
that gives the best signal.
"""

import numpy as np
import pandas as pd
import model_h
import matplotlib.pyplot as plt
from collections import defaultdict


def create_cols_for_plotting(pro_name, question_col_names=None, var_engagement=False):
    """
    Create a mapping for the PRO questions specified that allows plotting of the results
    from the same question with different time windows on the same grid. The key of the
    dictionary is the PRO question (e.g. 'EQ5DQ1') and the values are a list containing
    column names to be plotted (e.g. ['LatestEQ5DQ1', 'DiffLatestAvgEQ5DQ1TW1']).

    Args:
        pro_name (str): name of PRO.
        question_col_names (list, optional): a list of question names required for
                            plotting. Defaults to None.
        var_engagement (bool, optional): whether the variable to be plot is engagement.
                        Defaults to False.

    Returns:
        dict of (str:list): dictionary containing mapping where each key maps to a list
                 of column names.
    """
    cols_for_plotting = defaultdict(list)

    if var_engagement is False:
        for question in question_col_names:
            for time_window_num in range(1, 7):
                col_name = (
                    "DiffLatestAvg" + pro_name + question + "TW" + str(time_window_num)
                )
                cols_for_plotting[pro_name + question].append(col_name)
                if (pro_name == "SymptomDiary") & (question == "Q3"):
                    col_name = (
                        "ScaledSum" + pro_name + question + "TW" + str(time_window_num)
                    )
                    cols_for_plotting["ScaledSum" + pro_name + question].append(
                        col_name
                    )
            cols_for_plotting[pro_name + question].append(
                "DiffLatestPrev" + pro_name + question
            )
            if (pro_name == "EQ5D") | (pro_name == "MRC"):
                cols_for_plotting[pro_name + question].append(
                    "Latest" + pro_name + question
                )
            if (pro_name == "CAT") | (pro_name == "SymptomDiary"):
                cols_for_plotting[pro_name + question].append(
                    "WeekAvg" + pro_name + question
                )

    if var_engagement is True:
        for time_window_num in range(1, 7):
            col_name = "Engagement" + pro_name + "TW" + str(time_window_num)
            cols_for_plotting[pro_name].append(col_name)
    return cols_for_plotting


def plot_feature_signal(
    data, nrows, ncols, figsize, cols_to_plot, fig_name, outcome="ExacWithin3Months"
):
    """
    Plot boxplots for each multiple columns onto the same grid if multiple columns are
    specified.

    Args:
        data (pd.DataFrame): dataframe containing all data to plot and outcome column.
        nrows (int): number of rows for the subplot grid.
        ncols (int): number of columns for the subplot grid.
        figsize (tuple): (width, height) in inches.
        cols_to_plot (list): column names to plot.
        fig_name (str): name of figure required to save figure.
        outcome (str, optional): name of column to group values by for plotting the
                 data. Defaults to 'ExacWithinMonths'.

    Returns:
        None.
    """
    fig, ax = plt.subplots(nrows, ncols, figsize=figsize)
    if (nrows > 1) | (ncols > 1):
        ax = ax.flatten()
        for i, col in enumerate(cols_to_plot):
            data.boxplot(
                col,
                outcome,
                ax=ax[i],
                flierprops={"markersize": 2},
                medianprops={"color": "black"},
                # oxprops={"color": "black"},
            )
    else:
        for i, col in enumerate(cols_to_plot):
            data.boxplot(
                col,
                outcome,
                flierprops={"markersize": 2},
                medianprops={"color": "black"},
            )
    plt.tight_layout()
    plt.savefig("./plots/boxplots/" + fig_name + ".png")
    plt.close()


data = pd.read_pickle("./data/patient_labels_hosp_comm.pkl")
patient_details = pd.read_pickle("./data/patient_details.pkl")

data = data.merge(
    patient_details[["StudyId", "FirstSubmissionDate", "LatestPredictionDate"]],
    on="StudyId",
    how="left",
)

# Calculate the lookback start date. Will need this to aggreggate data for model
# features
data["LookbackStartDate"] = data["IndexDate"] - pd.DateOffset(days=180)

############################################################################
# Derive features from PRO responses
############################################################################
############################################
# Monthly PROs - EQ5D
############################################
pro_eq5d = pd.read_csv("<YOUR_DATA_PATH>/copd-dataset/CopdDatasetProEQ5D.txt", delimiter="|")
pro_eq5d = pro_eq5d.merge(
    data[["StudyId", "IndexDate", "FirstSubmissionDate", "LatestPredictionDate"]],
    on="StudyId",
    how="inner",
)

# EQ5DQ6 is a much less structured question compared to the other questions in EQ5D. A
# new score will be calculated using only EQ5DQ1-Q5 to prevent Q6 affecting the score.
pro_eq5d["EQ5DScoreWithoutQ6"] = pro_eq5d.loc[:, "EQ5DQ1":"EQ5DQ5"].sum(axis=1)

# Calculate engagement over service
pro_eq5d = model_h.calc_total_pro_engagement(pro_eq5d, "EQ5D")

# Calculate engagement over multiple time windows
for time_window in range(1, 7):
    pro_eq5d_engagement = model_h.calc_pro_engagement_in_time_window(
        pro_eq5d, "EQ5D", time_window=time_window, data=data
    )
    pro_eq5d = pro_eq5d.merge(
        pro_eq5d_engagement, on=["StudyId", "IndexDate"], how="left"
    )

# Calculate last PRO score
pro_eq5d = model_h.calc_last_pro_score(pro_eq5d, "EQ5D")

# Calculate the PRO score prior to the last PRO score
pro_eq5d = model_h.calc_pro_score_prior_to_latest(pro_eq5d, "EQ5D")

#############################
# Scores across time windows
#############################
# Mapping to calculate the difference between the latest PRO scores and both the average
# and previous PRO score
question_names_eq5d = ["Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Score", "ScoreWithoutQ6"]
mapping_eq5d = model_h.define_mapping_for_calcs(
    "EQ5D", question_names_eq5d, prefixes=["Avg", "Prev"]
)

# Calculate average PRO score across various time windows (months) prior to IndexDate,
# ignoring the latest PRO score
for time_window in range(1, 7):
    pro_eq5d = model_h.calc_pro_average(pro_eq5d, "EQ5D", time_window=time_window)
    for key in mapping_eq5d:
        model_h.calc_diff_pro_scores(
            pro_eq5d, "EQ5D", key, mapping_eq5d[key][0], time_window=time_window
        )

# Calculate difference between latest PRO score and PRO score prior to the latest
for key in mapping_eq5d:
    model_h.calc_diff_pro_scores(pro_eq5d, "EQ5D", key, mapping_eq5d[key][1])

# Remove unwanted columns and duplicates
pro_eq5d = pro_eq5d.loc[
    :,
    ~(
        pro_eq5d.columns.str.startswith("Avg")
        | pro_eq5d.columns.str.startswith("EQ5D")
        | pro_eq5d.columns.str.startswith("Prev")
        | pro_eq5d.columns.str.startswith("Response")
    ),
]
pro_eq5d = pro_eq5d.drop(
    columns=[
        "Score",
        "SubmissionTime",
        "FirstSubmissionDate",
        "TimeInService",
        "TimeSinceSubmission",
        "LatestPredictionDate",
        "LatestPRODate",
    ]
)
pro_eq5d = pro_eq5d.drop_duplicates()

############################################
# Weekly PROs - MRC
############################################
pro_mrc = pd.read_csv("<YOUR_DATA_PATH>/copd-dataset/CopdDatasetProMrc.txt", delimiter="|")
pro_mrc = pro_mrc.merge(
    data[["StudyId", "IndexDate", "FirstSubmissionDate", "LatestPredictionDate"]],
    on="StudyId",
    how="inner",
)

# Calculate engagement over service
pro_mrc = model_h.calc_total_pro_engagement(pro_mrc, "MRC")

# Calculate engagement over multiple time windows
for time_window in range(1, 7):
    pro_mrc_engagement = model_h.calc_pro_engagement_in_time_window(
        pro_mrc, "MRC", time_window=time_window, data=data
    )
    pro_mrc = pro_mrc.merge(pro_mrc_engagement, on=["StudyId", "IndexDate"], how="left")

# Calculate last PRO score
pro_mrc = model_h.calc_last_pro_score(pro_mrc, "MRC")

# Calculate the PRO score prior to the last PRO score
pro_mrc = model_h.calc_pro_score_prior_to_latest(pro_mrc, "MRC")

#############################
# Scores across time windows
#############################
# Mapping to calculate the difference between the latest PRO scores and both the average
# and previous PRO score
question_names_mrc = ["Q1"]
mapping_mrc = model_h.define_mapping_for_calcs(
    "MRC", question_names_mrc, prefixes=["Avg", "Prev"]
)

# Calculate average PRO score across various time windows (months) prior to IndexDate,
# ignoring the latest PRO score
for time_window in range(1, 7):
    pro_mrc = model_h.calc_pro_average(pro_mrc, "MRC", time_window=time_window)
    for key in mapping_mrc:
        model_h.calc_diff_pro_scores(
            pro_mrc, "MRC", key, mapping_mrc[key][0], time_window=time_window
        )

# Calculate difference between latest PRO score and PRO score prior to the latest
for key in mapping_mrc:
    model_h.calc_diff_pro_scores(pro_mrc, "MRC", key, mapping_mrc[key][1])

# Remove unwanted columns and duplicates
pro_mrc = pro_mrc.loc[
    :,
    ~(
        pro_mrc.columns.str.startswith("Avg")
        | pro_mrc.columns.str.startswith("MRC")
        | pro_mrc.columns.str.startswith("Prev")
        | pro_mrc.columns.str.startswith("Response")
    ),
]
pro_mrc = pro_mrc.drop(
    columns=[
        "SubmissionTime",
        "Score",
        "FirstSubmissionDate",
        "TimeInService",
        "TimeSinceSubmission",
        "LatestPredictionDate",
        "LatestPRODate",
    ]
)
pro_mrc = pro_mrc.drop_duplicates()

############################################
# Daily PROs - CAT
############################################
pro_cat = pd.read_csv("<YOUR_DATA_PATH>/copd-dataset/CopdDatasetProCat.txt", delimiter="|")
pro_cat = pro_cat.merge(
    data[["StudyId", "IndexDate", "FirstSubmissionDate", "LatestPredictionDate"]],
    on="StudyId",
    how="inner",
)

# Calculate engagement over service and 1 month prior to index date
pro_cat = model_h.calc_total_pro_engagement(pro_cat, "CAT")

# Calculate engagement over multiple time windows
for time_window in range(1, 7):
    pro_cat_engagement = model_h.calc_pro_engagement_in_time_window(
        pro_cat, "CAT", time_window=time_window, data=data
    )
    pro_cat = pro_cat.merge(pro_cat_engagement, on=["StudyId", "IndexDate"], how="left")

# Calculate PRO average for the week before the index date
pro_cat = model_h.calc_pro_average(pro_cat, "CAT", avg_period="WeeklyAvg")

# Calculate PRO average for the week before most recent week to the index date
pro_cat = model_h.calc_pro_average(pro_cat, "CAT", avg_period="WeekPrevAvg")

#############################
# Scores across time windows
#############################
# Mapping to calculate the difference between the latest PRO scores and both the average
# and previous PRO score
question_names_cat = ["Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7", "Q8", "Score"]
mapping_cat = model_h.define_mapping_for_calcs(
    "CAT", question_names_cat, prefixes=["LongerAvg", "WeekPrevAvg"]
)

# Calculate average PRO score across various time windows (months) prior to IndexDate,
# ignoring the latest PRO score
for time_window in range(1, 7):
    pro_cat = model_h.calc_pro_average(
        pro_cat, "CAT", time_window=time_window, avg_period="LongerAvg"
    )
    for key in mapping_cat:
        model_h.calc_diff_pro_scores(
            pro_cat, "CAT", key, mapping_cat[key][0], time_window=time_window
        )

# Calculate difference between latest PRO score and PRO score prior to the latest
for key in mapping_cat:
    model_h.calc_diff_pro_scores(pro_cat, "CAT", key, mapping_cat[key][1])

# Remove unwanted columns and duplicates
pro_cat = pro_cat.loc[
    :,
    ~(
        pro_cat.columns.str.startswith("WeekPrev")
        | pro_cat.columns.str.startswith("Longer")
        | pro_cat.columns.str.startswith("CAT")
        | pro_cat.columns.str.startswith("Response")
    ),
]
pro_cat = pro_cat.drop(
    columns=[
        "Score",
        "SubmissionTime",
        "FirstSubmissionDate",
        "LatestPredictionDate",
        "TimeInService",
        "AvgStartDate",
        "WeekStartDate",
    ]
)
pro_cat = pro_cat.drop_duplicates()

############################################
# Daily PROs - Symptom Diary
############################################
# Symptom diary have some questions that are numeric and some that are categorical
pro_sd = pd.read_csv(
    "<YOUR_DATA_PATH>/copd-dataset/CopdDatasetProSymptomDiary.txt", delimiter="|"
)
pro_sd = pro_sd.merge(
    data[["StudyId", "IndexDate", "FirstSubmissionDate", "LatestPredictionDate"]],
    on="StudyId",
    how="inner",
)

# Calculate engagement over service
pro_sd = model_h.calc_total_pro_engagement(pro_sd, "SymptomDiary")
pro_sd_engagement = pro_sd[
    ["StudyId", "PatientId", "IndexDate", "TotalEngagementSymptomDiary"]
]

# Calculate engagement over multiple time windows
for time_window in range(1, 7):
    pro_sd_engagement_tw = model_h.calc_pro_engagement_in_time_window(
        pro_sd, "SymptomDiary", time_window=time_window, data=data
    )
    pro_sd_engagement = pro_sd_engagement.merge(
        pro_sd_engagement_tw, on=["StudyId", "IndexDate"], how="left"
    )
pro_sd_engagement = pro_sd_engagement.drop_duplicates()

###############################
# Numeric questions
# (Q1, Q2)
# Q3 included for comparison
###############################
# Calculate PRO average for the week before the index date
pro_sd_numeric = pro_sd[
    [
        "StudyId",
        "PatientId",
        "IndexDate",
        "SubmissionTime",
        "Score",
        "SymptomDiaryQ1",
        "SymptomDiaryQ2",
        "SymptomDiaryQ3",
    ]
]
pro_sd_numeric = model_h.calc_pro_average(
    pro_sd_numeric, "SymptomDiary", avg_period="WeeklyAvg"
)

# Calculate PRO average for the week before most recent week to the index date
pro_sd_numeric = model_h.calc_pro_average(
    pro_sd_numeric, "SymptomDiary", avg_period="WeekPrevAvg"
)

#############################
# Scores across time windows
#############################
# Mapping to calculate the difference between the latest PRO scores and both the average
# and previous PRO score
question_names_sd = ["Q1", "Q2", "Q3"]
mapping_sd = model_h.define_mapping_for_calcs(
    "SymptomDiary", question_names_sd, prefixes=["LongerAvg", "WeekPrevAvg"]
)

# Calculate average PRO score across various time windows (months) prior to IndexDate,
# ignoring the latest PRO score
for time_window in range(1, 7):
    pro_sd_numeric = model_h.calc_pro_average(
        pro_sd_numeric, "SymptomDiary", time_window=time_window, avg_period="LongerAvg"
    )
    for key in mapping_sd:
        model_h.calc_diff_pro_scores(
            pro_sd_numeric,
            "SymptomDiary",
            key,
            mapping_sd[key][0],
            time_window=time_window,
        )

# Calculate difference between latest PRO score and PRO score prior to the latest week
for key in mapping_sd:
    model_h.calc_diff_pro_scores(pro_sd_numeric, "SymptomDiary", key, mapping_sd[key][1])

###############################
# Binary questions
# (Q3)
###############################
# Calculate sum of binary values across previous months
sd_sum_all = pro_sd_numeric[["StudyId", "IndexDate"]]
sd_sum_all = sd_sum_all.drop_duplicates()
for time_window in range(1, 7):
    sd_sum = model_h.calc_sum_binary_vals(
        pro_sd_numeric, binary_cols=["SymptomDiaryQ3"], time_window=time_window
    )
    sd_sum_all = sd_sum_all.merge(sd_sum, on=["StudyId", "IndexDate"], how="left")

# Scale sums by how often patients responded
sd_sum_all = sd_sum_all.merge(
    pro_sd_engagement, on=["StudyId", "IndexDate"], how="left"
)
mapping_scaling = {}
for time_window in range(1, 7):
    mapping_scaling["SumSymptomDiaryQ3TW" + str(time_window)] = (
        "EngagementSymptomDiaryTW" + str(time_window)
    )
for key in mapping_scaling:
    model_h.scale_sum_to_response_rate(sd_sum_all, key, mapping_scaling[key])

# Combine numeric and binary dfs
pro_sd_full = pro_sd_numeric.merge(
    sd_sum_all, on=["StudyId", "PatientId", "IndexDate"], how="left"
)

# Remove unwanted columns from numeric df
pro_sd_full = pro_sd_full.loc[
    :,
    ~(
        pro_sd_full.columns.str.startswith("WeekPrev")
        | pro_sd_full.columns.str.startswith("Longer")
        | pro_sd_full.columns.str.startswith("Symptom")
        | pro_sd_full.columns.str.startswith("Sum")
        | pro_sd_full.columns.str.startswith("Response")
    ),
]
pro_sd_full = pro_sd_full.drop(
    columns=[
        "Score",
        "SubmissionTime",
        "AvgStartDate",
        "TimeWindowStartDate",
        "WeekStartDate",
    ]
)
pro_sd_full = pro_sd_full.drop_duplicates()

############################################################################
# Combine PROs with main df
############################################################################
data = data.merge(pro_eq5d, on=["StudyId", "PatientId", "IndexDate"], how="left")
data = data.merge(pro_mrc, on=["StudyId", "PatientId", "IndexDate"], how="left")
data = data.merge(pro_cat, on=["StudyId", "PatientId", "IndexDate"], how="left")
data = data.merge(pro_sd_full, on=["StudyId", "PatientId", "IndexDate"], how="left")

# Calculate mean for features grouped by outcome
feat_to_explore = data.loc[:, "TotalEngagementEQ5D":"ScaledSumSymptomDiaryQ3TW6"]
feat_to_explore.loc[:, "ExacWithin3Months"] = data.loc[:, "ExacWithin3Months"]
grouped_data_by_outcome = feat_to_explore.groupby("ExacWithin3Months").mean()
grouped_data_by_outcome = grouped_data_by_outcome.T

############################################################################
# Plotting
############################################################################
##############################
# EQ5D Boxplots
##############################
# Plotting score values
cols_for_plotting = model_h.create_cols_for_plotting(
    "EQ5D", question_col_names=question_names_eq5d
)
for key in cols_for_plotting:
    model_h.plot_feature_signal(
        data,
        nrows=3,
        ncols=3,
        figsize=(12, 12),
        cols_to_plot=cols_for_plotting[key],
        fig_name=key + "_boxplot",
    )

# Plotting engagement
cols_for_plotting = model_h.create_cols_for_plotting("EQ5D", var_engagement=True)
for key in cols_for_plotting:
    model_h.plot_feature_signal(
        data,
        nrows=2,
        ncols=3,
        figsize=(12, 12),
        cols_to_plot=cols_for_plotting[key],
        fig_name=key + "_engagement",
    )

##############################
# MRC Boxplots
##############################
# Plotting score values
cols_for_plotting = model_h.create_cols_for_plotting(
    "MRC", question_col_names=question_names_mrc
)
for key in cols_for_plotting:
    model_h.plot_feature_signal(
        data,
        nrows=3,
        ncols=3,
        figsize=(12, 12),
        cols_to_plot=cols_for_plotting[key],
        fig_name=key + "_boxplot",
    )

# Plotting engagement
cols_for_plotting = model_h.create_cols_for_plotting("MRC", var_engagement=True)
for key in cols_for_plotting:
    model_h.plot_feature_signal(
        data,
        nrows=2,
        ncols=3,
        figsize=(12, 12),
        cols_to_plot=cols_for_plotting[key],
        fig_name=key + "_engagement",
    )

##############################
# CAT Boxplots
##############################
# Plotting score values
cols_for_plotting = model_h.create_cols_for_plotting(
    "CAT", question_col_names=question_names_cat
)
for key in cols_for_plotting:
    model_h.plot_feature_signal(
        data,
        nrows=3,
        ncols=3,
        figsize=(12, 12),
        cols_to_plot=cols_for_plotting[key],
        fig_name=key + "_boxplot",
    )
# Plotting engagement
cols_for_plotting = model_h.create_cols_for_plotting("CAT", var_engagement=True)
for key in cols_for_plotting:
    model_h.plot_feature_signal(
        data,
        nrows=2,
        ncols=3,
        figsize=(12, 12),
        cols_to_plot=cols_for_plotting[key],
        fig_name=key + "_engagement",
    )

##############################
# SymptomDiary Boxplots
##############################
# Plotting score values
cols_for_plotting = model_h.create_cols_for_plotting(
    "SymptomDiary", question_col_names=question_names_sd
)
for key in cols_for_plotting:
    model_h.plot_feature_signal(
        data,
        nrows=3,
        ncols=3,
        figsize=(12, 12),
        cols_to_plot=cols_for_plotting[key],
        fig_name=key + "_boxplot",
    )

# Plotting engagement
cols_for_plotting = model_h.create_cols_for_plotting("SymptomDiary", var_engagement=True)
for key in cols_for_plotting:
    model_h.plot_feature_signal(
        data,
        nrows=2,
        ncols=3,
        figsize=(12, 12),
        cols_to_plot=cols_for_plotting[key],
        fig_name=key + "_engagement",
    )