-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
1047 lines (850 loc) · 43 KB
/
index.Rmd
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
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "HIIT vs. MICT"
output:
html_document:
fig_caption: yes
theme: cerulean
toc: yes
toc_depth: 3
toc_float: yes
pdf_document:
toc: yes
toc_depth: '3'
word_document:
toc: yes
toc_depth: '3'
---
This is designed to track study progress! Below is a weekly update.
- **Things to keep track of:**
- Are green/blue participants on track with workouts?
- Have participants at the end...
- completed EP surveys and enough workouts?
- willing to crossover?
- Are new participants willing to do biopsy?
```{r setup, include=FALSE}
# Load packages
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(readxl)
library(ggplot2)
library(table1)
library(lubridate)
library(knitr)
library(kableExtra)
library(ggpubr)
library(stringr)
library(zoo)
```
```{r demog, message=FALSE, warning=FALSE, echo=FALSE}
# Read in the data generated by REDCapAPI.Rmd
demog<-read.csv("/Users/aubreykr/Google Drive/Shared drives/HIIT and Endurance Study/Data/data/Redcap/Processed_Data/64208_Demographics_Processed.csv")
#----Data Cleaning, features----------
# Pull in data to see if EP surveys are done
epsurveys<-read.csv("/Users/aubreykr/Google Drive/Shared drives/HIIT and Endurance Study/Data/data/Redcap/Raw_Data/64208_WorkoutDates_Raw.csv")
epsurveys<-epsurveys %>%
dplyr::select(record_id, redcap_event_name, perceived_stress_scale_pss10_complete)
epsurveys<-epsurveys %>%
filter(redcap_event_name == "week_12_ep_surveys_arm_1")
epsurveys<-epsurveys %>%
dplyr::rename(EP_surveys = perceived_stress_scale_pss10_complete) %>%
dplyr::select(record_id, EP_surveys)
epsurveys<-epsurveys %>%
mutate(EP_surveys = ifelse(EP_surveys == "Complete", "YES", ""))
# Create variable for crossover ppts
demog<-demog %>%
mutate(crossover = ifelse(record_id >=1000, "yes", "no"))
# Calculate expected num of workouts based on week they are on
demog$expected_num <- gsub("Week ", "", demog$current_week)
demog$expected_num <- (as.numeric(demog$expected_num) - 1)*3
# Flag people who need to be extended
demog$EXTEND <- ifelse(demog$expected_num - demog$total_workouts_in_REDCap >=4, "YES", " ")
demog$EXTEND[demog$Group == "Control"]<- " "
# EP vo2 complete?
demog$EP_VO2[is.na(demog$ep_vo2_max)==FALSE] <- "YES"
demog$EP_VO2[is.na(demog$ep_vo2_max)==TRUE] <- " "
# if missing, they have enrolled and update this
demog$enrollment_status[is.na(demog$enrollment_status) == TRUE] <- "Enrolled (not screened yet)"
# Specify order of weeks for plots
demog$current_week <- factor(demog$current_week, levels=c("Not Training Yet", "Week 1", "Week 2", "Week 3", "Week 4", "Week 5", "Week 6", "Week 7", "Week 8", "Week 9", "Week 10", "Week 11", "Week 12", "Week 13", "Week 14"))
# new column for target HR zone depending on group
demog<-demog %>%
mutate(HR_zone = case_when(Group == "MICT" ~ bl_heart_rate_mict,
Group == "HIIT" ~ bl_heart_rate_hiit))
# manually assign HR zone for crossover records
demog$HR_zone[demog$record_id == "1070"] <- "122-134"
demog$HR_zone[demog$record_id == "1076"] <- "114-126"
demog$HR_zone[demog$record_id == "1103"] <- "133-149"
demog<-full_join(demog, epsurveys, by=c("record_id"))
```
## Where are participants this week?
This was last updated on `r format(Sys.Date(), format="%B %d, %Y")`.
```{r firstcode, message=FALSE, warning=FALSE, echo=FALSE}
#---------Snapshot of participant progress------------
ongoing<-demog %>% filter(enrollment_status == "On-going Randomized" & is.na(ep_vo2_max)==TRUE | enrollment_status=="Enrolled (not screened yet)" | record_id == 127)
current_num<-length(unique(ongoing$record_id))
demog %>%
filter(enrollment_status == "On-going Randomized" & is.na(ep_vo2_max)==TRUE | enrollment_status=="Enrolled (not screened yet)" | record_id ==127) %>%
ggplot(aes(x = current_week, fill=Group, group = factor(record_id))) + geom_bar() +
geom_text(stat = "count", aes(label = paste0(record_id, sep="\n(", total_workouts_in_REDCap, sep=")"), y = ..count..),
position = position_stack(vjust = 0.5), color = "black", size = 3, alpha=1) +
scale_x_discrete(drop = FALSE) + theme_bw() +
theme(axis.text.x = element_text(angle = 55, vjust = 1, hjust = 1)) +
xlab(paste0("Plot Last Updated:", sep = " ", Sys.Date())) +
ggtitle(paste0("Current Participants: n=", sep="", current_num)) + labs(fill = "Record ID") + theme(plot.title = element_text(hjust = 0.5)) +
scale_y_continuous(breaks = seq(0, 30, 2))
```
## Workout Adherence
### On-going participants
```{r workouts0, message=FALSE, warning=FALSE, echo=FALSE}
counts<-demog %>%
filter(enrollment_status == "On-going Randomized" & current_week !="Not Training Yet" & is.na(ep_vo2_max)==TRUE)
active_num <- length(unique(counts$record_id))
# Filter for participants who are on-going
demog %>%
filter(enrollment_status == "On-going Randomized" & current_week !="Not Training Yet" & is.na(ep_vo2_max)==TRUE) %>%
dplyr::select(record_id, current_week, Group, total_workouts_in_REDCap, expected_num, quality_fraction, name_of_participant_buddy, HR_zone, EXTEND, EP_surveys) %>%
arrange(current_week, record_id) %>%
kbl(col.names = c("Record ID","Current Week","Group","Total Wkts", "Expected Num", "Quality (%)", "Buddy", "HR Target", "EXTEND", "EP_surveys"), align="c", escape=FALSE, caption=paste0("Active Participants: n=", sep="", active_num)) %>%
kable_styling(full_width = F, position = "center", font_size = 14, latex_options = "striped", bootstrap_options = c("striped", "hover"))
# EP survey check
demog %>%
filter(enrollment_status == "On-going Randomized" & (EP_VO2 != " " | current_week == "Week 12") & !record_id %in% c(76, 1076, 91, 92, 94, 98, 103, 105, 107, 110, 112, 1091, 117, 119, 123, 115))%>%
dplyr::select(record_id, current_week, Group, total_workouts_in_REDCap, expected_num, quality_fraction, name_of_participant_buddy, HR_zone, EP_VO2, EP_surveys) %>%
arrange(current_week, record_id) %>%
kbl(col.names = c("Record ID","Current Week","Group","Total Wkts", "Expected Num", "Quality (%)", "Buddy", "HR Target", "EP_Vo2?", "EP_surveys"), align="c", escape=FALSE, caption=paste0("EP survey check (randomized and EP VO2 done / at Week 12)")) %>%
kable_styling(full_width = F, position = "center", font_size = 14, latex_options = "striped", bootstrap_options = c("striped", "hover"))
#Active controls
# demog %>%
# filter(enrollment_status == "On-going Randomized" & Group == "Control" & current_week !="Not Training Yet" & !record_id %in% c(103, 76, 98, 91) & record_id <= 1000) %>%
# dplyr::select(record_id, current_week, Group, name_of_participant_buddy, control_crossover, EP_VO2) %>%
# arrange(current_week, name_of_participant_buddy) %>%
# kbl(col.names = c("Record ID","Current Week","Group","Buddy", "Crossover?", "EP VO2?"), align="c", escape=FALSE, caption="Active Controls") %>%
# kable_styling()
demog$bl_VO2 <- ifelse(is.na(demog$bl_vo2_max), "No", "Yes")
# upcoming ppts
demog %>%
filter(enrollment_status %in% c( "On-going Randomized", "Enrolled (not screened yet)") & current_week =="Not Training Yet" ) %>%
dplyr::select(record_id, current_week, Group, name_of_participant_buddy, HR_zone, bl_VO2) %>%
kbl(col.names = c("Record ID","Current Week","Group","Buddy", "HR zone", "BL VO2 done?"), align="c", escape=FALSE, caption="Upcoming ppts") %>%
kable_styling()
# not marked as completed, but did VO2
# demog %>%
# filter(enrollment_status != "Completed" & is.na(ep_vo2_max)==FALSE) %>%
# dplyr::select(record_id, Group, name_of_participant_buddy, EP_surveys) %>%
# arrange(desc(record_id)) %>%
# kbl(col.names = c("Record ID","Group","Buddy", "EP surveys?"), align="c", escape=FALSE, caption="Check on completed ppt EP surveys:") %>%
# kable_styling()
#Mitra processing
# mitra<-demog %>%
# select(record_id, enrollment_status, Group)
#
# write.csv(mitra,"/Users/aubreykr/Desktop/mitradates.csv")
#
# View(mitra %>%
# filter(!record_id %in% c(3,4,5,6,7,8,10,12,14,18,19,20,21,26,29,30,36,37,38,40,45,46,50,51,56,60,64,71,72,73,74,75,76,77,80,81,87,88,89,90,95)))
#
# mitras<-mitra %>%
# filter(enrollment_status %in% c("Screen failed", "Withdrawn (before training)", "Withdrawn (after training)", "Lost to Follow-Up (before training)", "Lost to Follow-Up (after training)") | record_id >=74 & record_id <1000)
# #df<-read.csv("/Users/aubreykr/Desktop/Mitras/Mitra_ScreenFail_Withdraw.csv")
#mitras
#df<-df %>%
#rename(record_id = Record.ID)
#mitras<-left_join(mitras, df)
#mitras %>%
#filter(Date.of.Stress.Test.Visit != "" | Date.of.Endpoint.Stress.Test.Visit !="")
```
### Crossover Participant Tracking
```{r crossovers, message=FALSE, warning=FALSE, echo=FALSE}
demog$crossover_rand_group[demog$crossover_rand_group == "Endurance"]<- "MICT"
demog %>%
filter(crossover == "yes") %>%
dplyr::select(record_id, Group, EP_VO2) %>%
kbl(col.names = c("Record ID","Rand Group", "EP VO2 done?"), align="c", escape=FALSE, caption="Crossover Participants") %>%
kable_styling()
```
```{r workouts,message=FALSE, warning=FALSE, echo=FALSE}
### Completed MICT participants
#Filter for participants who are completed and MICT
# completed_mict<-demog %>%
# filter(enrollment_status == "Completed" & Group == "MICT") %>%
# dplyr::select(record_id, quality_workouts_in_REDCap, percent_complete_of_36_wkts, number_polar_used, number_fitbit_used, total_workouts_in_REDCap, sex, agegroup, HR_zone)
#
# completed_mict %>%
# arrange(as.numeric(record_id)) %>%
# kable(col.names = c("Record ID", "Quality Wkts", "Percent Complete of 36 Wkts", "Polar Worn", "Fitbit Worn", "Total Wkts", "Sex", "Age", "HR Target"), align="c") %>%
# kable_styling(full_width = F, position = "center", font_size = 14, latex_options = "striped", bootstrap_options = c("striped", "hover"))
```
```{r workouts2,message=FALSE, warning=FALSE, echo=FALSE}
### Completed HIIT participants
# Filter for participants who are completed and HIIT
# completed_hiit<-demog %>%
# filter(enrollment_status == "Completed" & Group == "HIIT") %>%
# dplyr::select(record_id, quality_workouts_in_REDCap, percent_complete_of_36_wkts, number_polar_used,number_fitbit_used, total_workouts_in_REDCap, sex, agegroup, HR_zone)
#
# completed_hiit %>%
# arrange(as.numeric(record_id)) %>%
# kable(col.names = c("Record ID", "Quality Wkts", "Percent Complete of 36 Wkts", "Polar Worn", "Fitbit Worn", "Total Wkts", "Sex", "Age", "HR Target"), align="c") %>%
# kable_styling(full_width = F, position = "center", font_size = 14, latex_options = "striped", bootstrap_options = c("striped", "hover"))
```
```{r workouts3,message=FALSE, warning=FALSE, echo=FALSE}
### HIIT vs. MICT
#demog %>%
# filter(enrollment_status == "Completed" & Group %in% c("HIIT", "MICT")) %>%
# ggplot(aes(y=percent_complete_of_36_wkts, x=Group)) + geom_boxplot() + geom_point() + ylab("Percent Complete of 36 Workouts") +
# ggtitle("Percent Complete of 36 Workouts by Randomization Group") + theme_bw()+ theme(plot.title = element_text(hjust = 0.5)) + ylim(c(0,100))
#
# demog %>%
# filter(enrollment_status == "Completed" & Group %in% c("HIIT", "MICT")) %>%
# ggplot(aes(y=total_workouts_in_REDCap, x=Group)) + geom_boxplot() +geom_point() + geom_hline(yintercept = 32, linetype="dashed") + ylab("Total Workouts in REDCap") +
# ggtitle("Completed Participants (n=30): Total Workouts") + theme_bw()+ theme(plot.title = element_text(hjust = 0.5)) + ylim(c(0,40))
#
# demog %>%
# filter(enrollment_status == "Completed" & Group %in% c("HIIT", "MICT")) %>%
# ggplot(aes(y=quality_workouts_in_REDCap, x=Group)) + geom_boxplot() +geom_jitter(aes(color=factor(record_id))) + geom_hline(yintercept = 32, linetype="dashed") + ylab("Total Workouts in REDCap") +
# ggtitle("Completed Participants (n=30): Good Workouts") + theme_bw()+ theme(plot.title = element_text(hjust = 0.5)) + ylim(c(0,40)) + labs(color="Participant Num")
```
### NUMBER COMPLETED
```{r progressstrata2, message=FALSE, warning=FALSE, echo=FALSE}
cohort<-demog %>%
filter(is.na(ep_vo2_max)==FALSE)
completed_num<-cohort %>%
filter(is.na(ep_vo2_max)==FALSE & record_id <= 1000)
completed_num<-length(completed_num$record_id)
cohort %>%
filter(is.na(ep_vo2_max)==FALSE & record_id < 1000) %>%
ggplot(aes(x=Group, fill=Group, alpha=0.8))+geom_bar(stat="count")+ theme_bw()+
theme(plot.title = element_text(hjust = 0.5))+xlab("Group")+ylab("Number")+scale_fill_discrete(name = "Group")+
geom_text(aes(label=..count..),stat='count',vjust=1.5) +
ggtitle(paste0(completed_num, sep=" ", "Completed with VO2 max pre/post")) + guides(alpha = "none")
# cohort %>%
# filter(is.na(ep_vo2_max)==FALSE & record_id > 1000) %>%
# ggplot(aes(x=Group, fill=Group, alpha=0.8))+geom_bar(stat="count")+
# theme(plot.title = element_text(hjust = 0.5))+xlab("Group")+ylab("Number")+scale_fill_discrete(name = "Group")+
# geom_text(aes(label=..count..),stat='count',vjust=1.5) +
# ggtitle(paste0("Num Crossovers Completed")) + guides(alpha = "none")
```
### Progress toward filling 4 strata
```{r progressstrata, message=FALSE, warning=FALSE, echo=FALSE}
# Create sex + agebin variable
demog$strata[demog$sex == "Female" & demog$agegroup == "18-34 yrs"]<-"F, 18-35"
demog$strata[demog$sex == "Female" & demog$agegroup == "35-65 yrs"]<-"F, 35-65"
demog$strata[demog$sex == "Male" & demog$agegroup == "18-34 yrs"]<-"M, 18-34"
demog$strata[demog$sex == "Male" & demog$agegroup == "35-65 yrs"]<-"M, 35-64"
cohort<-demog %>%
filter(enrollment_status == "On-going Randomized" & record_id <1000 | enrollment_status == "Completed" & record_id <1000)
cohort %>%
filter(is.na(ep_vo2_max)==FALSE & record_id < 1000) %>%
ggplot(aes(x=Group, fill=Group, alpha=0.8))+geom_bar(stat="count")+theme_bw()+
theme(plot.title = element_text(hjust = 0.5))+xlab("Group")+ylab("Number")+scale_fill_discrete(name = "Group")+
geom_text(aes(label=..count..),stat='count',vjust=1.5) +
ggtitle(paste0(completed_num, sep=" ", "Completed with CPX pre/post")) + guides(alpha = "none") + facet_wrap(~strata)
# Progress Toward Filling 4 Strata (M, F, 18-35 yrs, 35-55 yrs)
cohort %>%
ggplot(aes(x=Group, fill=Group, alpha=0.8))+geom_bar(stat="count")+theme_bw()+
theme(plot.title = element_text(hjust = 0.5))+xlab("Group")+ylab("Number")+scale_fill_discrete(name = "Group")+facet_wrap(~strata)+
geom_text(aes(label=..count..),stat='count',vjust=1.5) +
ggtitle(paste("On-going Randomized or Completed Study: n=", sep="", length(unique(cohort$record_id)))) + guides(alpha = "none")
cohort<-cohort %>%
filter(record_id != "81" & record_id !="69" & record_id !="1070" & record_id !="1076" & record_id !="1091")
cohort%>%
ggplot(aes(x=Group, fill=Group, alpha=0.8))+geom_bar(stat="count")+ theme_bw()+
theme(plot.title = element_text(hjust = 0.5))+xlab("Group")+ylab("Number")+scale_fill_discrete(name = "Group")+
geom_text(aes(label=..count..),stat='count',vjust=1.5) +
ggtitle(paste("Sum of on-going + completed: n=", sep="", length(unique(cohort$record_id)))) + guides(alpha = "none")
```
## Study Progress
```{r newppl, message=FALSE, warning=FALSE, echo=FALSE}
# Order levels of enrollment status
demog<-demog %>%
mutate(enrollment_status = ifelse(is.na(ep_vo2_max)==FALSE & record_id<1000, "Completed", ifelse(
is.na(ep_vo2_max)==FALSE & record_id>1000, "Completed (crossover)", enrollment_status
)))
demog$enrollment_status <- factor(demog$enrollment_status, levels = c("Enrolled (not screened yet)", "Lost to Follow-Up (before training)", "Screen failed", "Withdrawn (before training)", "On-going Randomized", "Withdrawn (after training)", "Lost to Follow-Up (after training)", "Completed", "Completed (crossover)"))
ggplot(aes(x=enrollment_status, fill = enrollment_status, alpha=0.8), data=demog)+geom_bar(stat="count")+theme_bw()+
ggtitle(paste("Total Participants: n=", sep="", length(unique(demog$record_id))))+ theme(plot.title = element_text(hjust = 0.5))+xlab("Participant Status")+ylab("Number")+scale_fill_discrete(name = "Group")+ theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))+theme(legend.position = "none")+ geom_text(aes(label=..count..),stat='count',vjust=1.5)
```
### NUMBER CONSENTED
```{r consented, echo=FALSE, message=FALSE, warning=FALSE}
# PLOT CONSENTING
demog$date_consent<-as.yearmon(demog$date_consent)
demog$date_consent <- as.factor(demog$date_consent)
demog$date_consent<-factor(demog$date_consent, levels=c("Feb 2023", "Mar 2023", "Apr 2023", "May 2023", "Jun 2023", "Jul 2023", "Aug 2023", "Sep 2023", "Oct 2023", "Nov 2023", "Dec 2023", "Jan 2024", "Feb 2024", "Mar 2024", "Apr 2024", "May 2024", "Jun 2024", "Jul 2024", "Aug 2024", "Sep 2024", "Oct 2024", "Nov 2024", "Dec 2024", "Jan 2025", "Feb 2025"))
consent<-demog %>%
filter(is.na(date_consent)==FALSE)
consented_num<-length(consent$record_id)
demog %>%
filter(is.na(date_consent)==FALSE) %>%
ggplot(aes(x=date_consent)) + geom_bar(color="purple")+stat_count(geom = "text", color="white", aes(label = ..count..), vjust = 2)+theme_bw()+
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) + ggtitle(paste0("Number consented:", sep=" ", consented_num)) + theme(plot.title = element_text(hjust=0.5))+
scale_y_continuous(breaks = seq(0,15,by=2)) + xlab("Month Consented")
```
## Month-by-Month Projections
Note: average counts exclude the first month and Dec 2023 for winter closure which had lower rates.
```{r formatdates, echo=FALSE, message=FALSE, warning=FALSE}
# Filter for relevant variables: start and end month, rand group, record_id
projected <- demog %>%
filter(enrollment_status %in% c("Completed", "On-going Randomized")) %>%
dplyr::select(record_id, Group, start_month, end_month)
# Specify order of months
projected$start_month<-as.factor(projected$start_month)
projected$end_month<-as.factor(projected$end_month)
projected$start_month<-factor(projected$start_month, levels=c("Apr 2023", "May 2023", "Jun 2023", "Jul 2023", "Aug 2023", "Sep 2023", "Oct 2023", "Nov 2023", "Dec 2023", "Jan 2024", "Feb 2024", "Mar 2024", "Apr 2024", "May 2024", "Jun 2024", "Jul 2024", "Aug 2024", "Sep 2024", "Oct 2024", "Nov 2024", "Dec 2024", "Jan 2025", "Feb 2025"))
projected$end_month<-factor(projected$end_month, levels=c("Apr 2023", "May 2023", "Jun 2023", "Jul 2023", "Aug 2023", "Sep 2023", "Oct 2023", "Nov 2023", "Dec 2023", "Jan 2024", "Feb 2024", "Mar 2024", "Apr 2024", "May 2024", "Jun 2024", "Jul 2024", "Aug 2024", "Sep 2024", "Oct 2024", "Nov 2024", "Dec 2024", "Jan 2025", "Feb 2025"))
projected$start_month[is.na(projected$start_month)]<-"Feb 2024"
projected$end_month[is.na(projected$end_month)]<-"May 2024"
```
```{r plotprojected, echo=FALSE, message=FALSE, warning=FALSE}
# Plots
current_date <- Sys.Date()
current_date <- as.yearmon(current_date)
current_date <- as.factor(current_date)
counts_start<-projected %>%
group_by(start_month) %>%
count()
counts_start<-counts_start %>%
filter(!start_month %in% c("Apr 2023", "Jan 2024"))
avg_start <- round(mean(counts_start$n),2)
counts_end<-projected %>%
group_by(end_month) %>%
count()
counts_end<-counts_end %>%
filter(!end_month %in% c("Aug 2023", "Jan 2024"))
avg_end <- round(mean(counts_end$n),2)
projected %>%
ggplot(aes(x=start_month)) + geom_bar(fill="#F8766D") + stat_count(geom = "text", color="white", aes(label = ..count..), vjust = 2) +theme_bw()+
ggtitle(paste0("Start Months, average count/month:", sep=" ", avg_start)) + theme(plot.title = element_text(hjust = 0.5)) + geom_vline(xintercept = current_date, linetype="dotted", color="black")+ theme(axis.text.x = element_text(angle = 55, vjust = 1, hjust = 1))
projected %>%
ggplot(aes(x=end_month)) + geom_bar(fill="#00BFC4") + stat_count(geom = "text", color="white", aes(label = ..count..), vjust = 2) +theme_bw()+
ggtitle(paste0("End Months, average count/month:", sep=" ", avg_end)) + theme(plot.title = element_text(hjust = 0.5))+ geom_vline(xintercept = current_date, linetype="dotted", color="black") + theme(axis.text.x = element_text(angle = 55, vjust = 1, hjust = 1))
# Combined start + end plot
num_projected <- length(unique(projected$record_id))
# Gather and color by timepoint
projected <- gather(projected, key = "Timepoint", value = "Month", c("start_month", "end_month"))
projected$Timepoint <- factor(projected$Timepoint, levels=c("start_month", "end_month"))
projected$Month<-factor(projected$Month, levels=c("Apr 2023", "May 2023", "Jun 2023", "Jul 2023", "Aug 2023", "Sep 2023", "Oct 2023", "Nov 2023", "Dec 2023", "Jan 2024", "Feb 2024", "Mar 2024", "Apr 2024", "May 2024", "Jun 2024", "Jul 2024", "Aug 2024", "Sep 2024", "Oct 2024", "Nov 2024", "Dec 2024", "Jan 2025", "Feb 2025", "Mar 2025"))
ggplot(aes(x=Month, fill=Timepoint), data=projected) + geom_bar() + theme_bw()+
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
ggtitle(paste0(num_projected, sep=" ", "completing the study by the last date plotted")) + theme(plot.title = element_text(hjust = 0.5))+ geom_vline(xintercept = current_date, linetype="dotted", color="black") + stat_count(geom = "text", color="white", aes(label = ..count..), vjust = 2) + scale_y_continuous(breaks = seq(0,20,by=2)) +theme(axis.text.x = element_text(angle = 55, vjust = 1, hjust = 1))
```
## Biopsy Tracker
```{r biopsy, message=FALSE, warning=FALSE, echo=FALSE}
demog$baseline_visit_biopsy_complete <- ifelse(demog$baseline_visit_biopsy_complete=="Complete", 1, 0)
demog$endpoint_visit_biopsy_complete <- ifelse(demog$endpoint_visit_biopsy_complete=="Complete", 1, 0)
biopsy<-demog %>%
filter(baseline_visit_biopsy_complete == 1 | endpoint_visit_biopsy_complete == 1) %>%
gather(key = "Timepoint", value="biopsy_completed", c("baseline_visit_biopsy_complete", "endpoint_visit_biopsy_complete"))
biopsy<-biopsy %>%
dplyr::select(record_id, enrollment_status, sex, agegroup, Group, Timepoint, biopsy_completed) %>%
mutate(Timepoint = ifelse(Timepoint=="baseline_visit_biopsy_complete", "Baseline", "Endpoint"))
biopsy$Group[biopsy$record_id == 1076] <- "MICT"
biopsy %>%
filter(biopsy_completed==1) %>%
group_by(Group, Timepoint) %>%
count() %>%
kable() %>%
kable_styling(full_width = FALSE)
biopsy %>%
filter(biopsy_completed==1) %>%
arrange(Group, record_id) %>%
dplyr::select(record_id, Group, Timepoint) %>%
kable() %>%
kable_styling(full_width = FALSE)
# biopsy %>%
# filter(biopsy_completed==1) %>%
# ggplot(aes(x=Group, fill=Timepoint))+geom_bar(position="dodge") + theme_bw() + ylim(c(0,5)) + ggtitle("Number of biopsies complete") + theme(plot.title = element_text(hjust = 0.5))
```
```{r demographics}
```
## Workout Tracking: Wearables vs. REDCap
```{r wearables, message=FALSE, warning=FALSE, echo=FALSE}
## PROCESSING DATA FROM GOOGLE DRIVE ##
# Read in wearable data from Google Drive
data<-read.csv("/Users/aubreykr/Library/CloudStorage/GoogleDrive-aubreykr@stanford.edu/Shared drives/HIIT and Endurance Study/Data/data/workout/workout_allevents.csv")
# Rename to record_id and place at front of dataset
data<-data %>%
dplyr::rename(record_id = ppt_id) %>%
dplyr::select(record_id, everything())
# Create date
data<-data %>%
mutate(date = as.Date(data$X_realtime))
# Unique participants in the dataset
#length(unique(data$date))
#length(unique(data$record_id))
#(unique(data$sourcetype))
#paste0("Participants in this dataset:", sep=" ", (list(unique(data$record_id))))
# COUNT POLAR WORKOUTS
# Count number of polar workouts
data_polar<-data %>%
filter(sourcetype == "WearablePolar") %>%
group_by(record_id, date) %>%
count()
# Create num minutes per workout column
data_polar$polar_minutes = data_polar$n/60
# COUNT FITBIT WORKOUTS
# Count number of fitbit workouts
data_fitbit<-data %>%
filter(sourcetype == "WearableFitbit") %>%
group_by(record_id, date) %>%
count()
# Create num minutes per workout column
data_fitbit$fitbit_minutes = data_fitbit$n/60
# remove n column
data_polar<-data_polar %>%
dplyr::select(-c(n))
data_fitbit<-data_fitbit %>%
dplyr::select(-c(n))
# MERGE WEARABLE DATA
# Merge polar and fitbit dataframes
summary<-full_join(data_polar, data_fitbit, by=c("record_id", "date"))
# Total number workouts for Polar, Fitbit
num_polar_workouts <- summary %>%
filter(is.na(polar_minutes)!=TRUE) %>%
group_by(record_id) %>%
summarize(wearable_polar_workouts = length(unique(date)))
num_fitbit_workouts <- summary %>%
filter(is.na(fitbit_minutes)!=TRUE) %>%
group_by(record_id) %>%
summarize(wearable_fitbit_workouts = length(unique(date)))
# SUMMARIZE NUMBER WORKOUTS
#num_polar_workouts
#num_fitbit_workouts
wearables<-full_join(num_polar_workouts, num_fitbit_workouts, by="record_id")
```
```{r wearable merging, messages=FALSE, warning=FALSE, echo=FALSE}
## JOIN MYPHD/POLAR DATA WITH DEMOG FRAME ##
demog<-full_join(demog, wearables, by="record_id")
# calculate num missing
demog$num_missing_polar <- demog$wearable_polar_workouts - demog$number_polar_used
demog$num_missing_fitbit <- demog$wearable_fitbit_workouts - demog$number_fitbit_used
# set up data for table
completed<-demog %>%
filter(enrollment_status == "Completed" & Group != "Control") %>%
dplyr::select(record_id, number_polar_used, wearable_polar_workouts, num_missing_polar, number_fitbit_used, wearable_fitbit_workouts, num_missing_fitbit)
# create table
completed %>%
arrange(as.numeric(record_id)) %>%
kable(col.names = c("Record ID", "REDCap polar", "Wearable polar", "Num missing polar", "REDCap fitbit", "Wearable fitbit", "Num missing fitbit"), align="c") %>%
kable_styling(full_width = F, position = "center", font_size = 14, latex_options = "striped", bootstrap_options = c("striped", "hover"))
```
*Thanks everybody for your hard work!*
```{r vo2 analysis, echo=FALSE, include=FALSE, message=FALSE}
# vo2 <- gather(demog, key="Timepoint", value="VO2_Max", c(bl_vo2_max, ep_vo2_max))
# vo2$Timepoint[vo2$Timepoint == "bl_vo2_max"] <- "Week 0"
# vo2$Timepoint[vo2$Timepoint == "ep_vo2_max"] <- "Week 12"
#
# vo2 %>%
# filter(Group %in% c("HIIT", "MICT") & enrollment_status == "Completed") %>%
# ggplot(aes(x=Timepoint, y=VO2_Max)) + geom_boxplot() + geom_point()+
# labs(title = "VO2: Baseline vs. Endpoint", x = "Timepoint", y = "VO2 Peak (mL/kg)") + facet_wrap(~Group)+
# theme(plot.title=element_text(hjust=0.5)) + stat_compare_means(method = "t.test",
# label = "p.format",
# paired = TRUE)
# # percent change
# demog$vo2change <- (demog$ep_vo2_max - demog$bl_vo2_max) / demog$bl_vo2_max * 100
# demog$bmi_change <- demog$ep_bmi - demog$bl_bmi
# demog$bodyfatchange <- demog$ep_percent_body_fat - demog$bl_percent_body_fat
#
# demog %>%
# filter(enrollment_status == "Completed" & record_id != 4) %>%
# group_by(Group) %>%
# summarize(mean = mean(vo2change),
# sd = sd(vo2change))
#
#
# demog %>%
# filter(enrollment_status == "Completed" & record_id !="4") %>%
# ggplot(aes(y=vo2change, x=Group, color=sex, group=Group)) + geom_boxplot() + geom_point()+ theme_bw()+
# labs(title = "VO2 Max: Baseline vs. Endpoint", x = "Group", y = "% change in VO2 Max") +
# theme(plot.title=element_text(hjust=0.5)) + stat_compare_means(method = "t.test",
# label = "p.format",
# paired = TRUE) +
# geom_hline(yintercept = 0, linetype="dashed") + labs(color="Sex")
# colnames(demog)
```
```{r testdata, echo=FALSE, include=FALSE, message=FALSE, warning=FALSE}
# save<-demog %>%
# filter(enrollment_status == "Completed")
#
# label(save$Group) <- "Randomization Group"
# label(save$sex) <- "Sex"
# label(save$agegroup) <- "Age Group"
# label(save$race) <- "Race"
# label(save$vo2change) <- "VO2 max"
# label(save$bmi_change) <- "BMI "
# label(save$bodyfatchange) <- "Body Fat"
# label(save$quality_workouts_in_REDCap) <- "Workouts Completed"
# units(save$vo2change) <- "%"
# units(save$bmi_change) <- "kg/m2"
# units(save$bodyfatchange) <- "%"
# units(save$quality_workouts_in_REDCap) <- "%"
#
# my.render.cont <- function(x) {
# with(stats.default(x),
# sprintf("%0.2f (%0.1f)", MEAN, SD))
# }
#
# #table1(~sex + agegroup + vo2change + bmi_change + bodyfatchange + I(quality_workouts_in_REDCap/32 * 100) | Group, overall=F,
# # render.continuous=my.render.cont, render.missing=NULL, caption="Table 1. Participant Demographics and Preliminary Findings", data=save)
#
#
# # another table 1 version
# save<-demog %>%
# filter(enrollment_status == "Completed")
#
# label(save$Group) <- "Randomization Group"
# label(save$sex) <- "Sex"
# label(save$agegroup) <- "Age Group"
# label(save$race) <- "Race"
# label(save$vo2change) <- "VO2 max"
# label(save$bmi_change) <- "BMI "
# label(save$bodyfatchange) <- "Body Fat"
# label(save$quality_workouts_in_REDCap) <- "Workouts Completed"
# units(save$vo2change) <- "%"
# units(save$bmi_change) <- "kg/m2"
# units(save$bodyfatchange) <- "%"
# units(save$quality_workouts_in_REDCap) <- "%"
#
# save$race[save$race == "Other Asian - please specify below (Hmong, Laotian, Thai, Pakistani, Cambodian, etc)"] <- "Other"
# table1(~sex + agegroup + race + Group,
# render.continuous=my.render.cont, render.missing=NULL, caption="Table 1. Participant Demographics", data=save)
#
```
```{r dxa, echo=FALSE, include=FALSE}
#dxa <- read_xlsx("/Users/aubreykr/Desktop/dxa_feb2.xlsx")
#completed <- demog %>%
# filter(enrollment_status == "Completed") %>%
# select(record_id, Group)
# my.render.cont <- function(x) {
# with(stats.default(x),
# sprintf("%0.2f (%0.1f)", MEAN, SD))
# }
#
# label(completed$Group) <- "Randomization Group"
# label(completed$sex) <- "Sex"
# label(completed$agegroup) <- "Age Group"
# label(completed$race) <- "Race"
# label(completed$bl_vo2_max) <- "VO2 max"
# label(completed$bl_bmi) <- "BMI "
# label(completed$bl_percent_body_fat) <- "Body Fat"
#
# units(completed$bl_vo2_max) <- "mL/kg/min"
# units(completed$bl_bmi) <- "kg/m2"
# units(completed$bl_percent_body_fat) <- "%"
#
# table1(~Group + sex + agegroup + bl_vo2_max + bl_bmi + bl_percent_body_fat, data=completed, render.continuous=my.render.cont, caption="Table 1. Baseline Demographics")
#
# Convert DXA to record ids we can merge
# dxa$study_id <- str_sub(dxa$study_id, -2)
# dxa$study_id <- as.numeric(dxa$study_id)
# dxa<-dxa %>%
# rename(record_id = study_id)
#
# # merge dataframes
# dxa<-dxa %>%
# select(record_id, timepoint, contains(c("strength", "endur", "VFAT", "TRUNK", "MUSCLE")))
# dxa<-left_join(completed, dxa, by="record_id")
# # convert to kg
# dxa[, 12:26] <- dxa[, 12:26] / 1000
#
#
# # Exploratory plots
# for (col_name in colnames(dxa)[4:26]) {
# plot_data <- data.frame(value = dxa[[col_name]], timepoint = as.factor(dxa$timepoint), color=dxa$Group)
# print(ggplot(plot_data, aes(x = timepoint, y = value)) + facet_wrap(~color)+
# geom_boxplot() + geom_point() +
# stat_summary(fun = "median", geom = "text", aes(label = round(..y.., 1)), vjust = -0.5, color = "red")+
# ggtitle(col_name) + theme_bw() + theme(plot.title = element_text(hjust=0.5)))
# }
# #stat_compare_means(comparisons = list(c("1", "2")), method = "t.test",label = "p.format", paired = TRUE)+
#
# my.render.cont <- function(x) {
# with(stats.default(x),
# sprintf("%0.2f (%0.1f)", MEAN, SD))
# }
# table1(~.| Group+timepoint, overall=F, render.continuous=my.render.cont, data=dxa)
#
# colnames(demog)
#
# extra <- demog %>%
# select(record_id, sex, agegroup, bl_vo2_max, ep_vo2_max, bl_percent_body_fat, ep_percent_body_fat, bl_bmi, ep_bmi, percent_complete_of_36_wkts, total_workouts_in_REDCap)
#
# dxa2<-merge(dxa, extra, by="record_id")
#
# table1(~. | Group + timepoint, overall=F, render.continuous=my.render.cont, data=dxa2)
```
```{r vo2checking, message=FALSE, warning=FALSE, echo=FALSE, include=FALSE}
## Workout adherence and VO2 max
# #vo2<-read_xlsx("/Users/aubreykr/Desktop/VO2_prelim_analysis/Yair_condensed_VO2_1_6_24.xlsx")
#
# # remove missing rows
# #vo2<-vo2 %>%
# #filter(is.na(record_id)==FALSE)
#
# # change to baseline, endpoint labels
# vo2<-vo2 %>%
# mutate(Timepoint = case_when(Timepoint == "V1" ~ "Baseline",
# Timepoint == "V2" ~ "Endpoint"))
#
# # rearrange timepoint to front of column
# vo2<-vo2 %>%
# relocate(Timepoint, .after=record_id) %>%
# arrange(record_id, Timepoint)
#
# # Calculated variables for VO2, VT1, VT2
#
# # % change in VO2 max
# for (i in 1:nrow(vo2)) {
# if( i %% 2 == 1) { vo2$Peak_VO2_change[i] = 0 }
# if (i %% 2 == 0) { vo2$Peak_VO2_change[i] = (vo2$VO2_Peak_mLkg[i] - vo2$VO2_Peak_mLkg[i-1]) / vo2$VO2_Peak_mLkg[i-1] * 100}
# }
#
#
# # VT1
# for (i in 1:nrow(vo2)) {
# if( i %% 2 == 1) { vo2$VT1_change[i] = 0 }
# if (i %% 2 == 0) { vo2$VT1_change[i] = vo2$VT1_vo2[i] - vo2$VT1_vo2[i-1]}
# }
#
# # VT2
# for (i in 1:nrow(vo2)) {
# if( i %% 2 == 1) { vo2$VT2_change[i] = 0 }
# if (i %% 2 == 0) { vo2$VT2_change[i] = vo2$VT2_vo2[i] - vo2$VT2_vo2[i-1]}
# }
#
# # HR
# for (i in 1:nrow(vo2)) {
# if( i %% 2 == 1) { vo2$Peak_HR_change[i] = 0 }
# if (i %% 2 == 0) { vo2$Peak_HR_change[i] = vo2$Peak_HR[i] - vo2$Peak_HR[i-1]}
# }
#
# # HR at VT1
# for (i in 1:nrow(vo2)) {
# if( i %% 2 == 1) { vo2$VT1_HR_change[i] = 0 }
# if (i %% 2 == 0) { vo2$VT1_HR_change[i] = vo2$VT1_HR[i] - vo2$VT1_HR[i-1]}
# }
#
# # HR at VT2
# for (i in 1:nrow(vo2)) {
# if( i %% 2 == 1) { vo2$VT2_HR_change[i] = 0 }
# if (i %% 2 == 0) { vo2$VT2_HR_change[i] = vo2$VT2_HR[i] - vo2$VT2_HR[i-1]}
# }
#
# # plot VO2 max at BL vs. EP
# #ggplot(aes(x=Timepoint, y=VO2_Peak_mLkg, color=factor(record_id), group=record_id), data=vo2) + geom_point() +
# # geom_line(aes(group = record_id), linetype = "dashed") +
# # labs(title = "VO2 Peak: Baseline vs. Endpoint", x = "Timepoint", y = "VO2 Peak (mL/kg)") + facet_wrap(~group) + theme(plot.title=element_text(hjust=0.5))
#
# # length from first to last vo2 test
# length<-vo2[vo2$Timepoint == "Endpoint",]$date - vo2[vo2$Timepoint == "Baseline",]$date
# record_id<-unique(vo2$record_id)
# dates<-data.frame(cbind(record_id, length))
# vo2<-merge(vo2, dates)
#
# # change to length in weeks not days
# vo2$length_weeks<-vo2$length / 7
#
# # plot % change in VO2 max
# vo2 %>%
# filter(Timepoint=="Endpoint") %>%
# ggplot(aes(x=group, y=Peak_VO2_change)) + geom_boxplot() + geom_hline(yintercept=0, linetype="dotted") + geom_point() +
# stat_summary(
# fun = median,
# geom = "text",
# vjust = -0.6,
# size = 3.2,
# aes(group = group, label = sprintf("%.2f", ..y..))
# ) + ylab("Percent change in VO2 max") + xlab("Randomization Group") + ggtitle("Percent change in VO2 max after 12 Weeks") + theme(plot.title=element_text(hjust=0.5))
#
# # add adherence data and dxa data to vo2 dataset
# subset<-demog %>%
# filter(enrollment_status == "Completed") %>%
# dplyr::select(record_id, sex, agegroup, total_workouts_in_REDCap, quality_workouts_in_REDCap, percent_complete_of_36_wkts)
#
# vo2<-merge(vo2, subset, by="record_id")
#
# # plot correlation between workout adherence and change in VO2
#
# library(ggpubr)
#
# vo2 %>%
# filter(Timepoint=="Endpoint" & group!="Con" & record_id!="4") %>%
# ggplot(aes(x=quality_workouts_in_REDCap, y=Peak_VO2_change, color=group)) + geom_point() +
# geom_smooth(method = "lm", se = FALSE, size=0.5) + # Add linear regression line without confidence interval
# labs(title = "Number Successful Workouts vs. % Change in VO2 max",
# x = "Number Successful Workouts",
# y = "Percent Change in VO2") + theme(plot.title=element_text(hjust=0.5)) + geom_hline(yintercept=0, linetype="dotted", size=0.8)+
# stat_cor(method = "pearson")
#
# vo2 %>%
# filter(Timepoint=="Endpoint" & group!="Con") %>%
# ggplot(aes(x=total_workouts_in_REDCap, y=Peak_VO2_change, color=group)) + geom_point() +
# labs(title = "Number Total Workouts vs. % Change in VO2 max",
# x = "Number Total Workouts",
# y = "Percent Change in VO2") + theme(plot.title=element_text(hjust=0.5)) + geom_hline(yintercept=0, linetype="dotted", size=0.8)
#
#
# # look at intervention length
#
# vo2 %>%
# filter(Timepoint == "Endpoint" & group!="Con") %>%
# ggplot(aes(x=length_weeks, y=Peak_VO2_change, group=group, color=group)) + geom_point() + geom_smooth(method = "lm", se = FALSE, size=0.5) + labs(title = "Number weeks between VO2 max visits vs. % Change in VO2 max",
# x = "Number weeks between VO2 max visits",
# y = "Percent Change in VO2") + theme(plot.title=element_text(hjust=0.5)) + geom_hline(yintercept=0, linetype="dotted", size=0.8)+
# stat_cor(method = "pearson")
#
# vo2 %>%
# filter(Timepoint == "Endpoint" & group!="Con") %>%
# ggplot(aes(x=length_weeks, y=quality_workouts_in_REDCap, group=group, color=group)) + geom_point() + geom_smooth(method = "lm", se = FALSE, size=0.5) + labs(title = "Number weeks between VO2 max visits vs. num quality workouts",
# x = "Number weeks between VO2 max visits",
# y = "Number quality workouts in redcap") + theme(plot.title=element_text(hjust=0.5)) +
# stat_cor(method = "pearson")
#
# vo2<-vo2 %>%
# mutate(wkts_per_week = quality_workouts_in_REDCap / length_weeks)
#
# # average number of workouts per week
# vo2 %>%
# filter(Timepoint == "Endpoint" & group!="Con" & record_id!="4") %>%
# ggplot(aes(x=wkts_per_week, y=Peak_VO2_change, group=group, color=group)) + geom_point() + geom_smooth(method = "lm", se = FALSE, size=0.5) + labs(title = "Average num workouts per week vs. VO2 change",
# x = "Average num workouts per week",
# y = "Percent Change in VO2") + theme(plot.title=element_text(hjust=0.5)) +
# stat_cor(method = "pearson") + geom_hline(yintercept=0, linetype="dotted", size=0.8)
#
#
# #model<-lm(percent_change_vo2 ~ sex + agegroup + weight_kg + quality_workouts_in_REDCap + length_weeks + group, data = test)
# #summary(model)
#
#
# vo2 %>%
# filter(Timepoint == "Endpoint" & group!="Con") %>%
# ggplot(aes(x=quality_workouts_in_REDCap, y=Peak_VO2_change, color=group)) + geom_point() +
# labs(title = "Changes by Sex, Age",
# x = "Number Successful Workouts",
# y = "Percent Change in VO2") + theme(plot.title=element_text(hjust=0.5)) + geom_hline(yintercept=0, linetype="dotted", size=0.8) + facet_wrap(~sex + agegroup)
#
#
# ```
#
# ```{r vt1, message=FALSE, warning=FALSE, echo=FALSE}
#
# ggplot(aes(x=Timepoint, y=VO2_Peak_mLkg), data=vo2) + geom_boxplot() + geom_point()+
# labs(title = "VO2: Baseline vs. Endpoint", x = "Timepoint", y = "VO2 Peak (mL/kg)") + facet_wrap(~group) +
# theme(plot.title=element_text(hjust=0.5)) + stat_compare_means(
# method = "t.test", # You can also use "wilcox.test" for non-parametric test
# label = "p.format",
# paired = TRUE
# )
#
# ggplot(aes(x=Timepoint, y=VT1_vo2), data=vo2) + geom_boxplot() + geom_point()+
# labs(title = "VT1: Baseline vs. Endpoint", x = "Timepoint", y = "VO2 Peak (mL/kg)") + facet_wrap(~group) +
# theme(plot.title=element_text(hjust=0.5)) + stat_compare_means(
# method = "t.test", # You can also use "wilcox.test" for non-parametric test
# label = "p.format",
# paired = TRUE
# )
#
# ggplot(aes(x=Timepoint, y=VT2_vo2), data=vo2) + geom_boxplot() + geom_point()+
# labs(title = "VT2: Baseline vs. Endpoint", x = "Timepoint", y = "VO2 Peak (mL/kg)") + facet_wrap(~group) +
# theme(plot.title=element_text(hjust=0.5)) + stat_compare_means(
# method = "t.test", # You can also use "wilcox.test" for non-parametric test
# label = "p.format",
# paired = TRUE
# )
#
#
# ggplot(aes(x=Timepoint, y=Peak_HR), data=vo2) + geom_boxplot() + geom_point()+
# labs(title = "VO2 HR: Baseline vs. Endpoint", x = "Timepoint", y = "VO2 Peak (mL/kg)") + facet_wrap(~group) +
# theme(plot.title=element_text(hjust=0.5)) + stat_compare_means(
# method = "t.test", # You can also use "wilcox.test" for non-parametric test
# label = "p.format",
# paired = TRUE
# )
#
# ggplot(aes(x=Timepoint, y=VT1_HR), data=vo2) + geom_boxplot() + geom_point()+
# labs(title = "VT1 HR: Baseline vs. Endpoint", x = "Timepoint", y = "VO2 Peak (mL/kg)") + facet_wrap(~group) +
# theme(plot.title=element_text(hjust=0.5)) + stat_compare_means(
# method = "t.test", # You can also use "wilcox.test" for non-parametric test
# label = "p.format",
# paired = TRUE
# )
#
# ggplot(aes(x=Timepoint, y=VT2_HR), data=vo2) + geom_boxplot() + geom_point()+
# labs(title = "VT2 HR: Baseline vs. Endpoint", x = "Timepoint", y = "VO2 Peak (mL/kg)") + facet_wrap(~group) +
# theme(plot.title=element_text(hjust=0.5)) + stat_compare_means(
# method = "t.test", # You can also use "wilcox.test" for non-parametric test
# label = "p.format",
# paired = TRUE
# )
```
```{r scoringefficacy, message=FALSE, warning=FALSE, echo=FALSE, include=FALSE}
# motiv<-read.csv("/Users/aubreykr/Desktop/exselfefficacy.csv")
#
# motiv<-motiv %>%
# rename(Timepoint = redcap_event_name) %>%
# dplyr::select(-c(exeffiency_date_enrolled, exercise_selfefficacy_complete)) %>%
# mutate(Timepoint = case_when(Timepoint == "scr_bl_ep_arm_1" ~ "Baseline",
# Timepoint == "week_12_ep_surveys_arm_1" ~ "Endpoint",
# Timepoint == "month_6_arm_1" ~ "Month 6"))
#
# # self-efficacy score ranges from 9-28; sum the 9 questions.
# motiv$efficacy_score <- rowSums(motiv[, 3:11])
#
# # combine efficacy with vo2 data
# motiv<-motiv %>%
# dplyr::select(record_id, Timepoint, efficacy_score)
#
# motiv$record_id <- as.numeric(motiv$record_id)
#
# vo2<-left_join(vo2, motiv, by=c("record_id", "Timepoint"))
#
# vo2 %>%
# filter(record_id != "8" & record_id != "10" & record_id != "29") %>%
# ggplot(aes(x=Timepoint, y=efficacy_score)) + geom_boxplot() + geom_point()+
# labs(title = "Exercise Self-Efficacy: Baseline vs. Endpoint", x = "Timepoint", y = "Exercise Self-Efficacy (Score 9-36)") + facet_wrap(~group) +
# theme(plot.title=element_text(hjust=0.5)) + stat_compare_means(
# method = "t.test", # You can also use "wilcox.test" for non-parametric test
# label = "p.format",
# paired = TRUE
# )
#
# vo2 %>%
# filter(record_id != "8" & record_id != "10" & record_id != "29") %>%
# ggplot(aes(x=Timepoint, y=efficacy_score, group=group, color=factor(record_id))) + geom_point() + geom_line(aes(group = record_id), linetype = "dashed") + facet_wrap(~group)
#
# # plot VO2 max at BL vs. EP
# #ggplot(aes(x=Timepoint, y=VO2_Peak_mLkg, color=factor(record_id), group=record_id), data=vo2) + geom_point() +
# # geom_line(aes(group = record_id), linetype = "dashed") +
# # labs(title = "VO2 Peak: Baseline vs. Endpoint", x = "Timepoint", y = "VO2 Peak (mL/kg)") + facet_wrap(~group) + theme(plot.title=element_text(hjust=0.5))
#