
Time-Series Quality Control for Daily Municipal Health Counts
Source:R/sus_data_ts_quality.R
sus_data_ts_quality.RdEvaluates the quality of daily health event time series at the municipal level, producing per-municipality flags for:
Usage
sus_data_ts_quality(
data,
outcome_col = "n_obitos",
muni_col = "code_muni",
date_col = "date",
min_completeness = 0.9,
max_gap = 7L,
break_alpha = 0.05,
max_outlier_months = 3L,
lang = "pt",
verbose = TRUE
)Arguments
- data
A
climasus_dfat stage"aggregate", or anydata.framewith a municipality identifier column, a date column, and a daily count column.- outcome_col
Character. Name of the daily count column. Default:
"n_obitos".- muni_col
Character. Name of the municipality identifier column. Default:
"code_muni".- date_col
Character. Name of the date column. Default:
"date".- min_completeness
Numeric (0-1). Minimum completeness to recommend inclusion. Default:
0.90(90% of expected days present).- max_gap
Integer. Maximum tolerated consecutive zero/missing days before flagging a temporal gap. Default:
7L.- break_alpha
Numeric. Significance level for structural break test. Default:
0.05. Ignored ifstrucchangeis not installed.- max_outlier_months
Integer. Maximum number of outlier months allowed before exclusion. Default:
3L.- lang
Character. Language for messages:
"pt"(default),"en","es".- verbose
Logical. Print progress messages. Default
TRUE.
Value
A climasus_ts_quality list with:
$flagsTibble (one row per municipality) with columns:
muni_col,n_obs,n_expected,completeness,has_break,break_pval,n_outlier_months,n_gaps_gt{max_gap}d,score,include.$recommend_includeCharacter vector of municipality codes recommended for inclusion.
$recommend_excludeCharacter vector of municipality codes recommended for exclusion, with reason.
$paramsList of QC parameters used.
Details
Completeness: fraction of expected days with non-missing records.
Structural breaks: abrupt level shifts detectable by the CUSUM-based Zeileis et al. (2002) test (requires the
strucchangepackage).Monthly outliers: months with counts > Q3 + 1.5 x IQR (Tukey fence).
Temporal gaps: runs of consecutive days with zero or missing counts longer than
max_gap.
A composite inclusion score (0-100) and a binary include recommendation
are returned, matching the exclusion criteria used in large Brazilian
heat-wave studies (Lowe et al. 2021, Anjos & Targino 2023).
References
Zeileis, A., Leisch, F., Hornik, K., & Kleiber, C. (2002). strucchange: An R Package for Testing for Structural Change in Linear Regression Models. Journal of Statistical Software, 7(2). doi:10.18637/jss.v007.i02