Smooth data in 5-year age groups.
smooth_age_5_mav(Value, Age, OAG = TRUE, n = 3, tails = FALSE)
| Value | numeric vector of (presumably) counts in 5-year age groups. |
|---|---|
| Age | integer vector of age group lower bounds. |
| OAG | logical. Whether or not the top age group is open. Default |
| n | integer. The width of the moving average. Default 3 intervals (x-5 to x+9). |
| tails | logical. If tails is |
numeric vector of smoothed counts in 5-year age groups.
This function calls smooth_age_5_zigzag_inner(), but prepares data in a way consistent with other methods called by smooth_age_5(). It is probably preferable to call zigzag() from the top level, or else call this method from agesmth() for more control over tail imputations.
If tails is set to FALSE, this function calls mav(), which itself relies on the more general ma(). We lose the lowest and highest ages with this method, unless n=1, in which case data is returned in the original 5-year age groups. The total population count is not constrained to sum to the original total.
If tails is TRUE, the same results are expected but the tails are
filled in using a cascading method.
Age <- c(0,1,seq(5,90,by=5)) # defaults ns <- sapply(1:5,smooth_age_5_mav,Value=dth5_zigzag,Age=Age,OAG=TRUE) cols <- paste0(gray(seq(.8,0,length=5)),"A0") lwds <- seq(4,1,length=5) if (FALSE) { plot(Age, dth5_zigzag,pch=16) matplot(as.integer(rownames(ns)),ns,type='l', col = cols, lty = 1, add = TRUE, lwd = lwds) legend("topright", col = cols, lty = 1, lwd = lwds, legend = paste("n =",1:5)) }