e_log_shift | R Documentation |
Default min_add
values:
If specified, use that.
All positive, add 0.
Min is 0, add the minimum non-0 value.
Min is negative and max is positive, add the minimum non-0 value (so minimum is now the previous non-0 value).
Max is negative, add the minimum value plus 1 so log2(x)=0
is the minimum value.
e_log_shift(x, min_add = NULL, base_log = 2, sw_symmetric = c(FALSE, TRUE)[1])
x |
numeric vector |
min_add |
value to add to x before taking log, if not specified and min(x) <= 0, then this is determined automatically |
base_log |
base for log |
sw_symmetric |
overrides |
numeric vector with attributes
f_print_example <- function(x, x2 = e_log_shift(x)) {
print(x)
print(x2)
par(mfrow = c(1, 2))
hist(x)
hist(x2)
par(mfrow = c(1, 1))
invisible(NULL)
}
e_log_shift(x = c(0, 1, 2, 3))
e_log_shift(x = c(0, 10, 100, 1000), base = 10)
e_log_shift(x = c(-4, -2, 0, 2, 4))
# Symmetric, positive with right skew
x <- rgamma(100, 1, 1) |> sort()
x_log <- e_log_shift(x, sw_symmetric = TRUE)
print(x)
print(x_log)
par(mfrow = c(1, 3))
hist(x)
hist(x_log)
dat_skew <- tibble::tibble(min_add = seq(0, 1, by = 0.01), skewness = NA)
for (i_row in seq_len(nrow(dat_skew))) {
## i_row = 1
dat_skew$skewness[i_row] <-
e_log_shift(x, min_add = dat_skew$min_add[i_row]) |>
moments::skewness()
} # i_row
plot(dat_skew$min_add, dat_skew$skewness, type = "l")
abline(h = 0, col = "gray50")
abline(v = attr(x_log, "e_log_shift")["min_add"], col = "gray50")
par(mfrow = c(1, 1))
print(c(skew_x = moments::skewness(x), skew_x_log = moments::skewness(x_log)))
# Symmetric, positive with right skew, less than 1
x <- rgamma(100, 1, 1) |> sort()
x <- x / max(x + 1)
x_log <- e_log_shift(x, sw_symmetric = TRUE)
print(x)
print(x_log)
par(mfrow = c(1, 2))
hist(x)
hist(x_log)
par(mfrow = c(1, 1))
print(c(skew_x = moments::skewness(x), skew_x_log = moments::skewness(x_log)))
# Symmetric, negative with left skew
x <- -rgamma(100, 1, 1) |> sort()
x_log <- e_log_shift(x, sw_symmetric = TRUE)
print(x)
print(x_log)
par(mfrow = c(1, 2))
hist(x)
hist(x_log)
par(mfrow = c(1, 1))
print(c(skew_x = moments::skewness(x), skew_x_log = moments::skewness(x_log)))
# Symmetric, positive with left skew
x <- -rgamma(100, 1, 1) |> sort()
x <- x + min(x)
x_log <- e_log_shift(x, sw_symmetric = TRUE)
print(x)
print(x_log)
par(mfrow = c(1, 2))
hist(x)
hist(x_log)
par(mfrow = c(1, 1))
print(c(skew_x = moments::skewness(x), skew_x_log = moments::skewness(x_log)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.