graduate_mono: Graduate age groups using a monotonic spline.

View source: R/graduate.R

graduate_monoR Documentation

Graduate age groups using a monotonic spline.

Description

Take the cumulative sum of Value and then run a monotonic spline through it. The first differences split back single-age estimates of Value. Optionally keep the open age group untouched.

Usage

graduate_mono(Value, Age, AgeInt, OAG = TRUE)

Arguments

Value

numeric vector, presumably counts in grouped ages

Age

integer vector, lower bounds of age groups

AgeInt

integer vector, age interval widths

OAG

logical, default = TRUE is the final age group open?

Details

The "hyman" method of stats::splinefun() is used to fit the spline because 1) it passes exactly through the points, 2) it is monotonic and therefore guarantees positive counts, and 3) it seems to be a bit less wiggly (lower average first differences of split counts). Single-age data is returned as-is. If you want to use this function as a smoother you first need to group to non-single ages. Age be any age range, it does not need to start at 0.

Value

Numeric. vector of single smoothed age counts.

References

\insertRef

fritsch1980monotoneDemoTools

Examples

Value                <- structure(c(88623, 90842, 93439, 96325, 99281, 102051, 104351,
			 106555, 109170, 112188, 113582, 112614, 108904, 102622, 95867,
			 80874, 60196, 37523, 17927, 5642, 1110), .Names = c("0", "5",
			 "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60",
			 "65", "70", "75", "80", "85", "90", "95", "100"))

# if the last age group is closed, then it's best to use AgeInt, otherwise,
# one is assumed from the age siphoned from the names attribute of Value.
graduate_mono(Value, OAG = FALSE)
# or leave open age group in tact
graduate_mono(Value, OAG = TRUE)

data(pop1m_ind)
Value5                <- groupAges(pop1m_ind,Age=0:100,N=5) 

Value1 <- graduate_mono(Value = Value5, Age = names2age(Value5), OAG =TRUE)

## Not run: 
 
 plot(seq(0,100,5),Value5 / 5, xlab = 'Age', ylab = 'Counts', type = 's')
 lines(0:100,Value1)

## End(Not run)

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