rk_integerise: rk_integerise

Description Usage Arguments Details Value Examples

Description

Generate integer cases from numeric weights matrix.

Usage

1
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.

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:

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.

Value

A data frame of integerised cases

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)

philmikejones/rakeR documentation built on May 25, 2019, 6 a.m.