Skip to contents

Convert normal signed fold change to log2 fold change

Usage

fold_to_log2fold(x, ...)

Arguments

x

numeric vector

...

additional arguments are ignored.

Value

numeric vector representing log2 fold change values.

Details

This function takes fold change values as input, and returns log2 fold change values.

This function recognizes two forms of input:

  • ratios: with values between 0 and 1, and no negative values

  • fold changes: as from log2fold_to_fold() with no values between 0 and 1, and may include negative values.

For any value between 0 and 1, it applies log2() directly, which produces negative output. In return, conversion back to fold change using log2fold_to_fold() will not be reciprocal, instead that step will produce negative fold change.

For example:

  • input = 4 becomes log2 fold change = 2.

  • input = 0.25 becomes log2 fold change = -2.

  • input = -4 becomes log2 fold change = -2.

Examples

x <- c(-3, -2, -1, 0, 1, 2, 3, NA);
fc <- log2fold_to_fold(x);
fc;
#> [1] -8 -4 -2  1  2  4  8 NA

xfc <- c(-4, 0.5, 1, 2, 4)
fold_to_log2fold(xfc);
#> [1] -2 -1  0  1  2