forked from IDEMSInternational/ParentAppDataScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Metabase Analysis.R
1019 lines (855 loc) · 73.9 KB
/
Metabase Analysis.R
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
##################################
##################################
####### User Data Analysis #######
##################################
##################################
### extract data ----------------------------------------------------------------------
# to get user data
plhdata_org <- get_user_data(site = plh_con, merge_check = FALSE, UIC_Tracker = UIC.Tracker) # select 1 if you want to merge in changes (yes)
# to get notification data
nf_data <- get_nf_data()
## Data Cleaning - User Data ## --------------------------------------------------------
## Tidy up "Organisation" Variable:
# replace missing values in Organisation and rp.contact.field.organisation_code by Miss so that it is a factor level
plhdata_org$Organisation <- forcats::as_factor(tidyr::replace_na(plhdata_org$Organisation, "Miss"))
# look and Recode Factor organisation_full to just the main levels # Question: What about "null"?
plhdata_org$rp.contact.field.organisation_code <- as_factor(replace_na(plhdata_org$rp.contact.field.organisation_code, "Miss"))
# Combine Factors Organisation and rp.contact.field.organisation_code
plhdata_org$organisation_full <- interaction(x=list(plhdata_org$Organisation,
plhdata_org$rp.contact.field.organisation_code), drop=TRUE)
plhdata_org <- plhdata_org %>%
mutate(organisation_full = ifelse((rp.contact.field.organisation_code == "organisation_1") & (app_deployment_name %in% c("plh_tz", "PLH TZ")),
"ICS",
as.character(organisation_full)))
# filter out ICS users from before August
#plhdata_org <- plhdata_org %>%
# mutate(valid_ics = ifelse(organisation_full != "ICS", TRUE,
# ifelse(as.Date(createdAt) > as.Date("2022-08-01"), TRUE, FALSE))) %>%
# filter(valid_ics)
# filter out users without an intel phone?
# for now, filter out users not in the excel data
valid_ids <- UIC_Tracker_Tanzania %>% dplyr::select(YourParentAppCode)
plhdata_org_ics_fuzzy <- fuzzyjoin::stringdist_full_join(x = plhdata_org, y = valid_ids, by = c("app_user_id" = "YourParentAppCode"), max_dist = 5)
# TO CHECK:
#plhdata_org_ics_fuzzy %>% filter(!is.na(YourParentAppCode)) %>% dplyr::select(organisation_full, app_user_id, YourParentAppCode)
# Note: "2c5bfeb1c97cffdf" "oe5824bd19aa8c4" are in "Miss.Miss"
valid_app_user_id_TZ <- (plhdata_org_ics_fuzzy %>% filter(organisation_full == "ICS") %>% filter(!is.na(YourParentAppCode)))$app_user_id
plhdata_org <- plhdata_org %>%
mutate(valid_ics = ifelse(organisation_full != "ICS", TRUE,
ifelse(app_user_id %in% valid_app_user_id_TZ, TRUE, FALSE))) %>%
filter(valid_ics)
#plhdata_org1 %>% filter(organisation_full == "ICS") %>% dplyr::select(c(app_user_id, valid_ics))
plhdata_org <- plhdata_org %>%
mutate(organisation_full = ifelse(app_user_id %in% c("2c5bfeb1c97cffdf", "0e5824bd19aae8c4"),
"ICS",
as.character(organisation_full)))
plhdata_org$Org <- plyr::revalue(x=plhdata_org$organisation_full,
replace=c(`ICS` = "ICS",`Miss.Miss` = "Other", `Miss.baba` = "Other", `Miss.w` = "Other", `Miss.idems` = "Other", `Miss.hillcrest` = "Other", `Miss.aqujhk,jafvh` = "Other", `Miss.ParentApp_dev` = "Other", `Miss.CWBSA` = "Other",
`Miss.idems Margherita` = "Other", `Miss.IDEMS Ohad` = "Other", `Miss.983aba50330cf24c` ="Other", `Miss.sdfds`="Other", `Miss.friend` ="Other", `Miss.myself` ="Other", `Miss.undefined` ="Other",
`Miss.other` ="Other", `Miss.zlto` ="Other", `Miss.hpccc` ="Other", `Miss.seven_passes` ="Other", `Miss.Hillcrest facilitator` ="Other", `Miss.Hillcrest Facilitator ` ="Other", `Miss.a00af0c3b3887330` ="Other",
`Nontobeko.Miss` = "Nontobeko", `Nontobeko.Nontobeko M` = "Nontobeko", `Nontobeko.bbe9ca70c78f7384` = "Nontobeko", `Nontobeko.nontobekoM` = "Nontobeko",
`Nontobeko.NontobekoM` = "Nontobeko", `Nontobeko.null` ="Nontobeko", `Miss.NontobekoM` = "Nontobeko",
`Joy.Miss` = "Joy", `Joy.c9097349f34b364c` ="Joy", `Joy.null` ="Joy",
`Dlalanathi.Miss` = "Dlalanathi", `Dlalanathi.null` = "Dlalanathi", `Miss.dlalanathiThandeka` = "Dlalanathi", `Dlalanathi.dlanathiThandeka` ="Dlalanathi",
`Dlalanathi.dlalanathThandeka` ="Dlalanathi", `Dlalanathi.dlalanathiThandeka` ="Dlalanathi", `Dlalanathi.dlalanathi` ="Dlalanathi", `Dlalanathi.dlalanithi Thandeka` ="Dlalanathi",
`Amathuba Collective.Miss` ="Amathuba", `Miss.Amathuba Mzi` ="Amathuba", `Miss.Amathuba Mzi ` ="Amathuba", `Miss.amathuba` ="Amathuba", `Miss.dlalanathi`="Dlalanathi",
`Miss.organisation_1` = "Other", `Miss.organisation_2` = "Other",`Miss.organisation_6` = "Other"))
# so do the Miss. to Other first: [no longer commented out 14 March '22 by Margherita]
# plhdata_org <- plhdata_org %>%
# mutate(Org = ifelse(Organisation == "Miss", "Other",
# ifelse(Organisation == "Dlalanathi", "Dlalanathi",
# ifelse(rp.contact.field.organisation_code == "dlalanathiThandeka", "Dlalanathi",
# ifelse(Organisation == "Nontobeko", "Nontobeko",
# ifelse(Organisation == "Joy", "Joy",
# ifelse(Organisation == "Amathuba Collective", "Amathuba",
# ifelse(rp.contact.field.organisation_code == "Amathuba Mzi ", "Amathuba",
# ifelse(rp.contact.field.organisation_code == "Amathuba Mzi", "Amathuba",
# ifelse(rp.contact.field.organisation_code == "amathuba", "Amathuba",
# paste(Organisation, rp.contact.field.organisation_code, sep = ".")))))))))))
# Look at the organisation data
sjmisc::frq(x=plhdata_org$Org, out="txt")
#####Create a subset for cleaned organisations ####
# TODO: none are called Miss in "Org" due to how you defined it
plhdata_org_clean <- plhdata_org %>%
filter(Org != "Other")%>%
mutate(Org = factor(Org))
# Create subsets of the data based on valid app user ID's
plhdata_org_clean <- plhdata_org_clean %>%
dplyr::filter(!is.na(app_version))
# add in country variable
plhdata_org_clean <- plhdata_org_clean %>%
mutate(country = ifelse(Org %in% c("Amathuba", "Joy", "Dlalanathi", "Nontobeko"), "South Africa",
ifelse(Org %in% c("ICS"), "Tanzania",
"Other")))
# Look at the numbers per organisation from clear data
sjmisc::frq(x=plhdata_org_clean$Org, out="txt")
# Sorting Name Changes --------------------------------------------------
old_names <- c("a_1_final", "a_2_final", "a_3_final", "a_4_final", "a_5_part_1_final", "a_5_part_2_final", "a_6_final", "a_7_part_1_final")
new_names <- c("ppf", "ppp", "ps", "cme", "fs", "fi", "cmp", "cs")
df_names <- data.frame(old_names, new_names)
for (v in c("v0.16.2", "v0.16.3", "v0.16.4")){
for (i in 1:nrow(df_names)){
old_name = df_names[i,1]
new_name = df_names[i,2]
plhdata_org_clean <- plhdata_org_clean %>%
map_df(.x = v, #c("v0.16.2", "v0.16.3", "v0.16.4"),
.f = ~version_variables_rename(old_name = old_name, new_name = new_name, new_name_v = .x))
# todo: doesn't work for v?? Should explore that. But for now, in this extra loop
}
}
# todo: following not working
#plhdata_org_clean <- plhdata_org_clean %>%
# map2_df(.x = c("a_1_final", "a_2_final", "a_3_final"),
# .y = c("ppf", "ppp", "ps"),
# .f = ~version_variables_rename(old_name = .x, new_name = .y))
##plhdata_org_clean$rp.contact.field.survey_welcome_a_1_final[281:290]
##plhdata_org_clean$rp.contact.field.survey_welcome_ppf_v0.16.2[281:290]
#
#plhdata_org_clean$rp.contact.field.survey_welcome_a_2_final[281:290]
#plhdata_org_clean$rp.contact.field.survey_welcome_ppp_v0.16.2[281:290]##
#
#plhdata_org_clean$rp.contact.field.survey_welcome_a_3_final[281:290]
#plhdata_org_clean$rp.contact.field.survey_welcome_ps_v0.16.2[281:290]
# More cleaning
# TODO: Add here any to make numeric. check with Esmee about w_self_care_diff_started_completed stored
plhdata_org_clean$rp.contact.field.survey_welcome_and_setup_completion_level <- as.numeric(plhdata_org_clean$rp.contact.field.survey_welcome_and_setup_completion_level)
plhdata_org_clean$rp.contact.field.user_age <- as.numeric(plhdata_org_clean$rp.contact.field.user_age)
plhdata_org_clean$rp.contact.field.household_adults <- as.numeric(plhdata_org_clean$rp.contact.field.household_adults)
plhdata_org_clean$rp.contact.field.household_teens <- as.numeric(plhdata_org_clean$rp.contact.field.household_teens)
plhdata_org_clean$rp.contact.field.household_babies <- as.numeric(plhdata_org_clean$rp.contact.field.household_babies)
plhdata_org_clean$rp.contact.field.household_children <- as.numeric(plhdata_org_clean$rp.contact.field.household_children)
plhdata_org_clean$rp.contact.field.w_1on1_diff_started_completed <- as.numeric(plhdata_org_clean$rp.contact.field.w_1on1_diff_started_completed)
plhdata_org_clean$rp.contact.field.parent_point_count_relax_w_self_care <- as.numeric(plhdata_org_clean$rp.contact.field.parent_point_count_relax_w_self_care)
plhdata_org_clean$rp.contact.field.w_self_care_diff_started_completed <- as.numeric(plhdata_org_clean$rp.contact.field.w_self_care_diff_started_completed)
plhdata_org_clean <- plhdata_org_clean %>%
mutate(across(ends_with("_completion_level"), ~as.numeric(.)))
plhdata_org_clean <- plhdata_org_clean %>%
mutate(across(starts_with("rp.contact.field.parent_point"), ~as.numeric(.)))
plhdata_org_clean$rp.contact.field.app_launch_count <- as.numeric(plhdata_org_clean$rp.contact.field.app_launch_count)
plhdata_org_clean$rp.contact.field.w_self_care_diff_started_completed <- as.numeric(plhdata_org_clean$rp.contact.field.w_self_care_diff_started_completed)
plhdata_org_clean$rp.contact.field.first_app_open <- as.Date(plhdata_org_clean$rp.contact.field.first_app_open)
plhdata_org_clean <- plhdata_org_clean %>%
mutate(across(starts_with("rp.contact.field.app_launch_count"), ~as.numeric(.)))
# Write clean data back -------------------------------------------------------
# Analysis - tables - separate for different groups.
# summary_table(columns_to_summarise = app_version, display_table = FALSE)
## Data Analysis ## --------------------------------------------------------
# Summary tables of started/completed things
# Show the summary of Self care workshop started(1st Workshop)
# summary_table(columns_to_summarise = rp.contact.field.w_self_care_started)
#plhdata_org_clean%>%dplyr::filter(Nontobeko,Joy,Amathuba,Dlalanathi)%>%summary_table(columns_to_summarise = rp.contact.field.w_self_care_started)
# Show the summary of Self care workshop completion(1st Workshop)
#summary_table(columns_to_summarise = rp.contact.field.w_self_care_completed)
# Show the summary of One-on-One Time started(2nd Workshop)
#summary_table(columns_to_summarise = rp.contact.field.w_1on1_started)
# Show the summary of One-on-One Time completion(2nd Workshop)
#summary_table(columns_to_summarise = rp.contact.field.w_1on1_completed)
# Show the summary of Praise started(3rd workshop)
#summary_table(columns_to_summarise = rp.contact.field.w_praise_started)
# Show the summary of Praise(3rd Workshop)
#summary_table(columns_to_summarise = rp.contact.field.w_praise_completed)
## Show the summary of Positive Instructions(4th workshop)
#summary_table(columns_to_summarise = rp.contact.field.w_instruct_started)
# Show the summary of Positive Instructions(4th workshop)
#summary_table(columns_to_summarise = rp.contact.field.w_instruct_completed)
# Show the summary of Managing Stress(5th workshop)
#summary_table(columns_to_summarise = rp.contact.field.w_stress_started)
# Show the summary of Managing Stress(5th workshop)
#summary_table(columns_to_summarise = rp.contact.field.w_stress_completed)
# Show the summary of Family Budgets(6th workshop)
#summary_table(columns_to_summarise = rp.contact.field.w_money_started)
# Show the summary of Family Budgets(6th workshop)
#summary_table(columns_to_summarise = rp.contact.field.w_money_completed)
#survey ------------------------------------------------------------------------------------
# workshop_together variable
#plhdata_org_clean <- plhdata_org_clean %>%
# mutate(rp.contact.field.workshop_path = ifelse(is.na(rp.contact.field.workshop_path),
# rp.contact.field.do_workshops_together,
# rp.contact.field.workshop_path))
# workshop_path edits ----------
plhdata_org_clean <- plhdata_org_clean %>%
mutate(rp.contact.field.workshop_path = ifelse(is.na(rp.contact.field.workshop_path_user_choice),
rp.contact.field.workshop_path,
ifelse(rp.contact.field.workshop_path_user_choice == "false",
"default",
rp.contact.field.workshop_path)))
# checks
#plhdata_org_clean %>%
# dplyr::select(c(rp.contact.field.workshop_path, rp.contact.field.do_workshops_together, rp.contact.field.workshop_path_user_choice, rp.contact.field.workshop_path1)) %>%
# View()
#plhdata_org_clean %>% group_by(rp.contact.field.workshop_path, rp.contact.field.do_workshops_together) %>% summarise(n()) %>% View()
data_baseline_survey <- c("rp.contact.field.survey_welcome_completed", "rp.contact.field.user_gender",
"rp.contact.field.user_age", "rp.contact.field.household_adults",
"rp.contact.field.household_teens", "rp.contact.field.household_babies",
"rp.contact.field.household_children", "rp.contact.field._app_language", "app_version", "rp.contact.field.workshop_path")
summary_table_baseline <- multiple_table_output(columns_to_summarise = data_baseline_survey, replace = "rp.contact.field.")
summary_table_baseline$`Household babies`
# summary_table_baseline$` app language`
# summary_table_baseline$`App version`
# summary_table_baseline$`Do workshops together`
# summary_table_baseline$`Household adults`
#summary_table_baseline$`User gender` %>% filter(Org %in% c(("Dlalanathi"))) %>%
# pivot_wider(names_from = `User gender`, values_from = N)
summary_plot_baseline <- multiple_plot_output(columns_to_summarise = data_baseline_survey, replace = "rp.contact.field.")
# summary_plot_baseline$`Survey welcome completed`
###Completion status of baseline survey
# Show the summary of baseline survey completion(Organisaton-wise)
# summary_table(plhdata_org_clean %>% filter(Org == "Nontobeko"),
# factor = NULL,
# columns_to_summarise = rp.contact.field.survey_welcome_completed)
# Show the summary of user ids on baseline survey completion (Organisaton-wise)
# user_id_print("rp.contact.field.survey_welcome_completed")
#Time spent on the workshops -----------------------------------------------------------------------
# TODO: sort NAs in these:
#Self care workshop
# summary_table(columns_to_summarise = rp.contact.field.w_self_care_diff_started_completed)
#One on one time workshop
# summary_table(columns_to_summarise = rp.contact.field.w_1on1_diff_started_completed)
# app language --------------------------------------------------
# summary_table(columns_to_summarise = rp.contact.field._app_language, replace = "rp.contact.field.")
# user_id_print("rp.contact.field._app_language")
# TODO: factor levels? that should be done in cleaning step.
#Define workshop week order
week_order <- c("Self care", "1on1", "Praise", "Instruct", "Stress", "Money", "Rules", "Consequence", "Solve", "Safe",
"Crisis", "Celebrate" )
#Each habit across workshop weeks
#relax points in each week
relax_workshop_vars <- c( "rp.contact.field.parent_point_count_relax_w_self_care", "rp.contact.field.parent_point_count_relax_w_1on1",
"rp.contact.field.parent_point_count_relax_w_praise", "rp.contact.field.parent_point_count_relax_w_instruct",
"rp.contact.field.parent_point_count_relax_w_stress", "rp.contact.field.parent_point_count_relax_w_money",
"rp.contact.field.parent_point_count_relax_w_rules", "rp.contact.field.parent_point_count_relax_w_consequence",
"rp.contact.field.parent_point_count_relax_w_solve", "rp.contact.field.parent_point_count_relax_w_safe",
"rp.contact.field.parent_point_count_relax_w_crisis","rp.contact.field.parent_point_count_relax_w_celebrate")
# treat_yourself points in each week
treat_yourself_workshop_vars <- c( "rp.contact.field.parent_point_count_treat_yourself_w_self_care", "rp.contact.field.parent_point_count_treat_yourself_w_1on1",
"rp.contact.field.parent_point_count_treat_yourself_w_praise", "rp.contact.field.parent_point_count_treat_yourself_w_instruct",
"rp.contact.field.parent_point_count_treat_yourself_w_stress", "rp.contact.field.parent_point_count_treat_yourself_w_money",
"rp.contact.field.parent_point_count_treat_yourself_w_rules", "rp.contact.field.parent_point_count_treat_yourself_w_consequence",
"rp.contact.field.parent_point_count_treat_yourself_w_solve", "rp.contact.field.parent_point_count_treat_yourself_w_safe",
"rp.contact.field.parent_point_count_treat_yourself_w_crisis","rp.contact.field.parent_point_count_treat_yourself_w_celebrate")
# praise_yourself points in each week
praise_yourself_workshop_vars <- c( "rp.contact.field.parent_point_count_praise_yourself_w_self_care", "rp.contact.field.parent_point_count_praise_yourself_w_1on1",
"rp.contact.field.parent_point_count_praise_yourself_w_praise", "rp.contact.field.parent_point_count_praise_yourself_w_instruct",
"rp.contact.field.parent_point_count_praise_yourself_w_stress", "rp.contact.field.parent_point_count_praise_yourself_w_money",
"rp.contact.field.parent_point_count_praise_yourself_w_rules", "rp.contact.field.parent_point_count_praise_yourself_w_consequence",
"rp.contact.field.parent_point_count_praise_yourself_w_solve", "rp.contact.field.parent_point_count_praise_yourself_w_safe",
"rp.contact.field.parent_point_count_praise_yourself_w_crisis","rp.contact.field.parent_point_count_praise_yourself_w_celebrate")
# spend_time points in each week
spend_time_workshop_vars <- c( "rp.contact.field.parent_point_count_spend_time_w_self_care", "rp.contact.field.parent_point_count_spend_time_w_1on1",
"rp.contact.field.parent_point_count_spend_time_w_praise", "rp.contact.field.parent_point_count_spend_time_w_instruct",
"rp.contact.field.parent_point_count_spend_time_w_stress", "rp.contact.field.parent_point_count_spend_time_w_money",
"rp.contact.field.parent_point_count_spend_time_w_rules", "rp.contact.field.parent_point_count_spend_time_w_consequence",
"rp.contact.field.parent_point_count_spend_time_w_solve", "rp.contact.field.parent_point_count_spend_time_w_safe",
"rp.contact.field.parent_point_count_spend_time_w_crisis","rp.contact.field.parent_point_count_spend_time_w_celebrate")
# praise_teen in each week
praise_teen_workshop_vars <- c( "rp.contact.field.parent_point_count_praise_teen_w_self_care", "rp.contact.field.parent_point_count_praise_teen_w_1on1",
"rp.contact.field.parent_point_count_praise_teen_w_praise", "rp.contact.field.parent_point_count_praise_teen_w_instruct",
"rp.contact.field.parent_point_count_praise_teen_w_stress", "rp.contact.field.parent_point_count_praise_teen_w_money",
"rp.contact.field.parent_point_count_praise_teen_w_rules", "rp.contact.field.parent_point_count_praise_teen_w_consequence",
"rp.contact.field.parent_point_count_praise_teen_w_solve", "rp.contact.field.parent_point_count_praise_teen_w_safe",
"rp.contact.field.parent_point_count_praise_teen_w_crisis","rp.contact.field.parent_point_count_praise_teen_w_celebrate")
# instruct_positively points in each week
instruct_positively_workshop_vars <- c( "rp.contact.field.parent_point_count_instruct_positively_w_self_care", "rp.contact.field.parent_point_count_instruct_positively_w_1on1",
"rp.contact.field.parent_point_count_instruct_positively_w_praise", "rp.contact.field.parent_point_count_instruct_positively_w_instruct",
"rp.contact.field.parent_point_count_instruct_positively_w_stress", "rp.contact.field.parent_point_count_instruct_positively_w_money",
"rp.contact.field.parent_point_count_instruct_positively_w_rules", "rp.contact.field.parent_point_count_instruct_positively_w_consequence",
"rp.contact.field.parent_point_count_instruct_positively_w_solve", "rp.contact.field.parent_point_count_instruct_positively_w_safe",
"rp.contact.field.parent_point_count_instruct_positively_w_crisis","rp.contact.field.parent_point_count_instruct_positively_w_celebrate")
# breathe points in each week
breathe_workshop_vars <- c( "rp.contact.field.parent_point_count_breathe_w_self_care", "rp.contact.field.parent_point_count_breathe_w_1on1",
"rp.contact.field.parent_point_count_breathe_w_praise", "rp.contact.field.parent_point_count_breathe_w_instruct",
"rp.contact.field.parent_point_count_breathe_w_stress", "rp.contact.field.parent_point_count_breathe_w_money",
"rp.contact.field.parent_point_count_breathe_w_rules", "rp.contact.field.parent_point_count_breathe_w_consequence",
"rp.contact.field.parent_point_count_breathe_w_solve", "rp.contact.field.parent_point_count_breathe_w_safe",
"rp.contact.field.parent_point_count_breathe_w_crisis","rp.contact.field.parent_point_count_breathe_w_celebrate")
# money points in each week
money_workshop_vars <- c( "rp.contact.field.parent_point_count_money_w_self_care", "rp.contact.field.parent_point_count_money_w_1on1",
"rp.contact.field.parent_point_count_money_w_praise", "rp.contact.field.parent_point_count_money_w_instruct",
"rp.contact.field.parent_point_count_money_w_stress", "rp.contact.field.parent_point_count_money_w_money",
"rp.contact.field.parent_point_count_money_w_rules", #"rp.contact.field.parent_point_count_money_w_consequence",
"rp.contact.field.parent_point_count_money_w_solve", "rp.contact.field.parent_point_count_money_w_safe",
#"rp.contact.field.parent_point_count_money_w_crisis",
"rp.contact.field.parent_point_count_money_w_celebrate")
# consequence points in each week
consequence_workshop_vars <- c( "rp.contact.field.parent_point_count_consequence_w_self_care", "rp.contact.field.parent_point_count_consequence_w_1on1",
"rp.contact.field.parent_point_count_consequence_w_praise", "rp.contact.field.parent_point_count_consequence_w_instruct",
"rp.contact.field.parent_point_count_consequence_w_stress", "rp.contact.field.parent_point_count_consequence_w_money",
#"rp.contact.field.parent_point_count_consequence_w_rules", "rp.contact.field.parent_point_count_consequence_w_crisis",
"rp.contact.field.parent_point_count_consequence_w_consequence",
"rp.contact.field.parent_point_count_consequence_w_solve", "rp.contact.field.parent_point_count_consequence_w_safe",
"rp.contact.field.parent_point_count_consequence_w_celebrate")
# safe points in each week
safe_workshop_vars <- c( "rp.contact.field.parent_point_count_safe_w_self_care", "rp.contact.field.parent_point_count_safe_w_1on1",
"rp.contact.field.parent_point_count_safe_w_praise", "rp.contact.field.parent_point_count_safe_w_instruct",
"rp.contact.field.parent_point_count_safe_w_stress", "rp.contact.field.parent_point_count_safe_w_money",
"rp.contact.field.parent_point_count_safe_w_rules", "rp.contact.field.parent_point_count_safe_w_consequence",
"rp.contact.field.parent_point_count_safe_w_solve", "rp.contact.field.parent_point_count_safe_w_safe",
"rp.contact.field.parent_point_count_safe_w_crisis","rp.contact.field.parent_point_count_safe_w_celebrate")
data_all_weeks_pp_relax_neat <- naming_conventions(relax_workshop_vars, replace = "rp.contact.field.parent_point_count_relax_w_")
data_all_weeks_pp_treat_yourself_neat <- naming_conventions(treat_yourself_workshop_vars, replace = "rp.contact.field.parent_point_count_treat_yourself_w_")
data_all_weeks_pp_praise_yourself_neat <- naming_conventions(praise_yourself_workshop_vars, replace = "rp.contact.field.parent_point_count_praise_yourself_w_")
data_all_weeks_pp_spend_time_neat <- naming_conventions(spend_time_workshop_vars, replace = "rp.contact.field.parent_point_count_spend_time_w_")
data_all_weeks_pp_praise_teen_neat <- naming_conventions(praise_teen_workshop_vars, replace = "rp.contact.field.parent_point_count_praise_teen_w_")
data_all_weeks_pp_instruct_positively_neat <- naming_conventions(instruct_positively_workshop_vars, replace = "rp.contact.field.parent_point_count_instruct_positively_w_")
data_all_weeks_pp_breathe_neat <- naming_conventions(breathe_workshop_vars, replace = "rp.contact.field.parent_point_count_breathe_w_")
data_all_weeks_pp_money_neat <- naming_conventions(money_workshop_vars, replace = "rp.contact.field.parent_point_count_money_w_")
data_all_weeks_pp_consequence_neat <- naming_conventions(consequence_workshop_vars, replace = "rp.contact.field.parent_point_count_consequence_w_")
data_all_weeks_pp_safe_neat <- naming_conventions(safe_workshop_vars, replace = "rp.contact.field.parent_point_count_safe_w_")
#parent points in each week sorted by parent point (not necessary to code as we already have the number of PPs in each ws week below)
#Average relax parent points pp1
#summary_relax_workshop <- multiple_table_output(columns_to_summarise = relax_workshop_vars, replace = "rp.contact.field.parent_point_count_relax_w_")
summary_relax_workshop <- plhdata_org_clean %>%
group_by(Org) %>%
summarise(across(relax_workshop_vars, mean, na.rm = TRUE))
colnames(summary_relax_workshop) <- naming_conventions(colnames(summary_relax_workshop), "rp.contact.field.parent_point_count_relax_w_")
# summary_relax_workshop
# Make the table longer so that it is in a format for use in ggplot
summary_relax_workshop_long <- summary_relax_workshop %>%
pivot_longer(cols = !Org) %>%
mutate(name = fct_relevel(name, week_order)) # set the order of variables
# summary_relax_workshop_long
# Run the plot (#Code moved to RSHiny file in order to be able to filter by Org)
# ggplot(summary_relax_workshop_long, aes(x = name, y = value, colour = Org, shape = Org, group = Org)) +
# geom_point() + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
# geom_line() + labs(x = "Workshop week", y = "Number of points")
#Average treat_yourself parent points pp2
summary_treat_yourself_workshop <- plhdata_org_clean %>%
group_by(Org) %>%
summarise(across(treat_yourself_workshop_vars, mean, na.rm = TRUE))
colnames(summary_treat_yourself_workshop) <- naming_conventions(colnames(summary_treat_yourself_workshop), "rp.contact.field.parent_point_count_treat_yourself_w_")
# summary_treat_yourself_workshop
# Make the table longer so that it is in a format for use in ggplot
summary_treat_yourself_workshop_long <- summary_treat_yourself_workshop %>%
pivot_longer(cols = !Org) %>%
mutate(name = fct_relevel(name, week_order)) # set the order of variables
# summary_treat_yourself_workshop_long
# Run the plot (#Code moved to RSHiny file in order to be able to filter by Org)
# ggplot(summary_treat_yourself_workshop_long, aes(x = name, y = value, colour = Org, shape = Org, group = Org)) +
# geom_point() + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
# geom_line() + labs(x = "Workshop week", y = "Number of points")
#Average praise_yourself parent points pp3
summary_praise_yourself_workshop <- plhdata_org_clean %>%
group_by(Org) %>%
summarise(across(praise_yourself_workshop_vars, mean, na.rm = TRUE))
colnames(summary_praise_yourself_workshop) <- naming_conventions(colnames(summary_praise_yourself_workshop), "rp.contact.field.parent_point_count_praise_yourself_w_")
# summary_praise_yourself_workshop
# Make the table longer so that it is in a format for use in ggplot
summary_praise_yourself_workshop_long <- summary_praise_yourself_workshop %>%
pivot_longer(cols = !Org) %>%
mutate(name = fct_relevel(name, week_order)) # set the order of variables
# summary_praise_yourself_workshop_long
#Average spend_time parent points pp4
summary_spend_time_workshop <- plhdata_org_clean %>%
group_by(Org) %>%
summarise(across(spend_time_workshop_vars, mean, na.rm = TRUE))
colnames(summary_spend_time_workshop) <- naming_conventions(colnames(summary_spend_time_workshop), "rp.contact.field.parent_point_count_spend_time_w_")
# summary_spend_time_workshop
# Make the table longer so that it is in a format for use in ggplot
summary_spend_time_workshop_long <- summary_spend_time_workshop %>%
pivot_longer(cols = !Org) %>%
mutate(name = fct_relevel(name, week_order)) # set the order of variables
# summary_spend_time_workshop_long
#Average praise_teen parent points pp5
summary_praise_teen_workshop <- plhdata_org_clean %>%
group_by(Org) %>%
summarise(across(praise_teen_workshop_vars, mean, na.rm = TRUE))
colnames(summary_praise_teen_workshop) <- naming_conventions(colnames(summary_praise_teen_workshop), "rp.contact.field.parent_point_count_praise_teen_w_")
# summary_praise_teen_workshop
# Make the table longer so that it is in a format for use in ggplot
summary_praise_teen_workshop_long <- summary_praise_teen_workshop %>%
pivot_longer(cols = !Org) %>%
mutate(name = fct_relevel(name, week_order)) # set the order of variables
# summary_praise_teen_workshop_long
#Average instruct_positively parent points pp6
summary_instruct_positively_workshop <- plhdata_org_clean %>%
group_by(Org) %>%
summarise(across(instruct_positively_workshop_vars, mean, na.rm = TRUE))
colnames(summary_instruct_positively_workshop) <- naming_conventions(colnames(summary_instruct_positively_workshop), "rp.contact.field.parent_point_count_instruct_positively_w_")
# summary_instruct_positively_workshop
# Make the table longer so that it is in a format for use in ggplot
summary_instruct_positively_workshop_long <- summary_instruct_positively_workshop %>%
pivot_longer(cols = !Org) %>%
mutate(name = fct_relevel(name, week_order)) # set the order of variables
# summary_instruct_positively_workshop_long
#Average breathe parent points pp7
summary_breathe_workshop <- plhdata_org_clean %>%
group_by(Org) %>%
summarise(across(breathe_workshop_vars, mean, na.rm = TRUE))
colnames(summary_breathe_workshop) <- naming_conventions(colnames(summary_breathe_workshop), "rp.contact.field.parent_point_count_breathe_w_")
# summary_breathe_workshop
# Make the table longer so that it is in a format for use in ggplot
summary_breathe_workshop_long <- summary_breathe_workshop %>%
pivot_longer(cols = !Org) %>%
mutate(name = fct_relevel(name, week_order)) # set the order of variables
# summary_breathe_workshop_long
#Average spend_time parent points pp8
summary_money_workshop <- plhdata_org_clean %>%
group_by(Org) %>%
summarise(across(money_workshop_vars, mean, na.rm = TRUE))
colnames(summary_money_workshop) <- naming_conventions(colnames(summary_money_workshop), "rp.contact.field.parent_point_count_money_w_")
# summary_money_workshop
# Make the table longer so that it is in a format for use in ggplot
summary_money_workshop_long <- summary_money_workshop %>%
pivot_longer(cols = !Org) %>%
mutate(name = fct_relevel(name, week_order)) # set the order of variables
# summary_money_workshop_long
#Average consequence parent points pp9
summary_consequence_workshop <- plhdata_org_clean %>%
group_by(Org) %>%
summarise(across(consequence_workshop_vars, mean, na.rm = TRUE))
colnames(summary_consequence_workshop) <- naming_conventions(colnames(summary_consequence_workshop), "rp.contact.field.parent_point_count_consequence_w_")
# summary_consequence_workshop
# Make the table longer so that it is in a format for use in ggplot
summary_consequence_workshop_long <- summary_consequence_workshop %>%
pivot_longer(cols = !Org) %>%
mutate(name = fct_relevel(name, week_order)) # set the order of variables
# summary_consequence_workshop_long
#Average safe parent points pp10
summary_safe_workshop <- plhdata_org_clean %>%
group_by(Org) %>%
summarise(across(safe_workshop_vars, mean, na.rm = TRUE))
colnames(summary_safe_workshop) <- naming_conventions(colnames(summary_safe_workshop), "rp.contact.field.parent_point_count_safe_w_")
# summary_safe_workshop
# Make the table longer so that it is in a format for use in ggplot
summary_safe_workshop_long <- summary_safe_workshop %>%
pivot_longer(cols = !Org) %>%
mutate(name = fct_relevel(name, week_order)) # set the order of variables
# summary_safe_workshop_long
# HABITS by workshop week ------------------------------------------------------------------------------------
data_habit_parent_points_all <- c("rp.contact.field.parent_point_count_relax", "rp.contact.field.parent_point_count_treat_yourself",
"rp.contact.field.parent_point_count_praise_yourself", "rp.contact.field.parent_point_count_spend_time",
"rp.contact.field.parent_point_count_praise_teen", "rp.contact.field.parent_point_count_instruct_positively", "rp.contact.field.parent_point_count_breathe",
"rp.contact.field.parent_point_count_money", "rp.contact.field.parent_point_count_consequence", "rp.contact.field.parent_point_count_safe")
data_habit_parent_points_w_self_care <- c("rp.contact.field.parent_point_count_relax_w_self_care", "rp.contact.field.parent_point_count_treat_yourself_w_self_care", "rp.contact.field.parent_point_count_praise_yourself_w_self_care",
"rp.contact.field.parent_point_count_spend_time_w_self_care", "rp.contact.field.parent_point_count_praise_teen_w_self_care",
"rp.contact.field.parent_point_count_breathe_w_self_care", "rp.contact.field.parent_point_count_money_w_self_care",
"rp.contact.field.parent_point_count_consequence_w_self_care", "rp.contact.field.parent_point_count_safe_w_self_care", "rp.contact.field.parent_point_count_instruct_positively_w_self_care")
data_habit_parent_points_w_1on1 <- c("rp.contact.field.parent_point_count_relax_w_1on1", "rp.contact.field.parent_point_count_treat_yourself_w_1on1",
"rp.contact.field.parent_point_count_praise_yourself_w_1on1", "rp.contact.field.parent_point_count_spend_time_w_1on1",
"rp.contact.field.parent_point_count_praise_teen_w_1on1", "rp.contact.field.parent_point_count_breathe_w_1on1",
"rp.contact.field.parent_point_count_money_w_1on1", "rp.contact.field.parent_point_count_consequence_w_1on1",
"rp.contact.field.parent_point_count_safe_w_1on1", "rp.contact.field.parent_point_count_instruct_positively_w_1on1")
data_habit_parent_points_w_praise <- c("rp.contact.field.parent_point_count_relax_w_praise", "rp.contact.field.parent_point_count_treat_yourself_w_praise",
"rp.contact.field.parent_point_count_praise_yourself_w_praise", "rp.contact.field.parent_point_count_spend_time_w_praise",
"rp.contact.field.parent_point_count_praise_teen_w_praise", "rp.contact.field.parent_point_count_breathe_w_praise",
"rp.contact.field.parent_point_count_money_w_praise", "rp.contact.field.parent_point_count_consequence_w_praise",
"rp.contact.field.parent_point_count_safe_w_praise", "rp.contact.field.parent_point_count_instruct_positively_w_praise")
data_habit_parent_points_w_instruct <- c("rp.contact.field.parent_point_count_relax_w_instruct", "rp.contact.field.parent_point_count_treat_yourself_w_instruct",
"rp.contact.field.parent_point_count_praise_yourself_w_instruct", "rp.contact.field.parent_point_count_spend_time_w_instruct",
"rp.contact.field.parent_point_count_praise_teen_w_instruct", "rp.contact.field.parent_point_count_breathe_w_instruct",
"rp.contact.field.parent_point_count_money_w_instruct", "rp.contact.field.parent_point_count_consequence_w_instruct",
"rp.contact.field.parent_point_count_safe_w_instruct", "rp.contact.field.parent_point_count_instruct_positively_w_instruct")
data_habit_parent_points_w_stress <- c("rp.contact.field.parent_point_count_relax_w_stress", "rp.contact.field.parent_point_count_treat_yourself_w_stress",
"rp.contact.field.parent_point_count_praise_yourself_w_stress", "rp.contact.field.parent_point_count_spend_time_w_stress",
"rp.contact.field.parent_point_count_praise_teen_w_stress", "rp.contact.field.parent_point_count_breathe_w_stress",
"rp.contact.field.parent_point_count_money_w_stress", "rp.contact.field.parent_point_count_consequence_w_stress",
"rp.contact.field.parent_point_count_safe_w_stress", "rp.contact.field.parent_point_count_instruct_positively_w_stress")
data_habit_parent_points_w_money <- c("rp.contact.field.parent_point_count_relax_w_money", "rp.contact.field.parent_point_count_treat_yourself_w_money",
"rp.contact.field.parent_point_count_praise_yourself_w_money", "rp.contact.field.parent_point_count_spend_time_w_money",
"rp.contact.field.parent_point_count_praise_teen_w_money", "rp.contact.field.parent_point_count_breathe_w_money",
"rp.contact.field.parent_point_count_money_w_money", "rp.contact.field.parent_point_count_consequence_w_money",
"rp.contact.field.parent_point_count_safe_w_money", "rp.contact.field.parent_point_count_instruct_positively_w_stress")
data_habit_parent_points_w_rules <- c("rp.contact.field.parent_point_count_relax_w_rules", "rp.contact.field.parent_point_count_treat_yourself_w_rules",
"rp.contact.field.parent_point_count_praise_yourself_w_rules", "rp.contact.field.parent_point_count_spend_time_w_rules",
"rp.contact.field.parent_point_count_praise_teen_w_rules", "rp.contact.field.parent_point_count_breathe_w_rules",
"rp.contact.field.parent_point_count_money_w_rules", #"rp.contact.field.parent_point_count_consequence_w_rules",
"rp.contact.field.parent_point_count_safe_w_rules", "rp.contact.field.parent_point_count_instruct_positively_w_rules")
data_habit_parent_points_w_consequence <- c("rp.contact.field.parent_point_count_relax_w_consequence", "rp.contact.field.parent_point_count_treat_yourself_w_consequence",
"rp.contact.field.parent_point_count_praise_yourself_w_consequence", "rp.contact.field.parent_point_count_spend_time_w_consequence",
"rp.contact.field.parent_point_count_praise_teen_w_consequence", "rp.contact.field.parent_point_count_breathe_w_consequence",
#"rp.contact.field.parent_point_count_money_w_consequence",
"rp.contact.field.parent_point_count_consequence_w_consequence",
"rp.contact.field.parent_point_count_safe_w_consequence", "rp.contact.field.parent_point_count_instruct_positively_w_consequence")
data_habit_parent_points_w_solve <- c("rp.contact.field.parent_point_count_relax_w_solve", "rp.contact.field.parent_point_count_treat_yourself_w_solve",
"rp.contact.field.parent_point_count_praise_yourself_w_solve", "rp.contact.field.parent_point_count_spend_time_w_solve",
"rp.contact.field.parent_point_count_praise_teen_w_solve", "rp.contact.field.parent_point_count_breathe_w_solve",
"rp.contact.field.parent_point_count_money_w_solve", "rp.contact.field.parent_point_count_consequence_w_solve",
"rp.contact.field.parent_point_count_safe_w_solve", "rp.contact.field.parent_point_count_instruct_positively_w_solve")
data_habit_parent_points_w_safe <- c("rp.contact.field.parent_point_count_relax_w_safe", "rp.contact.field.parent_point_count_treat_yourself_w_safe",
"rp.contact.field.parent_point_count_praise_yourself_w_safe", "rp.contact.field.parent_point_count_spend_time_w_safe",
"rp.contact.field.parent_point_count_praise_teen_w_safe", "rp.contact.field.parent_point_count_breathe_w_safe",
"rp.contact.field.parent_point_count_money_w_safe", "rp.contact.field.parent_point_count_consequence_w_safe",
"rp.contact.field.parent_point_count_safe_w_safe", "rp.contact.field.parent_point_count_instruct_positively_w_safe")
data_habit_parent_points_w_crisis <- c("rp.contact.field.parent_point_count_relax_w_crisis", "rp.contact.field.parent_point_count_treat_yourself_w_crisis",
"rp.contact.field.parent_point_count_praise_yourself_w_crisis", "rp.contact.field.parent_point_count_spend_time_w_crisis",
"rp.contact.field.parent_point_count_praise_teen_w_crisis", "rp.contact.field.parent_point_count_breathe_w_crisis",
#"rp.contact.field.parent_point_count_money_w_crisis", "rp.contact.field.parent_point_count_consequence_w_crisis",
"rp.contact.field.parent_point_count_safe_w_crisis", "rp.contact.field.parent_point_count_instruct_positively_w_crisis")
data_habit_parent_points_w_celebrate <- c("rp.contact.field.parent_point_count_relax_w_celebrate", "rp.contact.field.parent_point_count_treat_yourself_w_celebrate",
"rp.contact.field.parent_point_count_praise_yourself_w_celebrate", "rp.contact.field.parent_point_count_spend_time_w_celebrate",
"rp.contact.field.parent_point_count_praise_teen_w_celebrate", "rp.contact.field.parent_point_count_breathe_w_celebrate",
"rp.contact.field.parent_point_count_money_w_celebrate", "rp.contact.field.parent_point_count_consequence_w_celebrate",
"rp.contact.field.parent_point_count_safe_w_celebrate", "rp.contact.field.parent_point_count_instruct_positively_w_celebrate")
summary_table_habits_all <- multiple_table_output(columns_to_summarise = data_habit_parent_points_all, replace = "rp.contact.field.parent_point_count_")
# summary_table_habits_all$`Relax`
# summary_table_habits_all$`Treat yourself`
# summary_table_habits_all$`Praise yourself`
# summary_table_habits_all$`Spend time`
# summary_table_habits_all$`Praise teen`
# summary_table_habits_all$`Instruct positively`
# summary_table_habits_all$`Breathe`
# summary_table_habits_all$`Money`
# summary_table_habits_all$`Consequence`
# summary_table_habits_all$`Safe`
summary_plot_habits_all <- multiple_plot_output(columns_to_summarise = data_habit_parent_points_all, replace = "rp.contact.field.parent_point_count_", plot_type = "boxplot")
#summary_plot_habits_all$Relax
summary_table_habits_self_care <- multiple_table_output(columns_to_summarise = data_habit_parent_points_w_self_care, replace = "rp.contact.field.parent_point_count_", replace_after = "_w_self_care")
summary_table_habits_self_care$`Relax`
summary_plot_habits_self_care <- multiple_plot_output(columns_to_summarise = data_habit_parent_points_all, replace = "rp.contact.field.parent_point_count_", plot_type = "boxplot")
summary_table_habits_1on1 <- multiple_table_output(columns_to_summarise = data_habit_parent_points_w_1on1, replace = "rp.contact.field.parent_point_count_", replace_after = "w_1on1")
summary_plot_habits_1on1 <- multiple_plot_output(columns_to_summarise = data_habit_parent_points_w_1on1, replace = "rp.contact.field.parent_point_count_", replace_after = "w_1on1", plot_type = "boxplot")
summary_table_habits_praise <- multiple_table_output(columns_to_summarise = data_habit_parent_points_w_praise,
replace = "rp.contact.field.parent_point_count_", replace_after = "w_praise")
summary_table_habits_instruct <- multiple_table_output(columns_to_summarise = data_habit_parent_points_w_instruct,
replace = "rp.contact.field.parent_point_count_", replace_after = "w_instruct")
summary_table_habits_stress <- multiple_table_output(columns_to_summarise = data_habit_parent_points_w_stress,
replace = "rp.contact.field.parent_point_count_", replace_after = "w_stress")
summary_table_habits_money <- multiple_table_output(columns_to_summarise = data_habit_parent_points_w_money,
replace = "rp.contact.field.parent_point_count_", replace_after = "w_money")
summary_table_habits_rules <- multiple_table_output(columns_to_summarise = data_habit_parent_points_w_rules,
replace = "rp.contact.field.parent_point_count_", replace_after = "w_rules")
summary_table_habits_consequence <- multiple_table_output(columns_to_summarise = data_habit_parent_points_w_consequence,
replace = "rp.contact.field.parent_point_count_", replace_after = "w_consequence")
summary_table_habits_solve <- multiple_table_output(columns_to_summarise = data_habit_parent_points_w_solve,
replace = "rp.contact.field.parent_point_count_", replace_after = "w_solve")
summary_table_habits_safe <- multiple_table_output(columns_to_summarise = data_habit_parent_points_w_safe,
replace = "rp.contact.field.parent_point_count_", replace_after = "w_safe")
summary_table_habits_crisis <- multiple_table_output(columns_to_summarise = data_habit_parent_points_w_crisis,
replace = "rp.contact.field.parent_point_count_", replace_after = "w_crisis")
summary_table_habits_celebrate <- multiple_table_output(columns_to_summarise = data_habit_parent_points_w_celebrate,
replace = "rp.contact.field.parent_point_count_", replace_after = "w_celebrate")
#Error as rp.contact.field.parent_point_count_praise_teen_w_celebrate does not exist
#Error as Column `rp.contact.field.parent_point_count_money_w_crisis` doesn't exist.
#NB error as Column `rp.contact.field.parent_point_count_consequence_w_money` doesn't exist.
#the tables seems to require all values to exist at least once in order to create the table for any of the parent points in that week.
#false: more likely issue is that R truncated some long contact field names and now cannot find them...
# for now: data_habit_parent_points_w_money <- data_habit_parent_points_w_money[-8]
#NB error as Column `parent_point_count_consequence_w_rules` doesn't exist.
# for now: data_habit_parent_points_w_rules <- data_habit_parent_points_w_rules[-8]
#Error as Column `rp.contact.field.parent_point_count_money_w_consequence` doesn't exist.
summary_mean_habits <- summary_table(columns_to_summarise = data_habit_parent_points_all,
replace = "rp.contact.field.parent_point_count_",
summaries = "mean")
#same as this:
#summary_mean_habits <- plhdata_org_clean %>%
# group_by(Org) %>%
# summarise(across(data_habit_parent_points_all, mean, na.rm = TRUE))
#colnames(summary_mean_habits) <- naming_conventions(colnames(summary_mean_habits), "rp.contact.field.parent_point_count_")
# Completion Level ----------------------------------------------------------------------------
data_completion_level <- c("rp.contact.field.w_self_care_completion_level", "rp.contact.field.w_1on1_completion_level", "rp.contact.field.w_praise_completion_level",
"rp.contact.field.w_instruct_completion_level", "rp.contact.field.w_stress_completion_level",
"rp.contact.field.w_money_completion_level", "rp.contact.field.w_rules_completion_level", #you have "safe_completion" under rules. Is this right?
"rp.contact.field.w_consequence_completion_level", "rp.contact.field.w_solve_completion_level", "rp.contact.field.w_safe_completion_level",
"rp.contact.field.w_crisis_completion_level", "rp.contact.field.w_celebrate_completion_level")
completion_vars <- c("Self Care", "One-on-one Time", "Praise", "Positive Instructions", "Managing Stress", "Family Budgets", "Rules", "Calm Consequences", "Problem Solving", "Teen Safety", "Dealing with Crisis","Celebration & Next Steps")
summary_table_completion_level <- multiple_table_output(columns_to_summarise = data_completion_level,
replace = "rp.contact.field.w_", replace_after = "_completion_level")
names(summary_table_completion_level) <- completion_vars
summary_plot_completion_level <- multiple_plot_output(columns_to_summarise = data_completion_level,
replace = "rp.contact.field.w_", replace_after = "_completion_level")
names(summary_plot_completion_level) <- completion_vars
summary_plot_completion_level$`One-on-one Time`
#mean average completion level per org
summary_mean_completion_level <- summary_table(columns_to_summarise = data_completion_level,
replace = "rp.contact.field.w_",
replace_after = "_completion_level",
summaries = "mean")
# Percentage of users who completed a workshop out of those who started it
# nrow(plhdata_org_clean %>% filter(rp.contact.field.w_money_completion_level == 100)) / nrow(plhdata_org_clean %>% filter(rp.contact.field.w_money_started == "true"))
# nrow(plhdata_org_clean %>% filter(rp.contact.field.w_money_completion_level == 100)) / nrow(plhdata_org_clean %>% filter(rp.contact.field.w_money_completion_level > 0))
for (i in 1:length(summary_table_completion_level)){
if (!"100" %in% names(summary_table_completion_level[[i]])){
summary_table_completion_level[[i]]$`100` <- 0
}
}
relative_perc_completed <- imap(summary_table_completion_level, ~.x %>%
mutate(started = Total - `0` - `NA`,
perc_completed = `100`/started*100) %>%
select(c(Org, started, perc_completed)))
table_perc_completed <- plyr::ldply(relative_perc_completed) %>%
pivot_wider(id_cols = Org, names_from = .id, values_from = perc_completed)
table_ws_started <- plyr::ldply(relative_perc_completed) %>%
pivot_wider(id_cols = Org, names_from = .id, values_from = started)
# Survey - past week ----------------------------------------------------------------------------
r_variables_names <- readxl::read_excel("r_variables_names.xlsx")
data_survey_past_week_all <- r_variables_names %>% filter(location_ID == "survey_past_week")
summary_table_survey_past_week <- tabulate_with_metadata(location_ID = "survey_past_week")
#data_survey_past_week <- c("rp.contact.field.survey_welcome_a_1_final", "rp.contact.field.survey_welcome_a_2_final",
# "rp.contact.field.survey_welcome_a_3_final", "rp.contact.field.survey_welcome_a_4_final",
# "rp.contact.field.survey_welcome_a_5_part_1_final", "rp.contact.field.survey_welcome_a_5_part_2_final",
# "rp.contact.field.survey_welcome_a_6_final", "rp.contact.field.survey_welcome_a_7_part_1_final",
# "rp.contact.field.survey_welcome_a_7_part_2_final", "rp.contact.field.survey_welcome_a_7_part_3_final",
# "rp.contact.field.survey_welcome_a_8_final", "rp.contact.field.survey_welcome_a_9_final")
#survey_vars <- c("Attention", "Praise", "Stress", "Shouting", "Money worries", "Summary", "Hitting", "Teen activity", "Lockdown?", "Knowledge of teen activity in non-lockdown week",
# "Sexual safety talk", "Teen COVID safe")
#summary_table_survey_past_week <- plhdata_org_clean %>%
# map(.x = data_survey_past_week, .f = ~summary_table(columns_to_summarise = .x, display = FALSE, include_margins = TRUE))
#names(summary_table_survey_past_week) <- survey_vars
# then to access a table:
# summary_table_survey_past_week$Attention
# summary_table_survey_past_week$Praise
# summary_table_survey_past_week$Stress
# summary_table_survey_past_week$Shouting
# summary_table_survey_past_week$`Money worries`
# summary_table_survey_past_week$Summary
# summary_table_survey_past_week$Hitting
# summary_table_survey_past_week$`Teen activity`
# summary_table_survey_past_week$`Lockdown?`
# summary_table_survey_past_week$`Knowledge of teen activity in non-lockdown week`
# summary_table_survey_past_week$`Sexual safety talk`
# summary_table_survey_past_week$`Teen COVID safe`
#TODO iff "7" to 7.1? - TODO - what do they mean by this?
## Home Practice ------------------------------------------------------------------
# home practice labels, NB two home practices for stress workshop (breathe and talk), but separate fields only exist for done and mood, not for started, challenges or completed
# completed field not included in analysis as it's a bit redundant (HP is completed when started, done, mood, and challenge are completed)
## create neat labels for HP variables - not used because replace and replace.after are sufficent to create labels and removes need for dummy when one workshop doesn't have the value
# hp_vars_done_mood <- c("One-on-one Time", "Praise", "Positive Instructions", "Stress - Breathe", "Stress - Talk", "Family Budgets", "Rules", "Calm Consequences", "Problem Solving", "Teen Safety", "Dealing with Crisis","Celebration & Next Steps")
# hp_vars_started_chall <- c("One-on-one Time", "Praise", "Positive Instructions", "Stress", "Family Budgets", "Rules", "Calm Consequences", "Problem Solving", "Teen Safety", "Dealing with Crisis","Celebration & Next Steps")
data_hp_started <- c("rp.contact.field.w_1on1_hp_review_started", "rp.contact.field.w_praise_hp_review_started",
"rp.contact.field.w_instruct_hp_review_started", "rp.contact.field.w_stress_hp_review_started",
"rp.contact.field.w_money_hp_review_started", "rp.contact.field.w_rules_hp_review_started",
"rp.contact.field.w_consequence_hp_review_started", "rp.contact.field.w_solve_hp_review_started", "rp.contact.field.w_safe_hp_review_started",
"rp.contact.field.w_crisis_hp_review_started")
data_hp_done <- c("rp.contact.field.w_1on1_hp_done", "rp.contact.field.w_praise_hp_done", "rp.contact.field.w_instruct_hp_done", "rp.contact.field.w_stress_hp_breathe_done", "rp.contact.field.w_stress_hp_talk_done",
"rp.contact.field.w_money_hp_done", "rp.contact.field.w_rules_hp_done", "rp.contact.field.w_consequence_hp_done",
"rp.contact.field.w_solve_hp_done", "rp.contact.field.w_safe_hp_done", "rp.contact.field.w_crisis_hp_done")
# NB No mood 'review' for week 3 home practice (praise)
data_hp_mood <- c("rp.contact.field.w_1on1_hp_mood", "rp.contact.field.w_instruct_hp_mood", "rp.contact.field.w_stress_hp_breathe_mood", "rp.contact.field.w_stress_hp_talk_mood",
"rp.contact.field.w_money_hp_mood", "rp.contact.field.w_rules_hp_mood", "rp.contact.field.w_consequence_hp_mood",
"rp.contact.field.w_solve_hp_mood", "rp.contact.field.w_safe_hp_mood", "rp.contact.field.w_crisis_hp_mood")
# TODO: this should work in function
plhdata_org_clean <- add_na_variable(variable = data_hp_started)
plhdata_org_clean <- add_na_variable(variable = data_hp_done)
plhdata_org_clean <- add_na_variable(variable = data_hp_mood)
#Combine home practice challenges (append hp_challenge to hp_challenge_list and remove null and duplicates) NB no challenge for praise workshop week
summary_table_hp_chall <- NULL
summary_table_hp_chall$hp_list_challenges_1on1 <- challenge_freq(var = "rp.contact.field.w_1on1_hp_challenge_list", append_var = "rp.contact.field.w_1on1_hp_challenge")
summary_table_hp_chall$hp_list_challenges_instruct <- challenge_freq(var = "rp.contact.field.w_instruct_hp_challenge_list", append_var = "rp.contact.field.w_instruct_hp_challenge")
summary_table_hp_chall$hp_list_challenges_stress <- challenge_freq(var = "rp.contact.field.w_stress_hp_challenge_list", append_var = "rp.contact.field.w_breathe_hp_challenge")
#summary_table_hp_chall$ <- challenge_freq(var = "rp.contact.field.w_talk_hp_challenge_list", append_var = "rp.contact.field.w_talk_hp_challenge")
summary_table_hp_chall$hp_list_challenges_money <- challenge_freq(var = "rp.contact.field.w_money_hp_challenge_list", append_var = "rp.contact.field.w_money_hp_challenge")
summary_table_hp_chall$hp_list_challenges_rules <- challenge_freq(var = "rp.contact.field.w_rules_hp_challenge_list", append_var = "rp.contact.field.w_rules_hp_challenge")
summary_table_hp_chall$hp_list_challenges_consequence <- challenge_freq(var = "rp.contact.field.w_consequence_hp_challenge_list", append_var = "rp.contact.field.w_consequence_hp_challenge")
summary_table_hp_chall$hp_list_challenges_solve <- challenge_freq(var = "rp.contact.field.w_solve_hp_challenge_list", append_var = "rp.contact.field.w_solve_hp_challenge")
summary_table_hp_chall$hp_list_challenges_safe <- challenge_freq(var = "rp.contact.field.w_safe_hp_challenge_list", append_var = "rp.contact.field.w_safe_hp_challenge")
summary_table_hp_chall$hp_list_challenges_crisis <- challenge_freq(var = "rp.contact.field.w_crisis_hp_challenge_list", append_var = "rp.contact.field.w_crisis_hp_challenge")
# NB No challenge for week 3 home practice (praise)
data_hp_chall <- c("hp_list_challenges_1on1", "hp_list_challenges_instruct", "hp_list_challenges_stress", "hp_list_challenges_money", "hp_list_challenges_rules",
"hp_list_challenges_consequence", "hp_list_challenges_solve", "hp_list_challenges_safe", "hp_list_challenges_crisis")
# overview table for home practice review started: number of users per home practice who reached first screen, i.e. only "true" not "false" or NA
data_hp_started_neat <- naming_conventions(data_hp_started, replace = "rp.contact.field.w_", replace_after = "_review_started")
summary_table_hp_started <- multiple_table_output(plhdata_org_clean, data_hp_started)
names(summary_table_hp_started) <- data_hp_started_neat
table_hp_started_long <- plyr::ldply(summary_table_hp_started) #could be the table used for teh plot to show true, false and NA for each HP review
if (!"true" %in% colnames(table_hp_started_long)) { table_hp_started_long$true <- 0 }
table_hp_started <- table_hp_started_long %>% pivot_wider(id_cols = Org, names_from = .id, values_from = c(true))
#how to call in Rshiny: summary_table_hp_started$`1on1 hp` etc
# home practice review - user claims they had a chance to do the hp
summary_table_hp_done <- multiple_table_output(plhdata_org_clean, data_hp_done, replace = "rp.contact.field.w_", replace_after = "_done")
#summary_table_hp_done$`1on1 hp`
# home practice review - user notes how HP went
summary_table_hp_mood <- multiple_table_output(plhdata_org_clean, data_hp_mood, replace = "rp.contact.field.w_", replace_after = "_mood")
#summary_table_hp_mood$`1on1 hp`
# home practice review - challenges selected for each workshop
#summary_table_hp_chall <- multiple_table_output(plhdata_org_clean, data_hp_chall, replace = "hp_list_")
# summary_table_hp_chall$___
# parent library ------------------------------------------------------------------
data_library <- c("rp.contact.field.click_hs_parent_centre_count", "rp.contact.field.click_pc_help_count",
"rp.contact.field.click_pc_my_tips_count", "rp.contact.field.click_pc_essential_tools_count",
"rp.contact.field.click_pc_covid_count", "rp.contact.field.click_pc_customisation_count",
"rp.contact.field.click_pc_relax_and_activities_count", "rp.contact.field.click_pc_support_contacts_count",
"rp.contact.field.click_pc_evidence_base_count", "rp.contact.field.click_pc_technical_support_count",
"rp.contact.field.click_pc_message_archive_count","rp.contact.field.click_pc_bereavement_count")
summary_table_library <- multiple_table_output(columns_to_summarise = data_library, replace = "rp.contact.field.click_pc_", replace_after = "count")
data_library_neat <- naming_conventions(names(summary_table_library), replace = "Rp.contact.field.click hs")
names(summary_table_library) <- data_library_neat
#mean library clicks (button type per organisation)
#mean library clicks per workshop week is not stored to my knowledge
summary_library_mean <- plhdata_org_clean %>%
group_by(Org) %>%
summarise(across(data_library, mean, na.rm = TRUE))
colnames(summary_library_mean) <- naming_conventions(colnames(summary_library_mean), "rp.contact.field.click_", "_count")
# summary_library_mean
#Test 2 Priority 22 (how to interpret data?)
#Number of in-app message clicks per workshop week.Per quick start button, per workshop week
#Workshops
plhdata_org_clean$hsqsclickedws1<-!is.na(plhdata_org_clean$rp.contact.field.click_hs_weekly_workshops_quick_start_w_self_care)
data_weekly_workshops <- c("rp.contact.field.click_hs_weekly_workshops_quick_start_w_self_care",
"hsqsclickedws1", "rp.contact.field.click_hs_weekly_workshops_quick_start_w_1on1",
"rp.contact.field.click_hs_weekly_workshops_quick_start_w_praise", "rp.contact.field.click_hs_weekly_workshops_quick_start_w_instruct",
"rp.contact.field.click_hs_weekly_workshops_quick_start_w_stress", "rp.contact.field.click_hs_weekly_workshops_quick_start_w_money",
"rp.contact.field.click_hs_weekly_workshops_quick_start_w_rules", "rp.contact.field.click_hs_weekly_workshops_quick_start_w_consequence",
"rp.contact.field.click_hs_weekly_workshops_quick_start_w_solve", "rp.contact.field.click_hs_weekly_workshops_quick_start_w_safe",
"rp.contact.field.click_hs_weekly_workshops_quick_start_w_crisis", "rp.contact.field.click_hs_weekly_workshops_quick_start_w_celebrate",
"rp.contact.field.click_hs_parent_centre_quick_start_w_self_care", "rp.contact.field.click_hs_parent_centre_quick_start_w_1on1",
"rp.contact.field.click_hs_parent_points_quick_start_w_self_care", "rp.contact.field.click_hs_parent_points_quick_start_w_1on1")
data_weekly_workshops_neat <- c("Self care", "In app reminders", "One-on-one time", "Praise", "Positive instructions", "Stress",
"Family Budgets", "Rules", "Calm consequence", "Problem solving", "Teen safety", "Dealing with crisis",
"Celebration and Next Steps", "Parent center - Self care", "Parent center - One-on-one time", "Parent points - Self care", "Parent points - One-on-one time")
summary_tableweekly_workshops <- multiple_table_output(columns_to_summarise = data_weekly_workshops)
names(summary_tableweekly_workshops) <- data_weekly_workshops_neat
# summary_tableweekly_workshops$Stress
#In-app reminders(Number of in-app message clicks per workshop week),Per quick start button, per workshop week -------------------------
# TODO: hsqsclickedws1, hsqsclickedws2 is defined twice, differently each time. Should have different names - is this intentional?
plhdata_org_clean$hsqsclickedws1<-is.na(plhdata_org_clean$rp.contact.field.click_hs_weekly_workshops_quick_start_w_self_care)
plhdata_org_clean$hsqsclickedws2<-!is.na(plhdata_org_clean$rp.contact.field.click_hs_weekly_workshops_quick_start_w_1on1)
# summary_table(columns_to_summarise = hsqsclickedws1)
# summary_table(columns_to_summarise = hsqsclickedws2)
#Test 1
#plhdata_org_clean$hsqsclickedws1<-!is.na(plhdata_org_clean$rp.contact.field.click_hs_weekly_workshops_quick_start_count_w_self_care)
#plhdata_org_clean$hsqsclickedcountws1<-!is.na(plhdata_org_clean$rp.contact.field.click_hs_weekly_workshops_quick_start_count_w_self_care)
#plhdata_org_clean$hsqsclickedws2<-!is.na(plhdata_org_clean$rp.contact.field.click_hs_weekly_workshops_quick_start_w_1on1)
# summary_table(columns_to_summarise = rp.contact.field.click_hs_weekly_workshops_quick_start_count_w_self_care, replace = "rp.contact.field.click_hs_")
# user_id_print("rp.contact.field.click_hs_weekly_workshops_quick_start_count_w_self_care")
# summary_table(columns_to_summarise = hsqsclickedws1)
# summary_table(columns_to_summarise = hsqsclickedcountws1)
# summary_table(columns_to_summarise = hsqsclickedws2)
#Priority 23
#In-app reminders
#Total number of in-app message clicks.By User
#Weekly workshops
# summary_table(columns_to_summarise = rp.contact.field.click_hs_weekly_workshops_quick_start_count, replace = "rp.contact.field.click_hs_")
#
# #Parent center
# summary_table(columns_to_summarise = rp.contact.field.click_hs_parent_centre_quick_start_count, replace = "rp.contact.field.click_hs_")
#
# #Parent points
# summary_table(columns_to_summarise = rp.contact.field.click_hs_parent_points_quick_start_count, replace = "rp.contact.field.click_hs_")
#Priority 19
#App-opens
#Total number of app-opens for each user(cumulative)
#app_open_summary <- plhdata_org_clean %>%
# group_by(Org) %>%
# summarise(sum(rp.contact.field.app_launch_count))
# user_id_print("rp.contact.field.app_launch_count")
##Priority 20
#App-opens
#Number of app opens within a workshop week for each user
data_app_opens <- c("rp.contact.field.app_launch_count","rp.contact.field.app_launch_count_w_self_care", "rp.contact.field.app_launch_count_w_1on1",
"rp.contact.field.app_launch_count_w_praise","rp.contact.field.app_launch_count_w_instruct",
"rp.contact.field.app_launch_count_w_stress", "rp.contact.field.app_launch_count_w_money",
"rp.contact.field.app_launch_count_w_rules", "rp.contact.field.app_launch_count_w_consequence",
"rp.contact.field.app_launch_count_w_solve", "rp.contact.field.app_launch_count_w_safe",
"rp.contact.field.app_launch_count_w_crisis", "rp.contact.field.app_launch_count_w_celebrate")
data_app_opens_neat <- c("Total", "Welcome and Self care(1)", "One-on-one time(2)", "Praise (3)", "Positive Instructions(4)",
"Managing Stress(5)", "Family Budget(6)","Rules(7)", "Calm Consequences(8)",
"Problem Solving(9)", "Teen Safety(10)", "Crisis(11)", "Celebration & Next Steps(12)")
tables_app_opens <- multiple_table_output(columns_to_summarise = data_app_opens)
names(tables_app_opens) <- data_app_opens_neat
#Average app opens per ws week
summary_mean_appopens <- plhdata_org_clean %>%
group_by(Org) %>%
summarise(across(data_app_opens, mean, na.rm = TRUE))
colnames(summary_mean_appopens)[2:length(summary_mean_appopens)] <- data_app_opens_neat
# summary_mean_appopens
# Make the table longer so that it is in a format for use in ggplot
summary_mean_appopens_long <- summary_mean_appopens %>%
pivot_longer(cols = !Org) %>%
mutate(name = fct_relevel(name, data_app_opens_neat)) # set the order of variables
# summary_mean_appopens_long
##Priority 21
#App-opens
#Maximum time between app-opens - for each user.Time in full days
plhdata_org_clean$rp.contact.field.max_days_between_app_launches <- as.numeric(plhdata_org_clean$rp.contact.field.max_days_between_app_launches)
# summary_table(columns_to_summarise = rp.contact.field.max_days_between_app_launches, replace = "rp.contact.field.")
#Priority 36 --------------------------------------------------------------------------------
#Emotional Check-in
#Rate of users who respond "happy" ,"sad" & "ok"
data_emotional_check_in <- c("rp.contact.field.w_self_care_welcome_individual_a_final", "rp.contact.field.w_1on1_welcome_individual_a_final",
"rp.contact.field.w_praise_welcome_individual_a_final", "rp.contact.field.w_instruct_welcome_individual_a_final",
"rp.contact.field.w_stress_welcome_individual_a_final", "rp.contact.field.w_money_welcome_individual_a_final",
"rp.contact.field.w_rules_welcome_individual_a_final")
data_emotional_check_in_neat <- c("Self care", "One-on-one time", "Praise", "Positive instructions", "Managing stress", "Family budgets", "Rules")
tables_emotional_check_in <- multiple_table_output(columns_to_summarise = data_emotional_check_in)
names(tables_emotional_check_in) <- data_emotional_check_in_neat
# tables_emotional_check_in$`Self care`
# Completion rate of introductory session(Workshop 1:Selfcare) ------------------------------------------------
# plhdata_org_clean %>%
# split(.$Org) %>%
# map(~summary_table(data = .x, factor = NULL, columns_to_summarise = rp.contact.field.w_self_care_completed, replace = "rp.contact.field.survey"))
#plhdata_org_clean %>% group_by(Org) %>% select('app_user_id', "rp.contact.field.w_self_care_completed")
#plhdata_org_clean %>% group_by(Org) %>% select('app_user_id', "rp.contact.field.w_self_care_started")
#plhdata_org_clean %>% group_by(Org) %>% select('app_user_id', "rp.contact.field.w_1on1_started")
# Completion status of baseline survey ------------------------------------------------
# plhdata_org_clean %>%
# split(.$Org) %>%
# map(~summary_table(data = .x, factor = NULL, columns_to_summarise = rp.contact.field.survey_welcome_complppplheted, replace = "rp.contact.field.survey"))
summary_table_survey_completion <- plhdata_org_clean %>%
summary_table(columns_to_summarise = "rp.contact.field.survey_welcome_and_setup_completion_level", display = FALSE, include_margins = TRUE)
# summary_table_survey_completion
# Descriptive Statistics ------------------------------------------------------------------------------------------
# Gender of App Users
gender_table <- plhdata_org_clean %>%
split(.$Org) %>%
map(~summary_table(data = .x, factor = NULL, columns_to_summarise = rp.contact.field.user_gender))
names(gender_table) <- levels(plhdata_org_clean$Org)
# gender_table$Nontobeko
# gender_table$Amathuba
# gender_table
# Age of App Users
# summary_table(columns_to_summarise = rp.contact.field.user_age, summaries = "mean")
#Trials-----------------
# plhdata_org_clean %>% select('app_user_id', "rp.contact.field.user_age")
# plhdata_org_clean %>% select('app_user_id', "rp.contact.field.user_gender")
# plhdata_org_clean %>% filter(Org == "Amathuba") %>% select('app_user_id', "rp.contact.field.user_gender")
# mean(x=as.numeric(plhdata_org_clean$rp.contact.field.user_age), na.rm=TRUE)
##################################
##################################
### Notification Data Analysis ###
##################################
##################################
# download push notification data
# TODO: add fuzzy join to get_nf_data function
nf_data <- get_nf_data(site = plh_con) #, UIC_Tracker = UIC.Tracker)
#
# # what variables do we want in the nf data - org, sex, - add a few in.
data_baseline_survey <-
c(
"Org",
"rp.contact.field.survey_welcome_completed",
"rp.contact.field.user_gender",
"rp.contact.field.user_age",
"rp.contact.field.household_adults",
"rp.contact.field.household_teens",
"rp.contact.field.household_babies",
"rp.contact.field.household_children",
"rp.contact.field._app_language",
"app_version",
"rp.contact.field.workshop_path"
)
plhdata_org_clean_select <- plhdata_org_clean %>%
dplyr::select(c(app_user_id, data_baseline_survey))
# link nf data to user data by app_user_id
# use inner_join: remove from nf anyone not in plhdata_org
nf_data_join <- inner_join(nf_data, plhdata_org_clean_select)
# Only 8 rows. This is because we have filtered out a lot of the plhdata_org_clean users
# since their org is NA.
# e.g.:
#plhdata_org %>% filter(app_user_id == "73d882bf9283163d") %>% select(rp.contact.field.organisation_code)
# we're throwing away a lot of data over this missing organisation. I think we need to reconsider
# how to handle these?
# Additionally surely TZ has only one organisation?
pn_summary_count <- nf_data_join %>%
group_by(app_user_id, Org, rp.contact.field._app_language) %>%
summarise(
number_received = max(app_user_record_id),
number_responded = sum(!is.na(action_id)),
percentage_responded = number_responded / number_received *
100
)