feat: coverage argument + always-on reporting-coverage metadata (#13)
The Census of Governments is a complete census only in years ending in 2 and
7. Every other year is a sample, and the sample varies enormously. Neither
cog_geographic_rollup() nor cog_peer_compare()/cog_find_peers() had any
concept of "the universe": each summed or labelled whichever govids happened
to have rows and returned that with nothing distinguishing "every government
reported" from "a fifth of them did".
On the bundled fixture, Wisconsin's 608-city universe rolls up 597
governments in FY2012 and 112 in FY2019. The peer side is worse exposure, not
better: a Madison-scale cohort looks stable because Madison is large, while
governments matched to a small target sit in exactly the population band the
sample cycle hits hardest. Chilton's 15-peer cohort reports 15 of 15 in
FY2012 and 3 of 15 in FY2019.
Implements the owner's settled design: coverage = c("all", "census",
"consistent") on all three verbs, defaulting to "all" so nothing currently
calling them changes, PLUS always-on provenance$coverage carrying per-year
n_units_reporting / n_units_expected / is_census_year and
provenance$coverage_mode. cog_explain() prints a "Reporting coverage"
section. The default mode can no longer mislead silently, which is the point
-- using these verbs correctly must not require knowing the survey calendar.
Decisions worth stating:
- n_units_expected is the universe the CALLER named, not the national one.
That is what makes the ratio mean something: "597 of the 608 Wisconsin
cities you asked about". For peers it is the cohort size, counted over
peer rows only -- including the target would inflate every count by one
and make a cohort that has entirely stopped reporting look non-empty.
- The coverage table is built from the REQUESTED years, not the years
present in the result, so a year in which nothing reported still appears
with n_units_reporting = 0. A year that vanishes silently is precisely
the disclosure failure at issue.
- "census" filters years BEFORE the query, and aborts when the range holds
no census year rather than returning an empty result for a query the
caller believes they made.
- "consistent" exempts the peer-comparison target: it is the subject of the
comparison, not a member of the cohort being balanced, and dropping it
would leave nothing to compare. The summary_* quantiles are computed
AFTER the filter so they describe the cohort actually returned.
- is_census_year is documented as a statement about the survey CALENDAR,
never a claim of completeness -- FY1967 is a census year in which only 97
of Wisconsin's 608 cities report (DoD 3). n_units_reporting is the number
that tells the truth.
On cog_find_peers(), where there is no year range, coverage governs the
cohort VINTAGE: "census" snaps to the most recent census year with an
observed population, so a cohort is not built from a sample year in which
most of the candidate universe is absent. "consistent" is a comparison-time
concept and selects like "all" there, carried on the result for
cog_peer_compare().
One fix to the committed test, which was internally inconsistent. It pinned
n_units_reporting == 597 for FY2012 AND asserted that number equals a raw
cross-check that answers 595. Both numbers are right for different questions:
VERNON VILLAGE and WAUKESHA VILLAGE carry type = 3 in `long` (their
as-of-year identity, as townships) while the xwalk lists them as govs_type =
2 (their present identity, as villages) -- schema v6 made the long table's
geography present-harmonized but `type` still reads as-of-year. The rollup
counts against the requested govid set, so 597 answers "how many of the
governments I asked about reported". The cross-check now scopes to that same
universe instead of to long.type/long.fips_state; it still reads raw parquet
rather than going through the verb under test.
Suite: 670 pass / 0 fail / 2 skip (was 658/0/3). rcmdcheck clean.
The two remaining skips are #11 and #12.
This commit is contained in:
+10
-1
@@ -11,7 +11,8 @@ cog_find_peers(
|
||||
same_state = FALSE,
|
||||
pop_range = c(0.7, 1.3),
|
||||
is_ratio = TRUE,
|
||||
max_peers = 10L
|
||||
max_peers = 10L,
|
||||
coverage = c("all", "census", "consistent")
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
@@ -34,6 +35,14 @@ target's population at `year` to produce absolute bounds. If `FALSE`,
|
||||
`pop_range` is interpreted as absolute population counts.}
|
||||
|
||||
\item{max_peers}{Integer cap on the number of peers returned.}
|
||||
|
||||
\item{coverage}{Survey-cycle handling; see [cog_peer_compare()]. Here it
|
||||
governs the cohort VINTAGE when `year` is `NULL`: `"census"` snaps to the
|
||||
most recent census year with an observed population, so a cohort is not
|
||||
built from a sample year in which most of the candidate universe is
|
||||
absent. `"consistent"` needs a year range, which cohort selection does not
|
||||
have, so it selects like `"all"` and is carried on the result as
|
||||
`attr(x, "coverage")` for [cog_peer_compare()].}
|
||||
}
|
||||
\value{
|
||||
Tibble with columns `canonical_govid`, `gov_name`, `fips_state`,
|
||||
|
||||
@@ -10,7 +10,8 @@ cog_geographic_rollup(
|
||||
years,
|
||||
per_capita = FALSE,
|
||||
adjust_to_year = NULL,
|
||||
expenditure_concept = c("direct", "total")
|
||||
expenditure_concept = c("direct", "total"),
|
||||
coverage = c("all", "census", "consistent")
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
@@ -35,6 +36,26 @@ single-government queries but cannot be used here because combining Total
|
||||
across multiple layers of government double-counts intergovernmental
|
||||
transfers (a state's payment to a school district is the same dollar the
|
||||
district reports as its own Direct spending).}
|
||||
|
||||
\item{coverage}{How to handle the Census of Governments survey cycle,
|
||||
which is a **complete census only in years ending in 2 and 7** -- every
|
||||
other year is a sample, and the sample varies enormously (on the bundled
|
||||
fixture, Wisconsin's 608-city universe reports 597 governments in FY2012
|
||||
and 112 in FY2019).
|
||||
|
||||
* `"all"` (default) -- every unit that reported that year. Unchanged
|
||||
behaviour, so existing code keeps working.
|
||||
* `"census"` -- census years only. Aborts if the requested range holds
|
||||
none, rather than silently returning nothing.
|
||||
* `"consistent"` -- only units reporting in *every* requested year, giving
|
||||
a balanced panel.
|
||||
|
||||
Regardless of mode, `provenance$coverage` always carries per-year
|
||||
`n_units_reporting`, `n_units_expected` and `is_census_year`, and
|
||||
`provenance$coverage_mode` records the mode. `is_census_year` is a
|
||||
statement about the **survey calendar**, never a claim of completeness:
|
||||
FY1967 is a census year in which only 97 of Wisconsin's 608 cities
|
||||
report. `n_units_reporting` is the number that tells the truth.}
|
||||
}
|
||||
\value{
|
||||
Tibble with columns `year`, `layer`, `canonical_govid`, `gov_name`,
|
||||
|
||||
+28
-1
@@ -11,7 +11,8 @@ cog_peer_compare(
|
||||
years,
|
||||
per_capita = TRUE,
|
||||
adjust_to_year = NULL,
|
||||
expenditure_concept = c("direct", "total")
|
||||
expenditure_concept = c("direct", "total"),
|
||||
coverage = c("all", "census", "consistent")
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
@@ -33,6 +34,32 @@ population.}
|
||||
`"direct"` is accepted; the `"total"` option exists in [cog_spending()] for
|
||||
single-government queries but cannot be used here because combining Total
|
||||
across peer sets counts intergovernmental transfers twice.}
|
||||
|
||||
\item{coverage}{How to handle the Census of Governments survey cycle,
|
||||
which is a **complete census only in years ending in 2 and 7** -- every
|
||||
other year is a sample, and the sample varies enormously (on the bundled
|
||||
fixture, Wisconsin's 608-city universe reports 597 governments in FY2012
|
||||
and 112 in FY2019).
|
||||
|
||||
* `"all"` (default) -- every unit that reported that year. Unchanged
|
||||
behaviour, so existing code keeps working.
|
||||
* `"census"` -- census years only. Aborts if the requested range holds
|
||||
none, rather than silently returning nothing.
|
||||
* `"consistent"` -- only units reporting in *every* requested year, giving
|
||||
a balanced panel.
|
||||
|
||||
Regardless of mode, `provenance$coverage` always carries per-year
|
||||
`n_units_reporting`, `n_units_expected` and `is_census_year`, and
|
||||
`provenance$coverage_mode` records the mode. `is_census_year` is a
|
||||
statement about the **survey calendar**, never a claim of completeness:
|
||||
FY1967 is a census year in which only 97 of Wisconsin's 608 cities
|
||||
report. `n_units_reporting` is the number that tells the truth.
|
||||
|
||||
The comparison target is exempt from `"consistent"` balancing -- it is the
|
||||
subject of the comparison, not a member of the cohort -- and the
|
||||
`summary_*` quantiles are computed AFTER the filter, so they describe the
|
||||
cohort actually returned. `n_units_reporting` counts peers only, against
|
||||
the cohort size: "3 of your 15 peers reported in FY2019".}
|
||||
}
|
||||
\value{
|
||||
Tibble matching [cog_spending()]'s columns, plus a `role`
|
||||
|
||||
Reference in New Issue
Block a user