Generate integer cases from numeric weights matrix.

rk_integerise(weights, inds, method = "trs", seed = 42)

Arguments

weights

A matrix or data frame of fractional weights, typically provided by rakeR::rk_weight()

inds

The individual--level data (i.e. one row per individual)

method

The integerisation method specified as a character string. Defaults to "trs"; currently other methods are not implemented.

seed

The seed to use, defaults to 42.

Value

A data frame of integerised cases

Details

Extracted weights (using rakeR::rk_extract()) are more 'precise' than integerised weights (although the user should be careful this is not spurious precision based on context) as they return fractions. Nevertheless, integerised weights are useful in cases when:

  • Numeric information (such as income) is required, as this needs to be cut() to work with rakeR::rk_extract()

  • Simulated 'individuals' are required for case studies of key areas.

  • Input individual-level data for agent-based or dynamic models are required

The default integerisation method uses the 'truncate, replicate, sample' method developed by Robin Lovelace and Dimitris Ballas http://www.sciencedirect.com/science/article/pii/S0198971513000240

Other methods (for example proportional probabilities) may be implemented at a later date.

Examples

cons <- data.frame( "zone" = letters[1:3], "age_0_49" = c(8, 2, 7), "age_gt_50" = c(4, 8, 4), "sex_f" = c(6, 6, 8), "sex_m" = c(6, 4, 3), stringsAsFactors = FALSE ) inds <- data.frame( "id" = LETTERS[1:5], "age" = c( "age_gt_50", "age_gt_50", "age_0_49", "age_gt_50", "age_0_49" ), "sex" = c("sex_m", "sex_m", "sex_m", "sex_f", "sex_f"), "income" = c(2868, 2474, 2231, 3152, 2473), stringsAsFactors = FALSE ) vars <- c("age", "sex") weights <- rk_weight(cons = cons, inds = inds, vars = vars) weights_int <- rk_integerise(weights, inds = inds)