heapify: Induce heaping on terminal digits 0 and 5

View source: R/check_heaping.R

heapifyR Documentation

Induce heaping on terminal digits 0 and 5

Description

For single age count data, perturb the data in such a way as to induce heaping on ages ending in 0 and 5. This is a common phenomenon that several age heaping evaluation methods are designed to test for. In order to estimate how these methods respond to different degrees of heaping in a systematic way, a function such as this may be useful. The way this works is purely a guess, and no checks are in place, so use with caution.

Usage

heapify(
  Value,
  Age,
  p0 = 2,
  p5 = p0,
  pdf0 = c(1, 6, 15, 20, 15, 6, 1),
  pdf5 = c(c(1, 4, 6, 4, 1)),
  ageMin = 25,
  ageMax = max(Age[Age%%5 == 0])
)

Arguments

Value

numeric. A vector of demographic counts by single age.

Age

numeric. A vector of ages corresponding to the lower integer bound of the counts.

p0

total size of bias to round to 0s. Default 2.

p5

total size of bias to round to 5s. Defaults to p0.

pdf0

numeric vector of length 7 giving the pdf to apply around 0s.

pdf5

numeric vector of length 5 giving the pdf to apply around 5s.

ageMin

integer ending in 0 or 5. The lowest age to be heaped upon, default 25.

ageMax

integer ending in 0 or 5. The highest age to be heaped upon, defaults to highest age evenly divisible by 10.

Details

We use pascal weights, c(1,4,6,4,1) scaled to argument p5 and c(1,6,15,20,15,6,1) scaled to argument p0 to shift individuals from surrounding ages to ages endings in 5 and 0, respectively. This assumes that ages closer to digits 0 or 5 are more likely to be declared as 0 or 5, that this bias is symmetrical, and that such rounding can come from farther away ages for terminal digit 0 than for 5. The user can also make heaping scale differently for 0s and 5s, but there is no control over the shape of bias.

Value

Value numeric vector perturbed to look like age heaping as happened.

Examples

# example to show what we're talking about.
# pop1m_pasex is already quite heaped:
Age <- 0:99
A5 <- seq(0,95,by=5)
## Not run: 
plot(Age,pop1m_pasex)
# here it is again, smoothed:
smoothed <- graduate_sprague(
		smooth_age_5(pop1m_pasex,
				Age,
				method = "Strong",
				OAG = FALSE,
				young.tail = "Arriaga"),
		Age = A5,
		OAG = FALSE)
lines(Age, smoothed)
# an OK approximation for testing purposes.
points(Age,heapify(smoothed,Age=0:99,1.8,1.1,ageMin=20),pch="x")

## End(Not run)

timriffe/DemoTools documentation built on Oct. 14, 2024, 12:53 p.m.