Using current master; d29cd9b.
I'm actually not using mhq_terr_assessments directly, since I understood that mhq_terr_popunits already builds on it. But as there seems to be separate information about replacement in mhq_terr_assessments, I wanted to do a quick check of that.
Code to reproduce objects
> mhq_terr_datapath <- file.path(dirname(gitroot), "n2khab-sample-admin/data/mhq_terr/rapportage2025")
>
> mhq_terr_popunits <-
read_vc("mhq_terr_popunits", root = mhq_terr_datapath) %>%
as_tibble()
>
> mhq_terr_assessments <-
read_vc("mhq_terr_assessments", root = mhq_terr_datapath) %>%
as_tibble()
According to METADATA.md, regarding the mhq_terr_assessments data source:
change_location: has the population unit been replaced? (TRUE/FALSE)
My assumptions:
change_location refers to a local replacement
- local replacements in
mhq_terr_popunits are reflected by grts_ranking_draw != grts_ranking, as told. This is reflected by local_replacement in below output.
While looking only at mhq_terr_popunits units that have been assessed (according to source), it can be seen that corresponding locations in mhq_terr_assessments have a number of contradictions between change_location and local_replacement.
> assessment_replacement <-
mhq_terr_assessments %>%
select(assessment_date, point_code, type, is_present, change_location) %>%
inner_join(
mhq_terr_popunits %>%
filter(str_detect(source, "assessment")) %>%
select(point_code, grts_ranking, grts_ranking_draw, type),
join_by(point_code, type),
relationship = "many-to-one",
unmatched = c("drop", "error")
) %>%
mutate(local_replacement = grts_ranking != grts_ranking_draw) %>%
relocate(local_replacement, .before = grts_ranking)
>
> assessment_replacement %>%
count(is_present, change_location, local_replacement) %>%
filter(change_location != local_replacement)
# A tibble: 4 × 4
is_present change_location local_replacement n
<lgl> <lgl> <lgl> <int>
1 FALSE FALSE TRUE 2
2 TRUE FALSE TRUE 249
3 TRUE TRUE FALSE 156
4 NA FALSE TRUE 2
Given these numbers, I'm probably missing something. Maybe it has to do with revisits of the same location; below code may help to investigate all assessments of the involved locations. But as said, I'm not relying on mhq_terr_assessments (with change_location), only on mhq_terr_popunits.
> assessment_replacement %>%
filter(change_location != local_replacement) %>%
semi_join(assessment_replacement, ., join_by(point_code)) %>%
arrange(grts_ranking, grts_ranking_draw, type, point_code) %>%
print(n = 25)
# A tibble: 541 × 8
assessment_date point_code type is_present change_location local_replacement grts_ranking grts_ranking_draw
<date> <chr> <chr> <lgl> <lgl> <lgl> <dbl> <dbl>
1 2015-04-20 3894_2 9120 TRUE TRUE FALSE 3894 3894
2 2017-04-21 4945_2 9130_end TRUE TRUE FALSE 4945 4945
3 2018-06-22 12710_2 9120 TRUE TRUE FALSE 12710 12710
4 2014-06-05 18546_2 6510_hu TRUE TRUE FALSE 18546 18546
5 2020-05-20 18546_2 6510_hu TRUE FALSE FALSE 18546 18546
6 2022-06-09 18546_2 6510_hu TRUE FALSE FALSE 18546 18546
7 2020-07-03 23221_2 2130_hd TRUE TRUE FALSE 23221 23221
8 2015-07-05 23257_2 9130 TRUE TRUE FALSE 23257 23257
9 2018-06-05 23385_2 9130_end TRUE TRUE FALSE 23385 23385
10 2018-06-26 36774_2 9120 TRUE TRUE FALSE 36774 36774
11 2015-08-11 37557_2 1330_hpr TRUE TRUE FALSE 37557 37557
12 2022-09-28 37557_2 1330_hpr NA FALSE FALSE 37557 37557
13 2023-10-12 37557_2 1330_hpr TRUE FALSE FALSE 37557 37557
14 2014-05-30 38545_2 6510_hua TRUE TRUE FALSE 38545 38545
15 2022-05-31 38545_2 6510_hua TRUE FALSE FALSE 38545 38545
16 2014-06-11 41814_2 6510_hu TRUE TRUE FALSE 41814 41814
17 2020-05-13 41814_2 6510_hu TRUE FALSE FALSE 41814 41814
18 2016-06-16 46662_2 6510_hu TRUE TRUE FALSE 46662 46662
19 2014-06-13 47446_2 6510_hu TRUE TRUE FALSE 47446 47446
20 2016-09-05 58433_2 6230_hn TRUE TRUE FALSE 58433 58433
21 2023-07-05 58433_2 6230_hn TRUE FALSE FALSE 58433 58433
22 2014-06-06 63270_2 6510_hu TRUE TRUE FALSE 63270 63270
23 2020-05-13 63270_2 6510_hu TRUE FALSE FALSE 63270 63270
24 2016-06-03 78294_2 6510_hu TRUE TRUE FALSE 78294 78294
25 2024-06-05 78294_2 6510_hu TRUE FALSE FALSE 78294 78294
# ℹ 516 more rows
# ℹ Use `print(n = ...)` to see more rows
Using current
master; d29cd9b.I'm actually not using
mhq_terr_assessmentsdirectly, since I understood thatmhq_terr_popunitsalready builds on it. But as there seems to be separate information about replacement inmhq_terr_assessments, I wanted to do a quick check of that.Code to reproduce objects
According to
METADATA.md, regarding themhq_terr_assessmentsdata source:My assumptions:
change_locationrefers to a local replacementmhq_terr_popunitsare reflected bygrts_ranking_draw != grts_ranking, as told. This is reflected bylocal_replacementin below output.While looking only at
mhq_terr_popunitsunits that have been assessed (according tosource), it can be seen that corresponding locations inmhq_terr_assessmentshave a number of contradictions betweenchange_locationandlocal_replacement.Given these numbers, I'm probably missing something. Maybe it has to do with revisits of the same location; below code may help to investigate all assessments of the involved locations. But as said, I'm not relying on
mhq_terr_assessments(withchange_location), only onmhq_terr_popunits.