Skip to content

Commit 41dcbbe

Browse files
committed
Address PR comments
* Change "overall" to "Overall" in the region metadata. * Delete a comment about dropping missings to reflect new behavior (not dropping missings). * Restore code to drop aggregations where the main value is missing. * Make the state abbreviations in the state_list.csv file all upper case.
1 parent a959082 commit 41dcbbe

File tree

3 files changed

+65
-63
lines changed

3 files changed

+65
-63
lines changed

facebook/delphiFacebook/R/contingency_aggregate.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,6 @@ summarize_aggs <- function(df, crosswalk_data, aggregations, geo_level, params)
264264
}
265265

266266
## Find all unique groups and associated frequencies, saved in column `Freq`.
267-
# Keep rows with missing values initially so that we get the correct column
268-
# names. Explicitly drop groups with missing values in second step.
269267
unique_groups_counts <- as.data.frame(
270268
table(df[, group_vars, with=FALSE], exclude=NULL, dnn=group_vars),
271269
stringsAsFactors=FALSE
@@ -324,6 +322,11 @@ summarize_aggs <- function(df, crosswalk_data, aggregations, geo_level, params)
324322
aggregation <- aggregations$id[row]
325323
group_vars <- aggregations$group_by[[row]]
326324
post_fn <- aggregations$post_fn[[row]]
325+
326+
# Keep only aggregations where the main value, `val`, is present.
327+
dfs_out[[aggregation]] <- dfs_out[[aggregation]][
328+
rowSums(is.na(dfs_out[[aggregation]][, c("val", "sample_size")])) == 0,
329+
]
327330

328331
dfs_out[[aggregation]] <- apply_privacy_censoring(dfs_out[[aggregation]], params)
329332

facebook/delphiFacebook/R/contingency_write.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ write_contingency_tables <- function(data, params, geo_type, groupby_vars)
6565
#' @noRd
6666
add_geo_vars <- function(data, params, geo_type) {
6767

68-
start <- data.frame(
68+
overall <- "Overall"
69+
70+
first <- data.frame(
6971
country = "United States",
7072
ISO_3 = "USA",
7173
GID_0 = "USA"
@@ -74,11 +76,11 @@ add_geo_vars <- function(data, params, geo_type) {
7476
if (geo_type == "nation") {
7577

7678
rest <- data.frame(
77-
region = "overall",
79+
region = overall,
7880
GID_1 = NA_character_,
79-
state = "overall",
81+
state = overall,
8082
state_fips = NA_character_,
81-
county = "overall",
83+
county = overall,
8284
county_fips = NA_character_
8385
)
8486

@@ -92,18 +94,15 @@ add_geo_vars <- function(data, params, geo_type) {
9294
rest <- data.frame(
9395
region = toupper(data$geo_id),
9496
state = toupper(data$geo_id),
95-
county = "overall",
97+
county = overall,
9698
county_fips = NA_character_
9799
)
98100

99-
rest$state <- toupper(rest$state)
100-
states$state <- toupper(states$state)
101-
102101
rest <- left_join(rest, states, by = "state") %>%
103102
select(region, GID_1, state, state_fips, county, county_fips)
104103
}
105104

106-
geo_vars <- bind_cols(start, rest)
105+
geo_vars <- bind_cols(first, rest)
107106

108107
# Insert the geographic variables in place of the "geo_id" variable.
109108
index <- which(names(data) == "geo_id")

facebook/static/state_list.csv

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
state,GID_1,state_fips
2-
"ak","USA.2_1","02"
3-
"al","USA.1_1","01"
4-
"ar","USA.4_1","05"
5-
"az","USA.3_1","04"
6-
"ca","USA.5_1","06"
7-
"co","USA.6_1","08"
8-
"ct","USA.7_1","09"
9-
"dc","USA.9_1","11"
10-
"de","USA.8_1","10"
11-
"fl","USA.10_1","12"
12-
"ga","USA.11_1","13"
13-
"hi","USA.12_1","15"
14-
"ia","USA.16_1","19"
15-
"id","USA.13_1","16"
16-
"il","USA.14_1","17"
17-
"in","USA.15_1","18"
18-
"ks","USA.17_1","20"
19-
"ky","USA.18_1","21"
20-
"la","USA.19_1","22"
21-
"ma","USA.22_1","25"
22-
"md","USA.21_1","24"
23-
"me","USA.20_1","23"
24-
"mi","USA.23_1","26"
25-
"mn","USA.24_1","27"
26-
"mo","USA.26_1","29"
27-
"ms","USA.25_1","28"
28-
"mt","USA.27_1","30"
29-
"nc","USA.34_1","37"
30-
"nd","USA.35_1","38"
31-
"ne","USA.28_1","31"
32-
"nh","USA.30_1","33"
33-
"nj","USA.31_1","34"
34-
"nm","USA.32_1","35"
35-
"nv","USA.29_1","32"
36-
"ny","USA.33_1","36"
37-
"oh","USA.36_1","39"
38-
"ok","USA.37_1","40"
39-
"or","USA.38_1","41"
40-
"pa","USA.39_1","42"
41-
"ri","USA.40_1","44"
42-
"sc","USA.41_1","45"
43-
"sd","USA.42_1","46"
44-
"tn","USA.43_1","47"
45-
"tx","USA.44_1","48"
46-
"ut","USA.45_1","49"
47-
"va","USA.47_1","51"
48-
"vt","USA.46_1","50"
49-
"wa","USA.48_1","53"
50-
"wi","USA.50_1","55"
51-
"wv","USA.49_1","54"
52-
"wy","USA.51_1","56"
1+
"state","GID_1","state_fips"
2+
"AK","USA.2_1","02"
3+
"AL","USA.1_1","01"
4+
"AR","USA.4_1","05"
5+
"AZ","USA.3_1","04"
6+
"CA","USA.5_1","06"
7+
"CO","USA.6_1","08"
8+
"CT","USA.7_1","09"
9+
"DC","USA.9_1","11"
10+
"DE","USA.8_1","10"
11+
"FL","USA.10_1","12"
12+
"GA","USA.11_1","13"
13+
"HI","USA.12_1","15"
14+
"IA","USA.16_1","19"
15+
"ID","USA.13_1","16"
16+
"IL","USA.14_1","17"
17+
"IN","USA.15_1","18"
18+
"KS","USA.17_1","20"
19+
"KY","USA.18_1","21"
20+
"LA","USA.19_1","22"
21+
"MA","USA.22_1","25"
22+
"MD","USA.21_1","24"
23+
"ME","USA.20_1","23"
24+
"MI","USA.23_1","26"
25+
"MN","USA.24_1","27"
26+
"MO","USA.26_1","29"
27+
"MS","USA.25_1","28"
28+
"MT","USA.27_1","30"
29+
"NC","USA.34_1","37"
30+
"ND","USA.35_1","38"
31+
"NE","USA.28_1","31"
32+
"NH","USA.30_1","33"
33+
"NJ","USA.31_1","34"
34+
"NM","USA.32_1","35"
35+
"NV","USA.29_1","32"
36+
"NY","USA.33_1","36"
37+
"OH","USA.36_1","39"
38+
"OK","USA.37_1","40"
39+
"OR","USA.38_1","41"
40+
"PA","USA.39_1","42"
41+
"RI","USA.40_1","44"
42+
"SC","USA.41_1","45"
43+
"SD","USA.42_1","46"
44+
"TN","USA.43_1","47"
45+
"TX","USA.44_1","48"
46+
"UT","USA.45_1","49"
47+
"VA","USA.47_1","51"
48+
"VT","USA.46_1","50"
49+
"WA","USA.48_1","53"
50+
"WI","USA.50_1","55"
51+
"WV","USA.49_1","54"
52+
"WY","USA.51_1","56"

0 commit comments

Comments
 (0)