rr3 function

Randomly Round A Vector of Integers to Base 3

Randomly Round A Vector of Integers to Base 3

Apply the 'Random Round to Base 3' (RR3) algorithm to a vector of integers (or doubles where round(x) == x.

rr3(x)

Arguments

  • x: A vector of integers (in the sense that round(x) == x.) Can be an rvec .

Returns

A randomly-rounded version of x.

Details

The RR3 algorithm is used by statistical agencies to confidentialize data. Under the RR3 algorithm, an integer nn

is randomly rounded as follows:

  • If nn is divisible by 3, leave it unchanged
  • If dividing nn by 3 leaves a remainder of 1, then round down (subtract 1) with probability 2/3, and round up (add 2) with probability 1/3.
  • If dividing nn by 3 leaves a remainder of 1, then round down (subtract 2) with probability 1/3, and round up (add 1) with probability 2/3.

RR3 has some nice properties:

  • The randomly-rounded version of nn

    has expected value nn.

  • If nn non-negative, then the randomly rounded version of nn is non-negative.

  • If nn is non-positive, then the randomly rounded version of nn is non-positive.

Examples

x <- c(1, 5, 2, 0, -1, 3, NA) rr3(x)