jitter {base}R Documentation

‘Jitter’ (Add Noise) to Numbers

Description

Add a small amount of noise (“jitter”) to a numeric vector.

Usage

jitter(x, factor = 1, amount = NULL)

Arguments

x

numeric vector to which jitter should be added.

factor

numeric; used in calculation of amount when the provided amount is 0 or NULL.

amount

number or NULL; when positive, specifies the amount of jitter; see Details, also for other cases.

Details

The result of r <- x + amount * runif(n, -1, 1) where n <- length(x).

When amount is NULL (the default) amount <- factor * d/5 where d is about the smallest difference between adjacent unique (up to fuzz) x values.

If amount == 0, amount <- factor * (max(x) - min(x))/50, (using only finite x values), which is the same as in S and the references. In the above cases, the final amount is always ensured to be positive.

The short jitter() function is itself a succinct definition.

Value

jitter(x, ...) returns a numeric of the same length as x, but with an amount of noise added in order to break ties.

Author(s)

Werner Stahel and Martin Maechler, ETH Zurich

References

Chambers J. M., Cleveland W. S., Kleiner B., Tukey P. A. (1983). Graphical Methods for Data Analysis. Wadsworth & Brooks/Cole. ISBN 0871504138. (Figures 2.8, 4.22, 5.4.).

Chambers J. M., Hastie T. J. (1992). Statistical Models in S. Chapman & Hall, London. ISBN 9780412830402.

See Also

rug which you may want to combine with jitter.

Examples

round(jitter(c(rep(1, 3), rep(1.2, 4), rep(3, 3))), 3)
## These two had failed with S-plus 3.x: max(x) - min(x) == 0
jitter(rep(0, 7))
jitter(rep(10000, 5))

[Package base version 4.6.0 Index]