One dimensional smoothing over age (or time) using either loess ("loess" or polynomial "poly" regression. Results of loess may at times be similar to a two-step smooth_age_5() method followed by graduation (e.g. graduate_beers() or graduate_beers(), but local totals are not not constrained for any of the agesmth1() methods at this time. Total counts are constrained to the original total in all cases.

agesmth1(
  Value,
  Age,
  method = "loess",
  OAG = TRUE,
  degree = 2,
  trans,
  pow = 2,
  ...
)

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.

method

character, either "loess" or "poly".

OAG

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

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.

...

optional arguments passed to stats::lm()

Details

LOESS (locally weighted smoothing) helps to smooth data over age, preserving the open age group if necessary. It is a popular tool to create a smooth line through a timeplot or scatter plot. Loess smoothness may be tweaked by specifying an optional "span" argument. Polynomial fitting is used to smooth data over age or time fitting linear models. It can be tweaked by changing the degree and by either log or power transforming. The open age group can be kept as-is if desired by specifying OAG = TRUE. May be used on any age groups, including irregularly spaced, single age, or 5-year age groups. Predictions are only returned for the original age groups.

See also

Examples

Age <- 0:99 #cols <- RColorBrewer::brewer.pal(7,"Reds")[3:7] cols <- c("#FC9272", "#FB6A4A", "#EF3B2C", "#CB181D", "#99000D") if (FALSE) { plot(Age,pop1m_pasex) lines(Age, agesmth1(pop1m_pasex, Age, method="poly", OAG = FALSE),col=cols[1]) lines(Age, agesmth1(pop1m_pasex, Age, method="poly", degree = 3, OAG = FALSE), col = cols[2]) lines(Age, agesmth1(pop1m_pasex, Age, method="poly", degree = 3, trans = "log", OAG = FALSE), col = cols[3]) lines(Age, agesmth1(pop1m_pasex, Age, method="poly", degree = 3, trans = "power", pow = 2, OAG = FALSE), col = cols[4]) lines(Age, agesmth1(pop1m_pasex, Age, method="poly", degree = 4, trans = "power", pow = 3, OAG = FALSE), col = cols[5]) lines(Age, agesmth1(pop1m_pasex, Age, method="loess", OAG = FALSE), col = "royalblue") lines(Age, agesmth1(pop1m_pasex, Age, method="loess", span = 1, OAG = FALSE), col = "blue") }