Smooth population counts in 5-year age groups using the Carrier-Farrag, Karup-King-Newton, Arriaga, United Nations, Strong, MAV or Zigzag methods. Allows for imputation of values in the youngest and oldest age groups for the Carrier-Farrag, Karup-King-Newton, and United Nations methods.

do_smoothing(
  X,
  method = c("Carrier-Farrag", "KKN", "Arriaga", "United Nations", "Strong", "Zigzag",
    "MAV"),
  ageMin = 10,
  ageMax = 65,
  n = 3,
  young.tail = c("Original", "Arriaga", "Strong", NA),
  old.tail = young.tail,
  verbose = TRUE,
  ...
)

Arguments

X

Input data. UN format.

method

character string. Options include "Carrier-Farrag","Arriaga","KKN","United Nations", "Strong", MAV and "Zigzag". See details. Default "Carrier-Farrag".

ageMin

integer. The lowest age included included in intermediate adjustment. Default 10. Only relevant for Strong method.

ageMax

integer. The highest age class included in intermediate adjustment. Default 65. Only relevant for Strong method.

n

integer. The width of the moving average. Default 3 intervals (x-5 to x+9). Only relevant for moving average method.

young.tail

NA or character. Method to use for ages 0-9. See details. Default "original".

old.tail

NA or character. Method to use for the final age groups. See details. Default "original".

verbose

Logical value. If TRUE messages are printed as the method is applied. Set verbose = FALSE to silent the function.

...

Other arguments to be passed on to other methods and functions.

Value

A data.frame having the same number of columns as input data. Different numbers of rows. UN format.

Details

The Carrier-Farrag, Karup-King-Newton (KKN), and Arriaga methods do not modify the totals in each 10-year age group, whereas the United Nations, Strong, Zigzag, and moving average (MAV) methods do. The age intervals of input data could be any integer structure (single, abridged, 5-year, other), but output is always in 5-year age groups. All methods except the United Nations and MAV methods operate based on 10-year age group totals, excluding the open age group.

The Carrier-Farrag, Karup-King-Newton, and United Nations methods do not produce estimates for the first and final 10-year age groups. By default, these are imputed with the original 5-year age group totals, but you can also specify to impute with NA, or the results of the Arriaga, Strong and Cascade methods. If the terminal digit of the open age group is 5, then the terminal 10-year age group shifts down, so imputations may affect more ages in this case. Imputation can follow different methods for young and old ages.

Method names are simplified using simplify.text and checked against a set of plausible matches designed to give some flexibility in case you're not sure

In accordance with the description of these methods in Arriaga (1994), it is advised to compare the results from a variety of methods.

See also

Examples

P5 <- DDSQLtools.data$Pop5_Egypt_M_DB

M <- c("Carrier-Farrag", "KKN", "Arriaga",
       "United Nations", "Strong", "Zigzag", "MAV")

S1 <- do_smoothing(P5, method = M[1])
S2 <- do_smoothing(P5, method = M[2])
S3 <- do_smoothing(P5, method = M[3])
S4 <- do_smoothing(P5, method = M[4])
S5 <- do_smoothing(P5, method = M[5])
S6 <- do_smoothing(P5, method = M[6])
S7 <- do_smoothing(P5, method = M[7])

select_columns <- c("AgeID", "AgeStart", "AgeMid", "AgeEnd", "AgeLabel",
                    "DataTypeName", "DataTypeID", "DataValue")
S1[, select_columns]
#> # A tibble: 16 × 8
#>    AgeID AgeStart AgeMid AgeEnd AgeLabel DataTypeName    DataTypeID    DataValue
#>    <lgl>    <dbl>  <dbl>  <dbl> <fct>    <chr>           <chr>             <dbl>
#>  1 NA           0    2.5      5 0-4      DemoTools::age… do_smoothing…  3951843 
#>  2 NA           5    7.5     10 5-9      DemoTools::age… do_smoothing…  3936424 
#>  3 NA          10   12.5     15 10-14    DemoTools::age… do_smoothing…  4234663.
#>  4 NA          15   17.5     20 15-19    DemoTools::age… do_smoothing…  4132916.
#>  5 NA          20   22.5     25 20-24    DemoTools::age… do_smoothing…  3835300.
#>  6 NA          25   27.5     30 25-29    DemoTools::age… do_smoothing…  3321728.
#>  7 NA          30   32.5     35 30-34    DemoTools::age… do_smoothing…  2529984.
#>  8 NA          35   37.5     40 35-39    DemoTools::age… do_smoothing…  2178255.
#>  9 NA          40   42.5     45 40-44    DemoTools::age… do_smoothing…  2098388.
#> 10 NA          45   47.5     50 45-49    DemoTools::age… do_smoothing…  1834366.
#> 11 NA          50   52.5     55 50-54    DemoTools::age… do_smoothing…  1535701.
#> 12 NA          55   57.5     60 55-59    DemoTools::age… do_smoothing…  1213834.
#> 13 NA          60   62.5     65 60-64    DemoTools::age… do_smoothing…   896041 
#> 14 NA          65   67.5     70 65-69    DemoTools::age… do_smoothing…   638954 
#> 15 NA          70   72.5     75 70-74    DemoTools::age… do_smoothing…   401297 
#> 16 NA          75   87.5      0 75+      DemoTools::age… do_smoothing…   375648 

S <- cbind(S1$DataValue, S2$DataValue, S3$DataValue,
           S4$DataValue, S5$DataValue, S6$DataValue, S7$DataValue)
dimnames(S) <- list(Age = S1$AgeLabel, SmoothingMethod = M)

S
#>        SmoothingMethod
#> Age     Carrier-Farrag     KKN Arriaga United Nations    Strong    Zigzag
#>   0-4          3951843 3951843 3813809        3951843 3868225.4 3951843.0
#>   5-9          3936424 3936424 4074458        3936424 4020041.6 3936424.0
#>   10-14        4234663 4229492 4264697        4076626 4118061.1 4053592.3
#>   15-19        4132916 4138087 4102882        4292026 3947097.2 4256199.5
#>   20-24        3835300 3807223 3833019        3986911 3667466.1 4046477.2
#>   25-29        3321728 3349805 3324009        3152875 3283462.8 3192630.1
#>   30-34        2529984 2555637 2520776        2485954 2784409.8 2443296.8
#>   35-39        2178255 2152602 2187463        2241969 2419614.0 2179786.3
#>   40-44        2098388 2088796 2097290        2084947 2091286.8 2113598.4
#>   45-49        1834366 1843958 1835464        1850159 1797414.7 1888536.9
#>   50-54        1535701 1524627 1525280        1547446 1539709.0 1537081.2
#>   55-59        1213834 1224908 1224255        1208549 1243421.0 1197050.7
#>   60-64         896041  896041  920620         901219  937185.4  902926.7
#>   65-69         638954  638954  614375         638954  621002.3  638954.0
#>   70-74         401297  401297  401297         401297  401297.0  401297.0
#>   75+           375648  375648  375648         375648  375648.0  375648.0
#>        SmoothingMethod
#> Age           MAV
#>   0-4   3951843.0
#>   5-9   3961357.3
#>   10-14 4101334.3
#>   15-19 4126853.7
#>   20-24 3842934.0
#>   25-29 3187917.7
#>   30-34 2617428.3
#>   35-39 2256497.0
#>   40-44 2078089.3
#>   45-49 1823822.3
#>   50-54 1540345.7
#>   55-59 1215192.0
#>   60-64  915272.3
#>   65-69  645430.7
#>   70-74  401297.0
#>   75+    375648.0