| rounding_bias {scrutiny} | R Documentation |
Compute rounding bias
Description
Rounding often leads to bias, such that the mean of a rounded
distribution is different from the mean of the original distribution. Call
rounding_bias() to compute the amount of this bias.
Usage
rounding_bias(
x,
digits,
rounding = "up",
threshold = 5,
symmetric = FALSE,
mean = TRUE
)
Arguments
x |
Numeric or string coercible to numeric. |
digits |
Integer. Number of decimal digits to which |
rounding |
String. Rounding procedure that will be applied to |
threshold, symmetric |
Further arguments passed down to |
mean |
Logical. If |
Details
Bias is calculated by subtracting the original vector, x, from a
vector rounded in the specified way.
The function passes all arguments except for mean down to reround().
Other than there, however, rounding is "up" by default, and it can't be
set to "up_or_down", "up_from_or_down_from", or"ceiling_or_floor".
Value
Numeric. By default of mean, the length is 1; otherwise, it is the
same length as x.
Examples
# Define example vector:
vec <- seq_distance(0.01, string_output = FALSE)
vec
# The default rounds `x` up from 5:
rounding_bias(x = vec, digits = 1)
# Other rounding procedures are supported,
# such as rounding down from 5...
rounding_bias(x = vec, digits = 1, rounding = "down")
# ...or rounding to even with `base::round()`:
rounding_bias(x = vec, digits = 1, rounding = "even")