Newer
Older
p2_targets <- list(
# Confirming raw data matches `p1_unc_stats` from SB
tar_target(p2_unc_agg_summary,
summarize(across(c(contains('related'),
contains('unknown'),
contains('significant')),
list(total = ~sum(.x, na.rm=TRUE)))) |>
mutate(evidence_val = positively_related_total + negatively_related_total +
unrelated_total + unknown_direction_total)
),
# Based on metadata:
# Amt of evidence: Small = total_studies < 5; Medium = total_studies 5-9; Large,total_studies = > 9
# Amt of agreement: Low = < 50% of models; Medium = >50% & <74% of models; High = >74% of models; NA if the level of agreement could not be calculated as indicator was measured only once.
tar_target(p2_top_trend_stats,
p2_unc_agg_summary |>
positively_related_total, negatively_related_total, unrelated_total,
unknown_direction_total) |>
pivot_longer(!c(dimension,determinant)) |>
group_by(dimension, determinant) |>
# for each indicator find the maximum % of studies in agreement
# across the significance categories.
slice_max(value) |>
rename(sig_name = name, sig_value = value)
),
# Join `p2_unc_agg_summary` to top trends to get percentages of agreement and evidence
p2_unc_agg_summary |>
left_join(p2_top_trend_stats) |>
# level of agreement is the max percent of studies in agreement
dplyr::mutate(level_agreement = 100*(sig_value/evidence_val)) |>
readr::write_csv('2_process/out/indicator_uncertainty.csv')
tar_target(p2_indicators,
p1_unc_stats |>
distinct(dimension, determinant, indicator)
),
# Process census data for variables of interest
# B01003_001 = Total Population
# B19013_001 = Median Household Income in the Past 12 Months (in 2022 Inflation-Adjusted Dollars)
# B02001_003 = Estimate!!Total:!!Black or African American alone
# B03001_003 = Estimate!!Total:!!Hispanic or Latino:
# B01001_002 = Estimate!!Total:!!Male:
# B01001_026 = Estimate!!Total:!!Female:
tar_target(p2_census_layers,
list("B01003_001", "B19013_001", "B02001_003",
"B03001_003", "B01001_002", "B01001_026")
),
tar_target(p2_census_data,
get_census_data(geography = 'county', variable = p2_census_layers,
states = p1_census_states, year = 2022, proj = p1_proj),
pattern = map(p2_census_layers),
iteration = "list"
),
p2_census_data[[1]] |>
st_drop_geometry() |>
# Add % of total population col to each census layer
tar_target(p2_perc_census_layers_sf,
process_perc(tot_var = p2_census_data,
tot_pop = p2_tot_pop),
pattern = map(p2_census_data),
iteration = "list")