Smooth data over age fitting linear models, preserving the open age group if necessary. This is a wrapper to stats::lm() but using standard demographic arguments.

poly_smth1(Value, Age, degree = 2, trans, pow = 2, OAG = TRUE, ...)

Arguments

Value

numeric vector of counts in single, abridged, or 5-year age groups.

Age

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

degree

integer degree of polynomial. Default 2.

trans

if a transformation is desired, either specify "log" or "power", otherwise leave missing.

pow

if "power" specified for trans then the power transformation to apply.

OAG

logical. Whether or not the top age group is open. Default TRUE.

...

optional arguments passed to stats::lm()

Details

The total sum of Value is preserved in the output. One can control smoothness by adjusting the degree of the polynomial (higher degree more wiggly). See lm for more details. One may wish to log transform the data before fitting the polynomial, in which case trans should be specified as "log". "power" is also an option in which case the data is transformed by Value^(1/pow) before fitting, and then the prediction is back-transformed (negative values not allowed)-- This is friendlier in the case of 0s. For the log transformation, 0s have no weight.

See also

Examples

if (FALSE) { Age <- 0:99 cols <- RColorBrewer::brewer.pal(7,"Reds")[3:7] plot(Age,pop1m_pasex) lines(Age, poly_smth1(pop1m_pasex, Age, OAG = FALSE),col=cols[1]) lines(Age, poly_smth1(pop1m_pasex, Age, degree = 3, OAG = FALSE), col = cols[2]) lines(Age, poly_smth1(pop1m_pasex, Age, degree = 3, trans = "log", OAG = FALSE), col = cols[3]) lines(Age, poly_smth1(pop1m_pasex, Age, degree = 3, trans = "power", pow = 2, OAG = FALSE), col = cols[4]) lines(Age, poly_smth1(pop1m_pasex, Age, degree = 4, trans = "power", pow = 3, OAG = FALSE), col = cols[5]) }