forked from COHHIO/COHHIO_HMIS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06_Project_Evaluation.R
1950 lines (1812 loc) · 69.1 KB
/
06_Project_Evaluation.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
# COHHIO_HMIS
# Copyright (C) 2020 Coalition on Homelessness and Housing in Ohio (COHHIO)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details at
# <https://www.gnu.org/licenses/>.
library(tidyverse)
library(lubridate)
library(scales)
library(readxl)
library(HMIS)
# loading old data to freeze data as of the deadline
load("images/COHHIOHMIS.RData")
rm(Affiliation, CaseManagers, Disabilities, EmploymentEducation, EnrollmentCoC,
Export, HealthAndDV, Inventory, Offers, ProjectCoC, Referrals,
regions, Scores, Services, stray_services, Users, VeteranCE)
load("images/cohorts.RData")
rm(FileActualStart, FileStart, FileEnd, update_date, summary)
load("images/Data_Quality.RData")
# Points function ---------------------------------------------------------
pe_score <- function(structure, value) {
case_when(
structure == "24_30_11" & value >= .3 ~ 11,
structure == "24_30_11" & value >= .27 & value < .3 ~ 8,
structure == "24_30_11" & value >= .24 & value < .27 ~ 5,
structure == "24_30_11" & value < .24 ~ 0,
structure == "75_85_12" & value >= .85 ~ 12,
structure == "75_85_12" & value >= .8 & value < .85 ~ 9,
structure == "75_85_12" & value >= .75 & value < .8 ~ 5,
structure == "75_85_12" & value < .75 ~ 0,
structure == "80_90_12" & value >= .9 ~ 12,
structure == "80_90_12" & value >= .85 & value < .9 ~ 9,
structure == "80_90_12" & value >= .8 & value < .85 ~ 5,
structure == "80_90_12" & value < .8 ~ 0,
structure == "0_730_10" & value <= 730 ~ 10,
structure == "0_730_10" & value > 730 ~ 0,
structure == "75_85_10" & value >= .85 ~ 10,
structure == "75_85_10" & value >= .8 & value < .85 ~ 7.5,
structure == "75_85_10" & value >= .75 & value < .8 ~ 5,
structure == "75_85_10" & value < .75 ~ 0,
structure == "20_90_10" & value >= .9 ~ 10,
structure == "20_90_10" & value >= .75 & value < .9 ~ 8,
structure == "20_90_10" & value >= .5 & value < .75 ~ 6,
structure == "20_90_10" & value >= .3 & value < .5 ~ 4,
structure == "20_90_10" & value >= .2 & value < .3 ~ 2,
structure == "20_90_10" & value < .2 ~ 0,
structure == "2_6_10" & value <= .02 ~ 10,
structure == "2_6_10" & value <= .04 & value > .02 ~ 7.5,
structure == "2_6_10" & value <= .06 & value > .04 ~ 5,
structure == "2_6_10" & value > .06 ~ 0,
structure == "5_9_10" & value <= .05 ~ 10,
structure == "5_9_10" & value <= .08 & value > .05 ~ 7.5,
structure == "5_9_10" & value <= .09 & value > .08 ~ 5,
structure == "5_9_10" & value > .09 ~ 0,
structure == "75_83_10" & value >= .83 ~ 10,
structure == "75_83_10" & value >= .79 & value < .83 ~ 7.5,
structure == "75_83_10" & value >= .75 & value < .79 ~ 5,
structure == "75_83_10" & value < .75 ~ 0,
structure == "72_80_5" & value >= .8 ~ 5,
structure == "72_80_5" & value >= .76 & value < .8 ~ 3,
structure == "72_80_5" & value >= .72 & value < .76 ~ 2,
structure == "72_80_5" & value < .72 ~ 0,
structure == "7_12_10" & value <= .07 ~ 10,
structure == "7_12_10" & value <= .09 & value > .07 ~ 7.5,
structure == "7_12_10" & value <= .12 & value > .09 ~ 5,
structure == "7_12_10" & value > .12 ~ 0,
structure == "12_17_10" & value <= .12 ~ 10,
structure == "12_17_10" & value > 12 & value <= .14 ~ 7.5,
structure == "12_17_10" & value > .14 & value <= 17 ~ 5,
structure == "12_17_10" & value > .17 ~ 0,
structure == "22_28_10" & value >= .28 ~ 10,
structure == "22_28_10" & value >= .26 & value < .28 ~ 7.5,
structure == "22_28_10" & value >= .22 & value < .26 ~ 5,
structure == "22_28_10" & value < .22 ~ 0,
structure == "0_7_10_PSH" & value >= 6 & value <= 7 ~ 10,
structure == "0_7_10_PSH" & value >= 5 & value < 6 ~ 9,
structure == "0_7_10_PSH" & value >= 3 & value < 5 ~ 8,
structure == "0_7_10_PSH" & value >= 2 & value < 3 ~ 5,
structure == "0_7_10_PSH" & value >= 1 & value < 2 ~ 2,
structure == "0_7_10_PSH" & value < 1 ~ 0,
structure == "200_280_10" & value <= 200 ~ 10,
structure == "200_280_10" & value <= 240 & value > 200 ~ 7.5,
structure == "200_280_10" & value <= 280 & value > 240 ~ 5,
structure == "200_280_10" & value > 280 ~ 0,
structure == "67_75_10" & value >= .75 ~ 10,
structure == "67_75_10" & value >= .71 & value < .75 ~ 7.5,
structure == "67_75_10" & value >= .67 & value < .71 ~ 5,
structure == "67_75_10" & value < .67 ~ 0,
structure == "0_7_10" & value >= 4 & value <= 7 ~ 10,
structure == "0_7_10" & value >= 3 & value < 4 ~ 8,
structure == "0_7_10" & value >= 2 & value < 3 ~ 7,
structure == "0_7_10" & value >= 1 & value < 2 ~ 5,
structure == "0_7_10" & value < 1 ~ 0,
structure == "15_19_10" & value <= .15 ~ 10,
structure == "15_19_10" & value <= .17 & value > .15 ~ 7.5,
structure == "15_19_10" & value <= .19 & value > .17 ~ 5,
structure == "15_19_10" & value > .19 ~ 0,
structure == "20_24_10" & value <= .2 ~ 10,
structure == "20_24_10" & value <= .22 & value > .2 ~ 7.5,
structure == "20_24_10" & value <= .24 & value > .22 ~ 5,
structure == "20_24_10" & value > .24 ~ 0,
structure == "16_20_10" & value >= .2 ~ 10,
structure == "16_20_10" & value < .2 & value >= .18 ~ 7.5,
structure == "16_20_10" & value < .18 & value >= .16 ~ 5,
structure == "16_20_10" & value < .16 ~ 0,
structure == "260_340_10" & value <= 260 ~ 10,
structure == "260_340_10" & value > 260 & value <= 300 ~ 7.5,
structure == "260_340_10" & value > 300 & value <= 340 ~ 5,
structure == "260_340_10" & value > 340 ~ 0,
structure == "0_100_10" & value == 1 ~ 10,
structure == "0_100_10" & value < 1 ~ 0,
structure == "14_18_10" & value >= .18 ~ 10,
structure == "14_18_10" & value < .18 & value >= .16 ~ 7.5,
structure == "14_18_10" & value < .16 & value >= .14 ~ 5,
structure == "14_18_10" & value < .14 ~ 0,
structure == "150_210_10" & value <= 150 ~ 10,
structure == "150_210_10" & value <= 170 & value > 150 ~ 7.5,
structure == "150_210_10" & value <= 210 & value > 170 ~ 5,
structure == "150_210_10" & value > 210 ~ 0,
structure == "80_90_10" & value >= .9 ~ 10,
structure == "80_90_10" & value >= .85 & value < .9 ~ 7.5,
structure == "80_90_10" & value >= .8 & value < .85 ~ 5,
structure == "80_90_10" & value < .8 ~ 0,
structure == "34_40_10" & value >= .4 ~ 10,
structure == "34_40_10" & value >= .37 & value < .4 ~ 7.5,
structure == "34_40_10" & value >= .34 & value < .37 ~ 5,
structure == "34_40_10" & value < .34 ~ 0,
structure == "24_30_10" & value >= .3 ~ 10,
structure == "24_30_10" & value >= .27 & value < .3 ~ 7.5,
structure == "24_30_10" & value >= .24 & value < .27 ~ 5,
structure == "24_30_10" & value < .24 ~ 0,
structure == "90_100_5" & value == 1 ~ 5,
structure == "90_100_5" & value >= .9 & value < 1 ~ 2,
structure == "90_100_5" & value < .9 ~ 0
)
}
# The specs for this report is here:
#https://cohhio.org/wp-content/uploads/2019/03/2019-CoC-Competition-Plan-and-Timeline-FINAL-merged-3.29.19.pdf
ReportYear <- "2019"
ReportStart <- format.Date(mdy(paste0("0101", ReportYear)), "%m-%d-%Y")
ReportEnd <- format.Date(mdy(paste0("1231", ReportYear)), "%m-%d-%Y")
# Staging -----------------------------------------------------------------
keepers <- c(746, 15, 1353, 719, 737, 774, 208, 1566)
retired <- c(747, 1774, 1354, 718, 721, 738, 739, 548, 763, 764, 1323, 1579, 390)
pe_coc_funded <- Funder %>%
filter(Funder %in% c(1:7) &
ProjectID != 2069 &
(ProjectID %in% c(keepers, retired) |
(
ymd(StartDate) <= mdy(ReportEnd) &
(is.na(EndDate) |
ymd(EndDate) >= mdy(ReportEnd))
))) %>%
select(ProjectID, Funder, StartDate, EndDate) %>%
left_join(Project[c("ProjectID",
"ProjectName",
"ProjectType",
"HMISParticipatingProject")], by = "ProjectID") %>%
filter(HMISParticipatingProject == 1) %>%
select(ProjectType,
ProjectName,
ProjectID)
# consolidated projects
consolidations <- pe_coc_funded %>%
filter(ProjectID %in% c(keepers, retired)) %>%
mutate(
AltProjectID = case_when(
ProjectID %in% c(718, 719, 721) ~ 3000,
ProjectID %in% c(1353, 1354, 390) ~ 3001,
ProjectID %in% c(746, 747) ~ 3002,
ProjectID %in% c(1774, 15) ~ 3003,
ProjectID %in% c(737, 738, 739) ~ 3004,
ProjectID %in% c(548, 763, 764, 774) ~ 3005,
ProjectID %in% c(1323, 208) ~ 3006,
ProjectID %in% c(1566, 1579) ~ 3007
),
AltProjectName = case_when(
ProjectID %in% c(718, 719, 721) ~ "Butler County PSH Combined (718, 719, 721)",
ProjectID %in% c(1353, 1354, 390) ~ "Springfield SPC 1 Combined (1353, 1354, 390)",
ProjectID %in% c(746, 747) ~ "Jefferson County SPC Combined (746, 747)",
ProjectID %in% c(1774, 15) ~ "GLCAP PSH Combined (1774, 15)",
ProjectID %in% c(737, 738, 739) ~ "Lake SPC Combined (737, 738, 739)",
ProjectID %in% c(548, 763, 764, 774) ~ "Trumbull SPC Vouchers Combined (548, 763, 764, 774)",
ProjectID %in% c(1323, 208) ~ "Warren SPC Combined (1323, 208)",
ProjectID %in% c(1566, 1579) ~ "One Eighty PSH Plus Care Combined (1566, 1579)"
)
) %>%
select(ProjectID, ProjectName, AltProjectID, AltProjectName)
# filter to only CoC-funded projects (leaving out the SSO)
pe_coc_funded <- pe_coc_funded %>%
left_join(consolidations, by = c("ProjectID", "ProjectName")) %>%
mutate(
AltProjectID = if_else(is.na(AltProjectID), ProjectID, AltProjectID),
AltProjectName = if_else(is.na(AltProjectName), ProjectName, AltProjectName)
)
vars_we_want <- c(
"PersonalID",
"ProjectType",
"AltProjectID",
"VeteranStatus",
"EnrollmentID",
"AltProjectName",
"EntryDate",
"HouseholdID",
"RelationshipToHoH",
"LivingSituation",
"LengthOfStay",
"LOSUnderThreshold",
"PreviousStreetESSH",
"DateToStreetESSH",
"TimesHomelessPastThreeYears",
"AgeAtEntry",
"MonthsHomelessPastThreeYears",
"DisablingCondition",
"MoveInDate",
"MoveInDateAdjust",
"ExitDate",
"Destination",
"EntryAdjust",
"ExitAdjust"
)
vars_to_the_apps <- c(
"ProjectType",
"AltProjectName",
"PersonalID",
"EnrollmentID",
"HouseholdID",
"EntryDate",
"MoveInDateAdjust",
"ExitDate",
"MeetsObjective"
)
# Project Evaluation cohorts ----------------------------------------------
# pe_[cohort]: uses cohort objects to narrow down data to coc-funded projects'
# data to the 'vars_we_want', then dedupes in case there are multiple stays in
# that project during the date range.
# clients served during date range
pe_clients_served <- co_clients_served %>%
filter(served_between(., ReportStart, ReportEnd)) %>%
select("PersonalID", "ProjectID", "EnrollmentID") %>%
inner_join(pe_coc_funded, by = "ProjectID") %>%
left_join(Client, by = "PersonalID") %>%
left_join(
Enrollment %>%
select(-UserID,-DateCreated,-DateUpdated,-DateDeleted,-ExportID),
by = c(
"PersonalID",
"EnrollmentID",
"ProjectID",
"ProjectType",
"ProjectName"
)
) %>%
select(all_of(vars_we_want)) %>%
arrange(PersonalID, AltProjectID, desc(EntryDate)) %>%
distinct(PersonalID, AltProjectName, .keep_all = TRUE) # no dupes w/in a project
# several measures will use this
# Checking for deceased hohs for points adjustments
hoh_exits_to_deceased <- pe_clients_served %>%
filter(Destination == 24 &
RelationshipToHoH == 1 &
exited_between(., ReportStart, ReportEnd)) %>%
group_by(AltProjectID) %>%
summarise(HoHDeaths = n()) %>%
ungroup() %>%
right_join(pe_coc_funded["AltProjectID"] %>% unique(), by = "AltProjectID")
hoh_exits_to_deceased[is.na(hoh_exits_to_deceased)] <- 0
# Adults who entered during date range
pe_adults_entered <- co_adults_served %>%
select("PersonalID", "ProjectID", "EnrollmentID") %>%
inner_join(pe_coc_funded, by = "ProjectID") %>%
left_join(Client, by = "PersonalID") %>%
left_join(
Enrollment %>%
select(-UserID, -DateCreated, -DateUpdated, -DateDeleted, -ExportID),
by = c(
"PersonalID",
"EnrollmentID",
"ProjectID",
"ProjectType",
"ProjectName"
)
) %>%
group_by(HouseholdID) %>%
mutate(HHEntryDate = min(EntryDate)) %>%
ungroup() %>%
filter(entered_between(., ReportStart, ReportEnd) &
EntryDate == HHEntryDate) %>%
select(all_of(vars_we_want)) %>%
arrange(PersonalID, AltProjectID, desc(EntryDate))
# this one counts each entry
## for vispdat measure
pe_hohs_entered <- co_hohs_entered %>%
filter(entered_between(., ReportStart, ReportEnd)) %>%
select("PersonalID", "ProjectID", "EnrollmentID") %>%
inner_join(pe_coc_funded, by = "ProjectID") %>%
left_join(Client, by = "PersonalID") %>%
left_join(
Enrollment %>%
select(-UserID,-DateCreated,-DateUpdated,-DateDeleted,-ExportID),
by = c(
"PersonalID",
"EnrollmentID",
"ProjectID",
"ProjectType",
"ProjectName"
)
) %>%
select(all_of(vars_we_want)) %>%
arrange(PersonalID, AltProjectID, desc(EntryDate))
# for ncb logic
# Adults who moved in and exited during date range
pe_adults_moved_in_leavers <- co_adults_moved_in_leavers %>%
filter(
stayed_between(., ReportStart, ReportEnd) &
exited_between(., ReportStart, ReportEnd)
) %>%
select("PersonalID", "ProjectID", "EnrollmentID") %>%
inner_join(pe_coc_funded, by = "ProjectID") %>%
left_join(Client, by = "PersonalID") %>%
left_join(
Enrollment %>%
select(-UserID,-DateCreated,-DateUpdated,-DateDeleted,-ExportID),
by = c(
"PersonalID",
"EnrollmentID",
"ProjectID",
"ProjectType",
"ProjectName"
)
) %>%
select(all_of(vars_we_want)) %>%
arrange(PersonalID, AltProjectID, desc(EntryDate)) %>%
distinct(PersonalID, AltProjectName, .keep_all = TRUE) # no dupes w/in a project
# increase income
#Adults who moved in and were served during date range
pe_adults_moved_in <- co_adults_moved_in %>%
filter(stayed_between(., ReportStart, ReportEnd)) %>%
select("PersonalID", "ProjectID", "EnrollmentID") %>%
inner_join(pe_coc_funded, by = "ProjectID") %>%
left_join(Client, by = "PersonalID") %>%
left_join(
Enrollment %>%
select(-UserID,-DateCreated,-DateUpdated,-DateDeleted,-ExportID),
by = c(
"PersonalID",
"EnrollmentID",
"ProjectID",
"ProjectType",
"ProjectName"
)
) %>%
select(all_of(vars_we_want)) %>%
arrange(PersonalID, AltProjectID, desc(EntryDate)) %>%
distinct(PersonalID, AltProjectName, .keep_all = TRUE) # no dupes w/in a project
# health insurance
# Clients who moved in and exited during date range
pe_clients_moved_in_leavers <- co_clients_moved_in_leavers %>%
filter(stayed_between(., ReportStart, ReportEnd) &
exited_between(., ReportStart, ReportEnd)) %>%
select("PersonalID", "ProjectID", "EnrollmentID") %>%
inner_join(pe_coc_funded, by = "ProjectID") %>%
left_join(Client, by = "PersonalID") %>%
left_join(
Enrollment %>%
select(-UserID,-DateCreated,-DateUpdated,-DateDeleted,-ExportID),
by = c(
"PersonalID",
"EnrollmentID",
"ProjectID",
"ProjectType",
"ProjectName"
)
) %>%
select(all_of(vars_we_want)) %>%
arrange(PersonalID, AltProjectID, desc(EntryDate)) %>%
distinct(PersonalID, AltProjectName, .keep_all = TRUE) # no dupes w/in a project
# exits to PH, but needs an added filter of only mover-inners
# Heads of Household who were served during date range
pe_hohs_served <- co_hohs_served %>%
filter(served_between(., ReportStart, ReportEnd)) %>%
select("PersonalID", "ProjectID", "EnrollmentID") %>%
inner_join(pe_coc_funded, by = "ProjectID") %>%
left_join(Client, by = "PersonalID") %>%
left_join(
Enrollment %>%
select(-UserID,-DateCreated,-DateUpdated,-DateDeleted,-ExportID),
by = c(
"PersonalID",
"EnrollmentID",
"ProjectID",
"ProjectType",
"ProjectName"
)
) %>%
select(all_of(vars_we_want)) %>%
arrange(PersonalID, AltProjectID, desc(EntryDate)) %>%
distinct(PersonalID, AltProjectName, .keep_all = TRUE) # no dupes w/in a project
pe_hohs_served_leavers <- pe_hohs_served %>%
filter(exited_between(., ReportStart, ReportEnd))
# own housing and LoS
# Heads of Household who moved in and exited during date range
pe_hohs_moved_in_leavers <- co_hohs_moved_in_leavers %>%
filter(stayed_between(., ReportStart, ReportEnd) &
exited_between(., ReportStart, ReportEnd)) %>%
select("PersonalID", "ProjectID", "EnrollmentID") %>%
inner_join(pe_coc_funded, by = "ProjectID") %>%
left_join(Client, by = "PersonalID") %>%
left_join(
Enrollment %>%
select(-UserID,-DateCreated,-DateUpdated,-DateDeleted,-ExportID),
by = c(
"PersonalID",
"EnrollmentID",
"ProjectID",
"ProjectType",
"ProjectName"
)
) %>%
select(all_of(vars_we_want)) %>%
arrange(PersonalID, AltProjectID, desc(EntryDate)) %>%
distinct(PersonalID, AltProjectName, .keep_all = TRUE) # no dupes w/in a project
# Create Validation Summary -----------------------------------------------
# summary_pe_[cohort] - takes client-level pe_[cohort], calculates # of total
# clients in the cohort at the alt-project level
summary_pe_hohs_moved_in_leavers <- pe_hohs_moved_in_leavers %>%
group_by(AltProjectID) %>%
summarise(HoHsMovedInLeavers = n()) %>%
ungroup() %>%
right_join(pe_coc_funded["AltProjectID"] %>% unique(), by = "AltProjectID") %>%
mutate(HoHsMovedInLeavers = if_else(is.na(HoHsMovedInLeavers),
as.integer(0),
HoHsMovedInLeavers))
summary_pe_adults_moved_in_leavers <- pe_adults_moved_in_leavers %>%
group_by(AltProjectID) %>%
summarise(AdultMovedInLeavers = n()) %>%
right_join(pe_coc_funded["AltProjectID"] %>% unique(), by = "AltProjectID") %>%
mutate(AdultMovedInLeavers = if_else(is.na(AdultMovedInLeavers),
as.integer(0),
AdultMovedInLeavers))
summary_pe_adults_moved_in <- pe_adults_moved_in %>%
group_by(AltProjectID) %>%
summarise(AdultsMovedIn = n()) %>%
ungroup() %>%
right_join(pe_coc_funded["AltProjectID"] %>% unique(), by = "AltProjectID") %>%
mutate(AdultsMovedIn = if_else(is.na(AdultsMovedIn),
as.integer(0),
AdultsMovedIn))
summary_pe_clients_moved_in_leavers <- pe_clients_moved_in_leavers %>%
group_by(AltProjectID) %>%
summarise(ClientsMovedInLeavers = n()) %>%
ungroup() %>%
right_join(pe_coc_funded["AltProjectID"] %>% unique(), by = "AltProjectID") %>%
mutate(ClientsMovedInLeavers = if_else(is.na(ClientsMovedInLeavers),
as.integer(0),
ClientsMovedInLeavers))
summary_pe_hohs_served <- pe_hohs_served %>%
group_by(AltProjectID) %>%
summarise(HoHsServed = n()) %>%
ungroup() %>%
right_join(pe_coc_funded["AltProjectID"] %>% unique(), by = "AltProjectID") %>%
mutate(HoHsServed = if_else(is.na(HoHsServed),
as.integer(0),
HoHsServed))
summary_pe_hohs_served_leavers <- pe_hohs_served_leavers %>%
group_by(AltProjectID) %>%
summarise(HoHsServedLeavers = n()) %>%
ungroup() %>%
right_join(pe_coc_funded["AltProjectID"] %>% unique(), by = "AltProjectID") %>%
mutate(HoHsServedLeavers = if_else(is.na(HoHsServedLeavers),
as.integer(0),
HoHsServedLeavers))
summary_pe_clients_served <- pe_clients_served %>%
group_by(AltProjectID) %>%
summarise(ClientsServed = n()) %>%
ungroup() %>%
right_join(pe_coc_funded["AltProjectID"] %>% unique(), by = "AltProjectID") %>%
mutate(ClientsServed = if_else(is.na(ClientsServed),
as.integer(0),
ClientsServed))
summary_pe_adults_entered <- pe_adults_entered %>%
group_by(AltProjectID) %>%
summarise(AdultsEntered = n()) %>%
ungroup() %>%
right_join(pe_coc_funded["AltProjectID"] %>% unique(), by = "AltProjectID") %>%
mutate(AdultsEntered = if_else(is.na(AdultsEntered),
as.integer(0),
AdultsEntered))
summary_pe_hohs_entered <- pe_hohs_entered %>%
group_by(AltProjectID) %>%
summarise(HoHsEntered = n()) %>%
ungroup() %>%
right_join(pe_coc_funded["AltProjectID"] %>% unique(), by = "AltProjectID") %>%
mutate(HoHsEntered = if_else(is.na(HoHsEntered),
as.integer(0),
HoHsEntered))
# joins all summary_pe_[cohort]s into one object so now you have all the cohort
# totals at the alt-project level
pe_validation_summary <- summary_pe_adults_entered %>%
full_join(summary_pe_adults_moved_in, by = "AltProjectID") %>%
full_join(summary_pe_hohs_served_leavers, by = "AltProjectID") %>%
full_join(summary_pe_adults_moved_in_leavers, by = "AltProjectID") %>%
full_join(summary_pe_clients_served, by = "AltProjectID") %>%
full_join(summary_pe_clients_moved_in_leavers, by = "AltProjectID") %>%
full_join(summary_pe_hohs_moved_in_leavers, by = "AltProjectID") %>%
full_join(summary_pe_hohs_served, by = "AltProjectID") %>%
full_join(summary_pe_hohs_entered, by = "AltProjectID") %>%
left_join(pe_coc_funded %>%
select(AltProjectID, ProjectType, AltProjectName) %>%
unique(), by = c("AltProjectID")) %>%
left_join(hoh_exits_to_deceased, by = "AltProjectID") %>%
select(
ProjectType,
AltProjectID,
AltProjectName,
ClientsServed,
HoHsEntered,
HoHsServed,
HoHsServedLeavers,
HoHDeaths,
AdultsMovedIn,
AdultsEntered,
ClientsMovedInLeavers,
AdultMovedInLeavers,
HoHsMovedInLeavers
)
rm(list = ls(pattern = "summary_"))
# Finalizing DQ Flags -----------------------------------------------------
# calculates how many clients have a qualifying error of whatever type. only
# returns the providers with any qualifying errors.
dq_flags_staging <- dq_2019 %>%
right_join(pe_coc_funded, by = c("ProjectType", "ProjectID", "ProjectName")) %>%
mutate(
GeneralFlag =
if_else(
Issue %in% c(
"Duplicate Entry Exits",
"Incorrect Entry Exit Type",
"Children Only Household",
"No Head of Household",
"Too Many Heads of Household"
),
1,
0
),
BenefitsFlag =
if_else(
Issue %in% c(
"Non-cash Benefits Missing at Entry",
"Conflicting Non-cash Benefits yes/no at Entry"
),
1,
0
),
IncomeFlag =
if_else(
Issue %in% c("Income Missing at Entry",
"Conflicting Income yes/no at Entry"),
1,
0
),
LoTHFlag =
if_else(
Issue %in% c("Missing Residence Prior",
"Missing Months or Times Homeless"),
1,
0
)
) %>%
select(AltProjectName,
PersonalID,
HouseholdID,
GeneralFlag,
BenefitsFlag,
IncomeFlag,
LoTHFlag) %>%
filter(
GeneralFlag + BenefitsFlag + IncomeFlag + LoTHFlag > 0
) %>%
group_by(AltProjectName) %>%
summarise(GeneralFlagTotal = sum(GeneralFlag),
BenefitsFlagTotal = sum(BenefitsFlag),
IncomeFlagTotal = sum(IncomeFlag),
LoTHFlagTotal = sum(LoTHFlag))
# calculates whether the # of errors of whatever type actually throws a flag.
# includes all alt-projects regardless of if they have errors
data_quality_flags_detail <- pe_validation_summary %>%
left_join(dq_flags_staging, by = "AltProjectName") %>%
mutate(General_DQ = if_else(GeneralFlagTotal/ClientsServed >= .02, 1, 0),
Benefits_DQ = if_else(BenefitsFlagTotal/AdultsEntered >= .02, 1, 0),
Income_DQ = if_else(IncomeFlagTotal/AdultsEntered >= .02, 1, 0),
LoTH_DQ = if_else(LoTHFlagTotal/HoHsServed >= .02, 1, 0))
data_quality_flags_detail[is.na(data_quality_flags_detail)] <- 0
# writing out a file to help notify flagged projects toward end of process
users_eda_groups <- read_xlsx("data/RMisc2.xlsx",
sheet = 15) %>%
select(UserID, UserEmail, EDAGroupID)
eda_groups_providers <- read_xlsx("data/RMisc2.xlsx",
sheet = 16) %>%
select(ProjectID, EDAGroupID)
providers_users <- users_eda_groups %>%
left_join(eda_groups_providers, by = "EDAGroupID") %>%
filter(!is.na(ProjectID) &
!UserID %in% c(COHHIO_admin_user_ids))
notify_about_dq <- data_quality_flags_detail %>%
filter(GeneralFlagTotal > 0 |
BenefitsFlagTotal > 0 |
IncomeFlagTotal > 0 |
LoTHFlagTotal > 0) %>%
left_join(consolidations %>%
select(ProjectID, AltProjectID), by = "AltProjectID") %>%
mutate(ProjectID = if_else(is.na(ProjectID), AltProjectID, ProjectID)) %>%
left_join(providers_users, by = "ProjectID")
write_csv(notify_about_dq, "Reports/notify.csv")
# this file ^^ is used by Reports/CoC_Competition/Notify_DQ.Rmd to produce
# emails to all users attached to any of the providers with DQ flags.
# displays flags thrown at the alt-project level
data_quality_flags <- data_quality_flags_detail %>%
select(AltProjectName, General_DQ, Benefits_DQ, Income_DQ, LoTH_DQ)
# CoC Scoring -------------------------------------------------------------
docs_due <- mdy("04012020")
lower_th <- 6000
upper_th <- 10000
lower_psh_sh <- 8000
upper_psh_sh <- 12000
lower_rrh <- 5000
upper_rrh <- 9000
summary_pe_coc_scoring <- pe_coc_funded %>%
left_join(Project, by = c("ProjectType", "ProjectName", "ProjectID")) %>%
select(
ProjectType,
ProjectID,
AltProjectID,
AltProjectName,
CostPerExit,
DateReceivedPPDocs,
HousingFirstScore,
ChronicPrioritizationScore,
OnTrackSpendingScoring,
UnspentFundsScoring
) %>%
filter(!ProjectID %in% retired) %>%
mutate(
CostPerExitScore = case_when(
(ProjectType == 2 &
CostPerExit <= lower_th) |
(ProjectType %in% c(3, 8) &
CostPerExit <= lower_psh_sh) |
(ProjectType == 13 &
CostPerExit <= lower_rrh) ~ 0, # would be 5 but covid19
(ProjectType == 2 &
CostPerExit > lower_th &
CostPerExit <= upper_th) |
(
ProjectType %in% c(3, 8) &
CostPerExit > lower_psh_sh &
CostPerExit <= upper_psh_sh
) |
(
ProjectType == 13 &
CostPerExit > lower_rrh &
CostPerExit <= upper_rrh
) ~ 0, # would be 2 but covid19
(ProjectType == 2 &
CostPerExit > upper_th) |
(ProjectType %in% c(3, 8) &
CostPerExit > upper_psh_sh) |
(ProjectType == 13 &
CostPerExit > upper_rrh) ~ 0 # <- naturally zero!
),
CostPerExitPossible = 0, # would be 5, but virus
CostPerExitMath = "NOT SCORED in 2020 due to COVID-19.",
OnTrackSpendingPossible = 0, # would be 5, but virus
OnTrackSpendingMath = "NOT SCORED in 2020 due to COVID-19.",
UnspentFundsPossible = 0, # would be 5, but virus
UnspentFundsMath = "NOT SCORED in 2020 due to COVID-19.",
HousingFirstPossible = 0, # would be 15, but virus
HousingFirstDQ = case_when(
ymd(DateReceivedPPDocs) <= ymd(docs_due) &
is.na(HousingFirstScore) ~ 3,
is.na(DateReceivedPPDocs) &
is.na(HousingFirstScore) ~ 2,
is.na(DateReceivedPPDocs) &
!is.na(HousingFirstScore) ~ 4,
ymd(DateReceivedPPDocs) > ymd(docs_due) ~ 5
),
HousingFirstScore = 0,
# case_when(
# ymd(DateReceivedPPDocs) <= ymd(docs_due) &
# !is.na(HousingFirstScore) ~ HousingFirstScore,
# is.na(DateReceivedPPDocs) &
# is.na(HousingFirstScore) ~ -10L,
# ymd(DateReceivedPPDocs) > ymd(docs_due) ~ -10L
# ), # commented out due to covid19
HousingFirstMath = "NOT SCORED in 2020 due to COVID-19.",
ChronicPrioritizationDQ = case_when(
ymd(DateReceivedPPDocs) <= ymd(docs_due) &
is.na(ChronicPrioritizationScore) ~ 3,
is.na(DateReceivedPPDocs) &
is.na(ChronicPrioritizationScore) ~ 2,
is.na(DateReceivedPPDocs) &
!is.na(ChronicPrioritizationScore) ~ 4,
ymd(DateReceivedPPDocs) > ymd(docs_due) ~ 5
),
ChronicPrioritizationPossible = if_else(ProjectType == 3, 0, NULL),
# true would be 10, but virus
ChronicPrioritizationScore = if_else(ProjectType == 3, 0, NULL),
# case_when(
# ymd(DateReceivedPPDocs) <= ymd(docs_due) &
# ProjectType == 3 &
# !is.na(ChronicPrioritizationScore) ~ ChronicPrioritizationScore,
# is.na(DateReceivedPPDocs) &
# ProjectType == 3 &
# is.na(ChronicPrioritizationScore) ~ -5L,
# ymd(DateReceivedPPDocs) > ymd(docs_due) &
# ProjectType == 3 ~ -5L
# ), # commented out due to covid19
ChronicPrioritizationMath = "NOT SCORED in 2020 due to COVID-19."
)
# 2 = Documents not yet received
# 3 = Docs received, not yet scored
# 4 = CoC Error
# 5 = Docs received past the due date
# Housing Stability: Exits to PH ------------------------------------------
# pe_[measure] - client-level dataset of all clients counted in the measure
# along with whether each one meets the objective
# summary_pe_[measure] - uses pe_[measure] to smush to alt-project level and
# adds a score
# PSH (includes stayers tho), TH, SH, RRH
pe_exits_to_ph <- pe_hohs_served %>%
right_join(pe_coc_funded %>%
select(ProjectType, AltProjectID, AltProjectName) %>%
unique(),
by = c("AltProjectName", "ProjectType", "AltProjectID")) %>%
left_join(data_quality_flags, by = "AltProjectName") %>%
mutate(
DestinationGroup = case_when(
is.na(Destination) | ymd(ExitAdjust) > mdy(ReportEnd) ~
"Still in Program at Report End Date",
Destination %in% c(temp_destinations) ~ "Temporary",
Destination %in% c(perm_destinations) ~ "Permanent",
Destination %in% c(institutional_destinations) ~ "Institutional",
Destination == 24 ~ "Deceased (not counted)",
Destination %in% c(other_destinations) ~ "Other"
),
ExitsToPHDQ = case_when(
General_DQ == 1 ~ 1,
TRUE ~ 0
),
MeetsObjective =
case_when(
ProjectType %in% c(3, 9) &
DestinationGroup %in% c("Permanent", "Still in Program at Report End Date") ~ 1,
ProjectType %in% c(3, 9) &
(!DestinationGroup %in% c("Permanent", "Still in Program at Report End Date")) ~ 0,
ProjectType %in% c(2, 8, 13) &
DestinationGroup == "Permanent" ~ 1,
ProjectType %in% c(2, 8, 13) &
(DestinationGroup != "Permanent") ~ 0
),
PersonalID = as.character(PersonalID)
) %>%
filter((ProjectType %in% c(2, 8, 13) &
exited_between(., ReportStart, ReportEnd)) |
ProjectType == 3) %>% # filtering out non-PSH stayers
select(all_of(vars_to_the_apps), ExitsToPHDQ, Destination, DestinationGroup)
summary_pe_exits_to_ph <- pe_exits_to_ph %>%
group_by(ProjectType, AltProjectName, ExitsToPHDQ) %>%
summarise(ExitsToPH = sum(MeetsObjective)) %>%
ungroup() %>%
right_join(pe_validation_summary, by = c("ProjectType", "AltProjectName")) %>%
mutate(
ExitsToPHCohort = if_else(ProjectType == 3, "HoHsServed", "HoHsServedLeavers"),
HoHsServedLeavers = HoHsServedLeavers - HoHDeaths,
HoHsServed = HoHsServed - HoHDeaths,
ExitsToPH = if_else(is.na(ExitsToPH), 0, ExitsToPH),
Structure = case_when(
ProjectType == 3 ~ "80_90_12",
ProjectType %in% c(2, 13) ~ "75_83_10",
ProjectType == 8 ~ "67_75_10"
),
ExitsToPHPercent = if_else(
ProjectType == 3,
ExitsToPH / HoHsServed,
ExitsToPH / HoHsServedLeavers
),
ExitsToPHMath = case_when(
ProjectType == 3 & HoHsServed != 0 ~
paste(
ExitsToPH,
"exits to permanent housing or retention in PSH /",
HoHsServed,
"heads of household =",
percent(ExitsToPHPercent, accuracy = 1)
),
ProjectType != 3 & HoHsServedLeavers != 0 ~
paste(
ExitsToPH,
"exits to permanent housing /",
HoHsServedLeavers,
"heads of household leavers =",
percent(ExitsToPHPercent, accuracy = 1)
)
),
ExitsToPHPoints = if_else(
(ProjectType == 3 &
HoHsServed == 0) |
(ProjectType != 3 &
HoHsServedLeavers == 0),
if_else(ProjectType == 3, 12, 10),
pe_score(Structure, ExitsToPHPercent)
),
ExitsToPHPossible = if_else(ProjectType == 3, 12, 10),
ExitsToPHPoints = if_else(
ExitsToPHDQ == 0 | is.na(ExitsToPHDQ),
ExitsToPHPoints,
0
)
) %>%
select(
ProjectType,
AltProjectName,
ExitsToPH,
ExitsToPHMath,
ExitsToPHPercent,
ExitsToPHPoints,
ExitsToPHPossible,
ExitsToPHDQ,
ExitsToPHCohort
)
# Housing Stability: Moved into Own Housing -------------------------------
# TH, SH, RRH
pe_own_housing <- pe_hohs_moved_in_leavers %>%
right_join(pe_coc_funded %>%
select(ProjectType, AltProjectID, AltProjectName) %>%
unique(),
by = c("AltProjectName", "ProjectType", "AltProjectID")) %>%
left_join(data_quality_flags, by = "AltProjectName") %>%
filter(ProjectType != 3) %>%
mutate(
MeetsObjective = case_when(
Destination %in% c(3, 10:11, 19:21, 28, 31, 33:34) ~ 1,
!Destination %in% c(3, 10:11, 19:21, 28, 31, 33:34) ~ 0
),
OwnHousingDQ = case_when(
General_DQ == 1 ~ 1,
TRUE ~ 0
),
DestinationGroup = case_when(
is.na(Destination) | ymd(ExitAdjust) > mdy(ReportEnd) ~
"Still in Program at Report End Date",
Destination %in% c(1, 2, 12, 13, 14, 16, 18, 27) ~ "Temporary",
Destination %in% c(3, 10:11, 19:21, 28, 31, 33:34) ~ "Household's Own Housing",
Destination %in% c(22:23) ~ "Shared Housing",
Destination %in% c(4:7, 15, 25:27, 29) ~ "Institutional",
Destination %in% c(8, 9, 17, 30, 99, 32) ~ "Other",
Destination == 24 ~ "Deceased"
),
PersonalID = as.character(PersonalID)
) %>%
select(all_of(vars_to_the_apps), OwnHousingDQ, Destination, DestinationGroup)
summary_pe_own_housing <- pe_own_housing %>%
group_by(ProjectType, AltProjectName, OwnHousingDQ) %>%
summarise(OwnHousing = sum(MeetsObjective)) %>%
ungroup() %>%
right_join(pe_validation_summary, by = c("ProjectType", "AltProjectName")) %>%
mutate(
HoHsMovedInLeavers = HoHsMovedInLeavers - HoHDeaths,
OwnHousing = if_else(is.na(OwnHousing), 0, OwnHousing),
Structure = if_else(ProjectType != 3, "72_80_5", NULL),
OwnHousingPercent = if_else(ProjectType != 3,
OwnHousing / HoHsMovedInLeavers,
NULL),
OwnHousingMath = case_when(
HoHsMovedInLeavers == 0 &
ProjectType != 3 ~
"All points granted because this project had 0 Heads of Household Leavers who Moved into Housing",
ProjectType == 3 &
(HoHsMovedInLeavers == 0 | HoHsMovedInLeavers != 0) ~ "",
HoHsMovedInLeavers != 0 & ProjectType != 3 ~ paste(
OwnHousing,
"exited to their own permanent housing /",
HoHsMovedInLeavers,
"heads of household leavers who moved into housing =",
percent(OwnHousingPercent, accuracy = 1)
)
),
OwnHousingPoints = if_else(
HoHsMovedInLeavers == 0 & ProjectType != 3,
10,
pe_score(Structure, OwnHousingPercent)
),
OwnHousingPoints = if_else(is.nan(OwnHousingPercent) &
ProjectType != 3, 5, OwnHousingPoints),
OwnHousingPoints = case_when(OwnHousingDQ == 1 ~ 0,
is.na(OwnHousingDQ) |
OwnHousingDQ == 0 ~ OwnHousingPoints),
OwnHousingPoints = if_else(is.na(OwnHousingPoints), 0, OwnHousingPoints),
OwnHousingPossible = if_else(ProjectType != 3, 5, NULL),
OwnHousingCohort = "HoHsMovedInLeavers"
) %>%
select(ProjectType,
AltProjectName,
OwnHousingCohort,
OwnHousing,
OwnHousingMath,
OwnHousingPercent,
OwnHousingPoints,