-
Notifications
You must be signed in to change notification settings - Fork 5
/
02_QPR_SPDATs.R
165 lines (150 loc) · 5.6 KB
/
02_QPR_SPDATs.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
# 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/>.
# this script uses the COHHIOHMIS data to compare the avg SPDAT score of
# clients served in a county during the reporting period to the avg
# SPDAt score of those who enrolled into a PSH or RRH project during the
# reporting period.
library(tidyverse)
library(lubridate)
library(janitor)
library(HMIS)
# loading the COHHIOHMIS data, dropping unnecessary objects
if (!exists("Enrollment")) {
load("images/COHHIOHMIS.RData")
# rlang::env_binding_lock(environment(), ls())
}
# more paring down, only taking what variables I need from Enrollment
smallEnrollment <- Enrollment %>%
left_join(Project, by = c("ProjectType", "ProjectID", "ProjectName")) %>%
select(
EnrollmentID,
PersonalID,
ProjectID,
ProjectType,
ProjectName,
OperatingStartDate,
OperatingEndDate,
EntryDate,
ExitDate,
RelationshipToHoH,
CountyServed
)
# Entries will give us all the times a hh has an Entry into a PH project
Entries <- smallEnrollment %>%
filter(ProjectType %in% c(3, 9, 13))
note_qpr_served_county <- "The horizontal lines represent the average scores of Heads
of Household who were served in the County in a ES, TH, SH, or Outreach project
during the reporting period and who were scored. If a Head of Household was
served in a County outside the Balance of State or if that data was missing,
they are not being counted. When there are multiple project entries for the same
client, this only counts the most recent entry. When there are multiple scores,
this only counts the most recent score. There should not be more than 1 score on
the same day, but if there are it is counting the highest score."
# this object is used in the app to create the plot. it has date variables
# included so the numbers can be filtered by date range in the app. it takes
# long to run.
qpr_spdats_county <-
left_join(smallEnrollment, Scores, by = "PersonalID") %>%
filter(
ProjectType %in% c(1, 2, 4, 8) &
RelationshipToHoH == 1 &
ymd(ScoreDate) <= ymd(EntryDate) &
!CountyServed %in% c(
"Montgomery",
"Cuyahoga",
"Mahoning",
"Lucas",
"Stark",
"Summit",
"Hamilton",
"Franklin",
"--Outside of Ohio--"
) &
!is.na(CountyServed)
) %>%
select(
EnrollmentID,
PersonalID,
ProjectName,
EntryDate,
ExitDate,
CountyServed,
ScoreDate,
Score
) %>%
group_by(PersonalID) %>%
slice_max(ymd(EntryDate)) %>% # most recent EE
slice_max(ymd(ScoreDate)) %>% # most recent score
slice_max(Score) %>% # highest score
ungroup() %>%
select(PersonalID,
ProjectName,
CountyServed,
Score,
EntryDate,
ExitDate)
note_qpr_housed_county <- "The triangle represents the average score of each
household entering into a permanent housing project in a County during the
reporting period. This will necessarily leave out households coming from
Domestic Violence shelters since they are not scored. Any Heads of Household
who entered a permanent housing project without a score will be counted as
having a score of 0."
note_qpr_dq_community_need <- "It is very important that your Duplicate Entry Exits and your
Household Data Quality tabs are totally clear for this report to be accurate.
It is also important that your VI-SPDAT scores are ON THE HEAD OF HOUSEHOLD'S
RECORD. Any scores recorded on non-HoHs will not be counted here. Also if a
HoH is missing their County data or they were served in a County outside the
Ohio Balance of State, they will also not show here."
# this pulls all entries into PSH or RRH
qpr_spdats_project <- left_join(Entries, Scores, by = "PersonalID") %>%
select(-ProjectType,
-OperatingStartDate,
-OperatingEndDate) %>%
filter(
RelationshipToHoH == 1 &
(ymd(ScoreDate) <= ymd(EntryDate) | is.na(ScoreDate)) &
!CountyServed %in% c(
"Montgomery",
"Cuyahoga",
"Mahoning",
"Lucas",
"Stark",
"Summit",
"Hamilton",
"Franklin",
"--Outside of Ohio--"
) &
!is.na(CountyServed)
) %>%
mutate(
ScoreAdjusted = if_else(is.na(Score), 0, Score),
ScoreDateAdjusted = if_else(is.na(ScoreDate), today(), ScoreDate)
) %>%
group_by(EnrollmentID) %>%
slice_max(ymd(ScoreDateAdjusted)) %>%
slice_max(ScoreAdjusted) %>%
distinct() %>%
ungroup() %>%
select(-ScoreDateAdjusted)
# If you have clients here, you should either verify the scores saved here are
# valid or the correct client is marked as the Head of Household.
SPDATsOnNonHoHs <- left_join(Entries, Scores, by = "PersonalID") %>%
filter(RelationshipToHoH != 1 &
!is.na(Score) &
served_between(., ymd(calc_data_goes_back_to), ymd(meta_HUDCSV_Export_End))) %>%
select(ProjectName, PersonalID, EntryDate, ExitDate, Score) %>%
arrange(ProjectName)
rm(Entries, smallEnrollment, SPDATsOnNonHoHs)
# WARNING save.image does not save the environment properly, save must be used.
save(list = ls(), file = "images/QPR_SPDATs.RData", compress = FALSE)