recover_na: Recovers NA-values in data

View source: R/NA_imputation.R

recover_naR Documentation

Recovers NA-values in data

Description

Using information disaggregated at different levels recovers protected information: NAs in cells that would otherwise have values 1-4. Options to impute NA-values that cannot be perfectly recovered.

Usage

recover_na(
  disaggr_data,
  aggr_data,
  disaggr_col,
  aggr_col,
  var,
  only_accurate = FALSE,
  randomize_rest = FALSE
)

Arguments

disaggr_data

data.frame, contains the data for which NAs are to be recovered.

aggr_data

data.frame, contains the date on one aggregation level above. This data contains the additional information that is used to recovers NAs.

disaggr_col

character, is the name of the aggregation class in disaggr_data and aggr_data.

aggr_col

character, is the name of the aggregation class in aggr_data and disaggr_data.

var

character, is the name of the variable for which NAs are to be recovered.

only_accurate

logical, if TRUE, only replaces NA-values that can be recovered accurately. Otherwise see randomize_rest. Defaults to FALSE.

randomize_rest

logical, if TRUE, randomizes a value from 1:4 for those NA-values that cannot be accurately recovered. If FALSE, evenly allocates the missing values as inferred from aggr_data to replace NA-values.

Details

Note that randomization of the values that cannot be accurately allocated does not guarantee that the values of resulting disaggregate data will summ to the values of the aggregate data. Even allocation does ensure this.

Value

data.frame Output is a data.frame disaggr_data with NAs recovered.


pttry/statfitools documentation built on Feb. 2, 2025, 1:50 a.m.