Correction of Heaping on Individual Level
Overview
Provides methods for correcting heaping (digit preference) in survey data at the individual record level. Age heaping, where respondents disproportionately report ages ending in 0 or 5, is a common phenomenon that can distort demographic analyses. Unlike traditional smoothing methods that only correct aggregated statistics, this package corrects individual values by replacing a calculated proportion of heaped observations with draws from fitted truncated distributions (log-normal, normal, or uniform). Supports 5-year and 10-year heaping patterns, single heap correction, survey weights, and optional covariate-conditional (model-based) correction via quantile regression forests or linear models to preserve relationships. A multiple-imputation wrapper repeats the correction to propagate the added uncertainty into downstream inference.
Major changes
correctHeaps()andcorrectSingleHeap()gain survey-weight support via a newweight=argument. Heaping ratios and the selection of records to correct then use weighted counts (records are drawn uniformly and accumulated until their cumulative weight covers the excess mass).- **Breaking:** model-based correction is redesigned. Instead of a random-forest sign-adjustment heuristic,
correctHeaps(model=, dataModel=)now fits an imputation model for age given the covariates on the *retained* ("trusted") records and draws covariate-conditional replacements for the selected heaped records. The engine is selectable viamodel.engine = c("ranger", "lm")(arangerquantile forest by default). Corrected values therefore differ from 0.1.x, even with the same seed.
Show all changes in 0.2.0Hide the rest of the changes in 0.2.0
- New
width=argument controls the truncation half-window; 10-year heaps now use a single symmetric window instead of the previous two-stage +/-4 / +/-5 correction. - New
correctHeapsMI()producesmcorrected datasets (with deterministically derived seeds) for multiple-imputation inference, with aprint()method for the returnedheapingMIobject.
Internal
- Removed the internal helpers
.adjust_signs()and the legacy.draw_replacements(); the correction engine now lives inR/impute-model.R.
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-05
- NOTE12 OK, 1 NOTE2026-08-01
- OK14 OK2026-03-10
Documentation
- Help pages
- 15includes a package overview page
- Examples that run
- 100%14 run in a plain check
- Exported functions with examples
- 100%
- Documented parameters
- 100%
- Return-value docs
- 100%
- Help pages citing references
- 73%
Downloads
Repository
2 development-tooling and community-health practices detected across 2 families in the upstream repository
Checks run against github.com/matthias-da/heaping on 2026-10-18.
This repository shows signs of AI coding tools.
- Claude Codefirst seen 2026-01-29Named in .gitignore: .claude, CLAUDE.mdCommits: at least 8 crediting it in the message
- Claude Opus 4.84 commits · Jun to Jul 2026
- Claude Fable 52 commits · Jul 2026
- Claude Opus 4.51 commit · Jan 2026
- Claude Opus 4.61 commit · Mar 2026
Dependencies
Installing heaping adds 20 packages (7 with compiled code, 17 MB of source tarballs). Heaviest: ggplot2 6.0 MB, fitdistrplus 2.4 MB, isoband 1.5 MB.
Code & Tests
Datasets
People & History
Pick two releases to compare their code metrics.
- 0.2.0Latest
- RR 4.6.0 released · 2026-04-24
- 0.1.02026-02-09
- RR 4.5.0 released · 2025-04-11
Package metadata
- First published
- 2026-02-09
- Total releases
- 2 / 1 yrs
- License
- GPL (>= 2) OSI
- Minimum R
- ≥ 3.5.0
- Bundled data
- 236 KB / 1 file
- Download size
- 465 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("heaping")This package has no citation file, so citation() returns this entry built from DESCRIPTION.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-20, which the citation names so these numbers can be found later. More on citing and the projects behind them.