Take a list with a hierarchical survey as an entry - use another list to remap variables and modalities for specific questions
Arguments
- datalist
A list with all hierarchical data frame for a survey data set. format is expected to match the Excel export synchronized from kobo to RILD and loaded with kobocruncher::kobo_data()
- mapper
a list providing the mapping of the variables used for the calculation - this mapper is potentially to be adjusted in relation with deviation between the the standard XlsForm and the contextualized dataset
Examples
mapper = list(
hierarchy = "main",
variablemap = data.frame(
label = c("Does this household use anything for lighting?",
"What source of electricity is used most of the time in this household?"),
variable = c("LIGHT01",
"LIGHT03"),
mappattern = c("LIGHT01",
"LIGHT03") ),
modalitymap = data.frame(
variable = c( "LIGHT01",
"LIGHT03", "LIGHT03", "LIGHT03"),
label = c( "yes",
"No electricity in household", "Other, specify", "Don\'t know"),
standard = c( "1",
"1", "96", "98"),
map = c("yes",
"Noelec", "Other", "Dontknow")
)
)
## One variable is not correctly
datalist <- list(mainhousehold = data.frame(
group.LIGHT01 = c("yes", "yes", "no", "yes", "yes",
"no", "yes", "yes", "yes"),
group.LIGHT03 = c("Noelec", "Other", "Dontknow", "Noelec", "Other",
"Dontknow", "Nuclear", "Other", "Dontknow"))
)
datalist <- fct_re_map(datalist = datalist, mapper = mapper )
#> Mapped levels for LIGHT01 are now: 1, no
#> Mapped levels for LIGHT03 are now: 1, 96, 98, Nuclear
#fct_check_map(datalist = datalist, mapper = mapper )
## Now testing on a full remap...
## Dummy data created with fct_kobo_dummy
datalist <- kobocruncher::kobo_data( system.file("dummy_RMS_CAPI_v2.xlsx",
package = "IndicatorCalc"))
## Mapping file created from Dummy data
mappingfile <- system.file("RMS_CAPI_v2_mapping.xlsx",
package = "IndicatorCalc")
IndicatorRequirementFile <- system.file("RMS_CAPI_v2_mapper.xlsx",
package = "IndicatorCalc")
## and now we remap both required variables for main and ind
mappermain <- fct_build_map(mappingfile = mappingfile,
IndicatorRequirementFile = IndicatorRequirementFile,
thisMeasureLevel = "main")
datalist <- fct_re_map(datalist = datalist, mapper = mappermain )
#> ℹ HEA01 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for HEA01 are now: 1, 2, 3, 4, 5, 96, 98
#> ℹ HEA02 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for HEA02 are now: 1, 2, 3, 96
#> Mapped levels for HEA03 are now: 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 6, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 7, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 8, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 9, 90, 91, 92, 93, 94, 95
#> Mapped levels for LIGHT01 are now: 0, 1
#> ℹ LIGHT02 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for LIGHT02 are now: 1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9, 96
#> ℹ LIGHT03 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for LIGHT03 are now: 1, 2, 3, 4, 5, 6, 7, 8, 96, 98
#> ℹ DWA01 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for DWA01 are now: 1, 10, 11, 12, 13, 14, 15, 16, 2, 3, 4, 5, 6, 7, 8, 9, 96, 98
#> ℹ DWA02 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for DWA02 are now: 1, 2, 3
#> Mapped levels for DWA03a are now: 1, 2
#> Mapped levels for DWA03b are now: 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 6, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 7, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 8, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 9, 90, 91, 92, 93, 94, 95
#> Mapped levels for DWA04 are now: 0, 1
#> ℹ DWE01 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for DWE01 are now: 1, 2, 3, 4, 5, 6, 7, 8, 9, 96
#> ℹ DWE02 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for DWE02 are now: 1, 2, 3, 4, 5, 6, 7, 8, 9, 96
#> ℹ DWE03 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for DWE03 are now: 1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9, 96
#> ℹ DWE04 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for DWE04 are now: 1, 10, 11, 12, 13, 14, 15, 2, 3, 4, 5, 6, 7, 8, 9, 96
#> Mapped levels for DWE05 are now: 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 6, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 7, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 8, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 9, 90, 91, 92, 93, 94, 95
#> Mapped levels for DWE08 are now: 0, 1
#> Mapped levels for DWE09 are now: 1, 2, 3, 4
#> Mapped levels for HH01 are now: 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 6, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 7, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 8, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 9, 90, 91, 92, 93, 94, 95
#> Mapped levels for SAF01 are now: 1, 2, 3, 4, 98, 99
#> Mapped levels for GBV01a are now: 0, 1, 98
#> Mapped levels for GBV01b are now: 0, 1, 98
#> Mapped levels for GBV01c are now: 0, 1, 98
#> Mapped levels for GBV01d are now: 0, 1, 98
#> Mapped levels for VAW01a are now: 0, 1, 99
#> Mapped levels for VAW01b are now: 0, 1, 99
#> Mapped levels for VAW01c are now: 0, 1, 99
#> Mapped levels for VAW01d are now: 0, 1, 99
#> Mapped levels for VAW01e are now: 0, 1, 99
#> Mapped levels for BIR01 are now: 0, 1
#> Mapped levels for BIR02 are now: 0, 1
#> ℹ BIR03 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> The following `from` values were not present in `x`: 2, 3, 4, 5, 6, 96, 98
#> Mapped levels for BIR03 are now: 0, 1
#> ℹ BIR04 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for BIR04 are now: 1, 2, 3, 96
#> ℹ TOI01 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for TOI01 are now: 1, 10, 11, 12, 2, 3, 4, 5, 6, 7, 8, 9, 96
#> Mapped levels for TOI02 are now: 1, 2, 98
#> ℹ COOK02 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for COOK02 are now: 1, 10, 2, 3, 4, 5, 6, 7, 8, 9, 96
#> ℹ COOK03 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for COOK03 are now: 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 3, 4, 5, 6, 7, 8, 9, 96
#> Mapped levels for BANK01 are now: 0, 1
#> Mapped levels for BANK02 are now: 0, 1
#> Mapped levels for BANK03 are now: 0, 1
#> Mapped levels for BANK04 are now: 0, 1
#> Mapped levels for BANK05 are now: 0, 1
#> Mapped levels for INC01 are now: 1, 2, 3, 98
#> Mapped levels for UNEM01 are now: 0, 1
#> Mapped levels for UNEM02 are now: 0, 1
#> Mapped levels for UNEM03 are now: 0, 1
#> Mapped levels for UNEM04 are now: 0, 1
#> Mapped levels for UNEM05 are now: 0, 1
#> Mapped levels for UNEM06 are now: 1, 2, 3
#> Mapped levels for UNEM07 are now: 1, 2, 3
#> Mapped levels for UNEM08 are now: 1, 2, 3, 4
#> Mapped levels for UNEM09 are now: 0, 1
#> Mapped levels for UNEM10 are now: 0, 1
#> ℹ DWE06 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for DWE06 are now: 1, 2, 3, 4, 5, 6, 7, 8, 9, 96, 98, 99
#> ℹ DWE07 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for DWE07 are now: 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9, 96, 98, 99
#> ℹ DWE10 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for DWE10 are now: 1, 2, 3, 4, 5, 6, 96
#> Mapped levels for DWE11 are now: 1, 2, 3, 4, 99
#> Mapped levels for SPF01a are now: 0, 1, 98
#> Mapped levels for SPF01b are now: 0, 1, 98
#> Mapped levels for SPF01c are now: 0, 1, 98
#> Mapped levels for SPF01d are now: 0, 1, 98
#> Mapped levels for SPF01e are now: 0, 1, 98
#> Mapped levels for SPF01f are now: 0, 1, 98
#> Mapped levels for SPF01g are now: 0, 1, 98
#> Mapped levels for SPF01h are now: 0, 1, 98
mapperind <- fct_build_map(mappingfile = mappingfile,
IndicatorRequirementFile = IndicatorRequirementFile,
thisMeasureLevel = "ind")
datalist <- fct_re_map(datalist = datalist, mapper = mapperind )
#> Mapped levels for HACC01 are now: 0, 1
#> ℹ HACC02 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> The following `from` values were not present in `x`: 2, 3, 4, 5, 96
#> Mapped levels for HACC02 are now: 0, 1
#> Mapped levels for HACC03 are now: 0, 1
#> ℹ HACC04 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> The following `from` values were not present in `x`: 2, 3, 4, 5, 6, 7, 8, 9, 10, 96
#> Mapped levels for HACC04 are now: 0, 1
#> Mapped levels for EDU01 are now: 0, 1
#> Mapped levels for EDU02 are now: 0, 1
#> Mapped levels for EDU03 are now: 1, 2, 3, 4, 5, 6, 98
#> ℹ EDU04 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for EDU04 are now: 1, 2, 3, 4, 5, 96, 98
#> ℹ HH07 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for HH07 are now: 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 6, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 7, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 8, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 9, 90, 91, 92, 93, 94, 95
#> Mapped levels for REG03 are now: 0, 1, 98
#> Mapped levels for REG04 are now: 0, 1, 98, 99
#> Mapped levels for REG01a are now: 0, 1, 99
#> Mapped levels for REG01b are now: 0, 1, 99
#> Mapped levels for REG01c are now: 0, 1, 99
#> Mapped levels for REG01d are now: 0, 1, 99
#> Mapped levels for REG01e are now: 0, 1, 99
#> Mapped levels for REG01f are now: 0, 1, 99
#> Mapped levels for REG01g are now: 0, 1, 99
#> Mapped levels for REG02 are now: 0, 1, 99
#> Mapped levels for REG05a are now: 0, 1, 99
#> Mapped levels for REG05b are now: 0, 1, 99
#> Mapped levels for REG05c are now: 0, 1, 99
#> Mapped levels for REG05d are now: 0, 1, 99
#> Mapped levels for REG05e are now: 0, 1, 99
#> Mapped levels for REG05f are now: 0, 1, 99
#> Mapped levels for REG06 are now: 0, 1, 99
#> Mapped levels for COMM01 are now: 0, 1
#> Mapped levels for COMM02 are now: 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 6, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 7, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 8, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 9, 90, 91, 92, 93, 94, 95
#> Mapped levels for COMM03 are now: 0, 1, 98
#> Mapped levels for COMM04 are now: 0, 1, 98
#> Mapped levels for MMR03 are now: 0, 1, 98
#> ℹ TOI03 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for TOI03 are now: 1, 2, 3, 4, 5, 96, 98
#> ℹ TOI04 variable has more than one variable pattern match in the dataset. We will take the first one but good to check...
#> Mapped levels for TOI04 are now: 1, 2, 3
#> Mapped levels for TOI05 are now: 0, 1
#> Mapped levels for COOK01 are now: 0, 1
## Writing this in the installation folder of the packages to run all examples
# openxlsx::write.xlsx( list ( main = as.data.frame(datalist[["main"]]),
# ind = as.data.frame(datalist[["ind"]]) ),
# here::here("inst","dummy_RMS_CAPI_v2_mapped.xlsx"))