graduate_mono | R Documentation |
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.
graduate_mono(Value, Age, AgeInt, OAG = TRUE)
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 = |
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.
Numeric. vector of single smoothed age counts.
fritsch1980monotoneDemoTools
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.