% Generated by roxygen2: do not edit by hand % Please edit documentation in R/peers.R \name{cog_peer_compare} \alias{cog_peer_compare} \title{Compare a target government against a peer set} \usage{ cog_peer_compare( target_govid, peers, category, years, per_capita = TRUE, adjust_to_year = NULL, expenditure_concept = c("primary", "direct", "total"), coverage = c("all", "census", "consistent") ) } \arguments{ \item{target_govid}{Character scalar.} \item{peers}{A tibble from \code{\link[=cog_find_peers]{cog_find_peers()}} or a character vector of \code{canonical_govid}s.} \item{category}{Character scalar or vector.} \item{years}{Integer vector.} \item{per_capita}{Default \code{TRUE} — peer compare usually normalizes by population.} \item{adjust_to_year}{Integer base year for CPI-U conversion or \code{NULL}.} \item{expenditure_concept}{\code{"primary"} (default), \code{"direct"}, or \code{"total"} -- see \code{\link[=cog_spending]{cog_spending()}} for the three concepts. \code{"total"} is refused here because combining Total across peer sets counts intergovernmental transfers twice; \code{"primary"} and \code{"direct"} combine safely.} \item{coverage}{How to handle the Census of Governments survey cycle, which is a \strong{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). \itemize{ \item \code{"all"} (default) -- every unit that reported that year. Unchanged behaviour, so existing code keeps working. \item \code{"census"} -- census years only. Aborts if the requested range holds none, rather than silently returning nothing. \item \code{"consistent"} -- only units reporting in \emph{every} requested year, giving a balanced panel. } Regardless of mode, \code{provenance$coverage} always carries per-year \code{n_units_expected}, \code{n_units_collected}, \code{n_units_reporting} and \code{is_census_year}, and \code{provenance$coverage_mode} records the mode. \code{is_census_year} is a statement about the \strong{survey calendar}, never a claim of completeness: FY1967 is a census year in which only 97 of Wisconsin's 608 cities report. \code{n_units_reporting} is category-conditional and is not a response rate on its own -- see "Reading \code{coverage}" below for what each counter answers. The comparison target is exempt from \code{"consistent"} balancing -- it is the subject of the comparison, not a member of the cohort -- and the \verb{summary_*} quantiles are computed AFTER the filter, so they describe the cohort actually returned. \code{n_units_reporting} counts peers only, against the cohort size: "3 of your 15 peers reported in FY2019".} } \value{ Tibble matching \code{\link[=cog_spending]{cog_spending()}}'s columns, plus a \code{role} column taking values \code{"target"}, \code{"peer"}, \code{"summary_p25"}, \code{"summary_p50"}, or \code{"summary_p75"}, \code{target_rank} (target's rank among target+peers at \code{max(years)}, NA for other rows), and \code{cohort_year} (the year used to build the peer cohort, read from \code{attr(peers, "cohort_year")}; \code{NA} when \code{peers} was a bare character vector). Provenance reports \code{verb = "cog_peer_compare"}, \code{peer_count}, \code{cohort_year}, and \code{cohort_govids}. \strong{The \verb{summary_*} rows are per-category quantiles: they are not additive.} Each one is computed \strong{within each \verb{(year, spend_subtype, category)} cell} across the peer set, so a \code{summary_p50} row is \emph{the median peer's value in that one category}, not \emph{the value of the median peer's total}. The median peer for Police and the median peer for Fire are usually different governments, so summing \verb{summary_*} rows across categories does not give any peer's total and misstates the band it appears to describe — measured at −32.7\% to +251.0\% across 24 years on one cohort, with a sign flip at FY2012. Facet by \code{role} \strong{and} \code{category} (the documented use, and what the rows are built for). For a genuine "median peer's total spending" line, sum each peer's own categories first and take the quantile of those per-government totals: \if{html}{\out{