Description Usage Arguments Value See Also Examples
View source: R/ComparisonMethods.R
Wrapper for Population Comparison
1 | do_compare(pop1, pop2, fn = c("ID", "IRD", "ADM", "RDM"), verbose = TRUE, ...)
|
pop1 |
Input data for population 1. UN format; |
pop2 |
Input data for population 2. UN format; |
fn |
Method to be called from DemoTools. Available aternatives:
|
verbose |
Logical value. If |
... |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # ------------------------------------------
# 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")
C4 <- do_compare(pop1 = P5m, pop2 = P5f, fn = "IRD")
select_columns <- c("AgeID", "AgeStart", "AgeMid", "AgeEnd", "AgeLabel",
"DataTypeName", "DataTypeID", "DataValue")
C <- rbind(C1, C2, C3, C4)
C[, select_columns]
# ------------------------------------------
# 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)
Mx <- DDSQLtools.data$Mx5
lx.A <-
Mx %>%
do_lifetable() %>%
filter(IndicatorID == "lx") %>%
mutate(AgeLabel = paste0(AgeStart, "-", lead(AgeStart)))
lx.B <-
Mx %>%
mutate(DataValue = DataValue * 0.98, SexID = 0) %>%
do_lifetable() %>%
filter(IndicatorID == "lx") %>%
mutate(AgeLabel = paste0(AgeStart, "-", lead(AgeStart)))
C5 <- do_compare(pop1 = lx.A, pop2 = lx.B, fn = "ADM")
# ------------------------------------------
# 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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.