Wrapper for Population Comparison
do_compare(pop1, pop2, fn = c("ID", "IRD", "ADM", "RDM"), verbose = TRUE, ...)
Input data for population 1. UN format;
Input data for population 2. UN format;
Method to be called from DemoTools. Available aternatives:
"ID", "IRD", "ADM", "RDM"
;
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.
A data.frame having the same number of columns as input data. Different numbers of rows. UN format.
# ------------------------------------------
# Example 1 - Compute the Index of dissimilarity between 2 populations
P1m <- DDSQLtools.data$Pop1_Egypt_M_DB # 1-year age groups data
P1f <- DDSQLtools.data$Pop1_Egypt_F_DB
P5m <- DDSQLtools.data$Pop5_Egypt_M_DB # 5-year age groups data
P5f <- DDSQLtools.data$Pop5_Egypt_F_DB
C1 <- do_compare(pop1 = P1m, pop2 = P1f, fn = "ID")
C2 <- do_compare(pop1 = P5m, pop2 = P5f, fn = "ID")
# ------------------------------------------
# Example 2 - Compute the Index of relative difference between 2 populations
C3 <- do_compare(pop1 = P1m, pop2 = P1f, fn = "IRD")
#> Additional (optional) arguments to control the output for the DemoTools::IRD method:
#> log
#> Check ?IRD for details and default values.
C4 <- do_compare(pop1 = P5m, pop2 = P5f, fn = "IRD")
#> Additional (optional) arguments to control the output for the DemoTools::IRD method:
#> log
#> Check ?IRD for details and default values.
select_columns <- c("AgeID", "AgeStart", "AgeMid", "AgeEnd", "AgeLabel",
"DataTypeName", "DataTypeID", "DataValue")
C <- rbind(C1, C2, C3, C4)
C[, select_columns]
#> # A tibble: 4 × 8
#> AgeID AgeStart AgeMid AgeEnd AgeLabel DataTypeName DataTypeID DataValue
#> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <dbl>
#> 1 NA 0 52.5 99 0-99+ DemoTools::ID "do_compare(po… 5.18
#> 2 NA 0 50 75 0-75+ DemoTools::ID "do_compare(po… 1.27
#> 3 NA 0 52.5 99 0-99+ DemoTools::IRD "do_compare(po… 9.77
#> 4 NA 0 50 75 0-75+ DemoTools::IRD "do_compare(po… 1.60
# ------------------------------------------
# Example 3 - Compute the Mean Absolute Difference in survival
# rates between 2 populations
# Since we do not have l[x] data yet, we will make up some dummy data from
# death-rates just to check the example (to be updated).
library(dplyr)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
Mx <- DDSQLtools.data$Mx5
lx.A <-
Mx %>%
do_lifetable() %>%
filter(IndicatorID == "lx") %>%
mutate(AgeLabel = paste0(AgeStart, "-", lead(AgeStart)))
#> Additional (optional) arguments to control the output for the DemoTools::lt_abridged method:
#> Deaths Exposures nMx nqx lx AgeInt radix axmethod a0rule Sex IMR region mod SRB OAnew extrapLaw extrapFrom extrapFit ...
#> Check ?lt_abridged for details and default values.
lx.B <-
Mx %>%
mutate(DataValue = DataValue * 0.98, SexID = 0) %>%
do_lifetable() %>%
filter(IndicatorID == "lx") %>%
mutate(AgeLabel = paste0(AgeStart, "-", lead(AgeStart)))
#> Additional (optional) arguments to control the output for the DemoTools::lt_abridged method:
#> Deaths Exposures nMx nqx lx AgeInt radix axmethod a0rule Sex IMR region mod SRB OAnew extrapLaw extrapFrom extrapFit ...
#> Check ?lt_abridged for details and default values.
C5 <- do_compare(pop1 = lx.A, pop2 = lx.B, fn = "ADM")
#> Additional (optional) arguments to control the output for the DemoTools::ADM method:
#> lx1 lx2 Age1 Age2 ageMin ageMax
#> Check ?ADM for details and default values.
# ------------------------------------------
# Example 4 - Compute the Mean Absolute Difference in age-ratios of survival
# rates between 2 populations
C6 <- do_compare(pop1 = lx.A, pop2 = lx.B, fn = "RDM")
#> Additional (optional) arguments to control the output for the DemoTools::RDM method:
#> lx1 lx2 Age1 Age2 ageMin ageMax
#> Check ?RDM for details and default values.