This is a generic function to impute data from broader hierarchical geographical areas to smaller ones. It requires the exact specification of the of the geographical typology.

impute_down(
  upstream_data = NULL,
  downstream_data = NULL,
  country_var = "country_code",
  regional_code = "geo_code",
  values_var = "values",
  time_var = NULL,
  upstream_method_var = NULL,
  downstream_method_var = NULL
)

Arguments

upstream_data

An upstream data frame to project on containing smaller geographical units, for example, country-level data.

downstream_data

A downstream data frame containing the smaller level missing data observations. It must contain all the necessary structural information for imputation.

country_var

The geographical ID of the upstream data, defaults to "country_code".

regional_code

The geographical ID of the downstream data, defaults to "geo_code".

values_var

The variable that contains the upstream data to be imputed to the downstream data, defaults to "values".

time_var

The time component, if present, defaults to "year".

upstream_method_var

The name of the variable that contains the potentially applied imputation methods. Defaults to NULL.

downstream_method_var

The name of the variable that will contain the metadata of the potentially applied imputation methods. Defaults to NULL in which case a variable called 'method' will be created. If possible, avoid using upstream_data or downstream_data that contains a variable called 'method' for other purposes.

Value

The upstream data frame (containing data of a larger unit) and the downstream data (containing data of smaller sub-divisional units) are joined; whenever data is missing in the downstream sub-divisional column, it is imputed with the corresponding values from the upstream data frame. The 'method' metadata column explains if the actual downstream data or the imputed data can be found in the downstream value column.

Details

The more general impute_down function requires typology information from the higher and lower level typologies. This is not needed when the EU vocabulary is used, and the hierarchy can be established from the EU vocabularies.

See also

Other impute functions: impute_down_nuts()

Examples

{
upstream <- data.frame ( country_code =  rep( "AU", 3),
                         year = c(2018:2020),
                         my_var  = c(10,12,11),
                         description = c("note1", NA_character_,
                         "note3")
                       )

downstream <- australia_states

impute_down ( upstream_data  = upstream,
              downstream_data = downstream,
              country_var = "country_code",
              regional_code = "geo_code",
              values_var = "my_var",
              time_var = "year" )
}
#>    geo_code year                               geo_name country_code my_var
#> 1    AU-NSW 2018                  New South Wales state           AU     10
#> 2    AU-QLD 2018                       Queensland state           AU     10
#> 3     AU-SA 2018                  South Australia state           AU     10
#> 4    AU-TAS 2018                         Tasmania state           AU     10
#> 5    AU-VIC 2018                         Victoria state           AU     10
#> 6     AU-WA 2018                Western Australia state           AU     10
#> 7    AU-ACT 2018 Australian Capital Territory territory           AU     10
#> 8     AU-NT 2018           Northern Territory territory           AU     10
#> 9    AU-NSW 2019                  New South Wales state           AU     12
#> 10   AU-QLD 2019                       Queensland state           AU     12
#> 11    AU-SA 2019                  South Australia state           AU     12
#> 12   AU-TAS 2019                         Tasmania state           AU     12
#> 13   AU-VIC 2019                         Victoria state           AU     12
#> 14    AU-WA 2019                Western Australia state           AU     12
#> 15   AU-ACT 2019 Australian Capital Territory territory           AU     12
#> 16    AU-NT 2019           Northern Territory territory           AU     12
#> 17   AU-NSW 2020                  New South Wales state           AU     11
#> 18   AU-QLD 2020                       Queensland state           AU     11
#> 19    AU-SA 2020                  South Australia state           AU     11
#> 20   AU-TAS 2020                         Tasmania state           AU     11
#> 21   AU-VIC 2020                         Victoria state           AU     11
#> 22    AU-WA 2020                Western Australia state           AU     11
#> 23   AU-ACT 2020 Australian Capital Territory territory           AU     11
#> 24    AU-NT 2020           Northern Territory territory           AU     11
#>                    method description
#> 1  imputed from AU actual       note1
#> 2  imputed from AU actual       note1
#> 3  imputed from AU actual       note1
#> 4  imputed from AU actual       note1
#> 5  imputed from AU actual       note1
#> 6  imputed from AU actual       note1
#> 7  imputed from AU actual       note1
#> 8  imputed from AU actual       note1
#> 9  imputed from AU actual        <NA>
#> 10 imputed from AU actual        <NA>
#> 11 imputed from AU actual        <NA>
#> 12 imputed from AU actual        <NA>
#> 13 imputed from AU actual        <NA>
#> 14 imputed from AU actual        <NA>
#> 15 imputed from AU actual        <NA>
#> 16 imputed from AU actual        <NA>
#> 17 imputed from AU actual       note3
#> 18 imputed from AU actual       note3
#> 19 imputed from AU actual       note3
#> 20 imputed from AU actual       note3
#> 21 imputed from AU actual       note3
#> 22 imputed from AU actual       note3
#> 23 imputed from AU actual       note3
#> 24 imputed from AU actual       note3