forked from alexsingleton/Output_Area_Classification
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDescriptions.R
More file actions
175 lines (119 loc) · 5.1 KB
/
Descriptions.R
File metadata and controls
175 lines (119 loc) · 5.1 KB
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
# ░▒▓██████▓▒░ ░▒▓██████▓▒░ ░▒▓██████▓▒░
# ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
# ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
# ░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░▒▓█▓▒░
# ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░
# ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
# ░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░
#
#
#
###############################################################################
# This code was created to describe the final version of the UK Output
# Area Classification
# Created by the Geographic Data Service:
# Alex Singleton, University of Liverpool
# Owen Goodwin, University of Liverpool
# Paul Longley, University College London
###############################################################################
############################################################
# Create Descriptive Material
############################################################
library(tidyverse)
library(arrow)
library(magrittr)
library(janitor)
# Import variables lookup - This table contains all the variables used in OAC 2021
variable_lookup <- read_csv("./data/lookup/Variables_OAC.csv")
# Read input data and lookups
OAC_Input <- read_parquet("./data/OAC_Input.parquet")
UK_OAC_Preview <- read_csv("./data/UKOAC/UKOAC21_assignment.csv",col_types = cols(.default = "c"))
UK_OAC_Preview %<>%
rename( OA = Geography_Code)
UK_OAC_Final <- read_parquet("./data/UK_OAC_Final.parquet")
UK_OAC_Final %<>%
rename( OA = Geography_Code)
# Append Clusters
preview_OAC <- OAC_Input %>%
left_join(UK_OAC_Preview)
final_OAC <- OAC_Input %>%
left_join(UK_OAC_Final)
# Final OAC
# Calculate Index Scores and transpose Subgroup
IS_Final_Subgroup <- final_OAC %>%
group_by(Subgroup) %>%
summarise(across(where(is.numeric), \(x) mean(x, na.rm = TRUE))) %>%
ungroup() %>%
mutate(across(where(is.numeric), \(x) x / mean(x, na.rm = TRUE) * 100)) # index score
IS_Final_Subgroup %<>%
pivot_longer(-Subgroup, names_to = "no", values_to = "Value") %>%
pivot_wider(names_from = Subgroup, values_from = Value)
# Append variable names
Index_Scores_Final_Subgroups <- variable_lookup %>%
clean_names() %>%
select(no, variable_name,domain) %>%
left_join(IS_Final_Subgroup)
# Calculate Index Scores and transpose Group
IS_Final_Group <- final_OAC %>%
group_by(Group) %>%
summarise(across(where(is.numeric), \(x) mean(x, na.rm = TRUE))) %>%
ungroup() %>%
mutate(across(where(is.numeric), \(x) x / mean(x, na.rm = TRUE) * 100)) # index score
IS_Final_Group %<>%
pivot_longer(-Group, names_to = "no", values_to = "Value") %>%
pivot_wider(names_from = Group, values_from = Value)
# Append variable names
Index_Scores_Final_Groups <- variable_lookup %>%
clean_names() %>%
select(no, variable_name,domain) %>%
left_join(IS_Final_Group)
write_csv(Index_Scores_Final_Groups,"Index_Scores_Final_Groups.csv")
# Calculate Index Scores and transpose Supergroup
IS_Final_Supergroup <- final_OAC %>%
group_by(Supergroup) %>%
summarise(across(where(is.numeric), \(x) mean(x, na.rm = TRUE))) %>%
ungroup() %>%
mutate(across(where(is.numeric), \(x) x / mean(x, na.rm = TRUE) * 100)) # index score
IS_Final_Supergroup %<>%
pivot_longer(-Supergroup, names_to = "no", values_to = "Value") %>%
pivot_wider(names_from = Supergroup, values_from = Value)
# Append variable names
Index_Scores_Final_Supergroup <- variable_lookup %>%
clean_names() %>%
select(no, variable_name,domain) %>%
left_join(IS_Final_Supergroup)
write_csv(Index_Scores_Final_Supergroup,"Index_Scores_Final_Supergroup.csv")
################################
# Comparison Table #############
################################
# LAD Counts
# This requires the ONSPD (https://geoportal.statistics.gov.uk/datasets/b54177d3d7264cd6ad89e74dd9c1391d/about)
ONSPD <- read_csv("ONSPD_NOV_2024_UK.csv")
ONSPD %<>%
select(oa21, oslaua) %>%
filter(! oa21 %in% c("L99999999","M99999999")) %>%
filter(! is.na(oa21)) %>%
rename(OA = oa21) %>%
left_join(UK_OAC_Final)
LAD_Frq <- ONSPD %>%
group_by(Subgroup) %>%
summarise(
distinct_oslaua = n_distinct(oslaua)
)
# OA and Population Counts
Pop_UK <- read_parquet("./data/Pop_UK.parquet")
Pop_UK <- UK_OAC_Final %>%
left_join(Pop_UK)
Pop_UK %<>%
group_by(Subgroup) %>%
summarise(
count_OA = n(),
sum_pop = sum(tot_pop)
) %>%
mutate(
pct_OA = 100 * count_OA / sum(count_OA),
pct_pop = 100 * sum_pop / sum(sum_pop)
)
descriptive_stats <- LAD_Frq %>%
left_join(Pop_UK)
write_csv(descriptive_stats,"./data/descriptive_stats.csv")