log1mexp {VGAM} | R Documentation

## Logarithms with an Unit Offset and Exponential Term

### Description

Computes `log(1 + exp(x))` and `log(1 - exp(-x))` accurately.

### Usage

    log1mexp(x)
    log1pexp(x)

### Arguments

`x` | A vector of reals (numeric). Complex numbers not allowed since `expm1` and `log1p` do not handle these.

### Details

Computes `log(1 + exp(x))` and `log(1 - exp(-x))` accurately. An adjustment is made when x is away from 0 in value.

### Value

`log1mexp(x)` gives the value of log(1-exp(-x)).

`log1pexp(x)` gives the value of log(1+exp(x)).

### Note

If `NA` or `NaN` is present in the input, the corresponding output will be `NA`.

### Author(s)

This is a direct translation of the function in Martin Maechler's (2012) paper by Xiangjie Xue and T. W. Yee.

### References

Maechler, Martin (2012). Accurately Computing log(1-exp(-|a|)). Assessed from the Rmpfr package.

### See Also

`log1p`, `expm1`, `exp`, `log`

### Examples

    x <-  c(10, 50, 100, 200, 400, 500, 800, 1000, 1e4, 1e5, 1e20, Inf, NA)
    log1pexp(x)
    log(1 + exp(x))  # Naive; suffers from overflow
    log1mexp(x)
    log(1 - exp(-x))
    y <- -x
    log1pexp(y)
    log(1 + exp(y))  # Naive; suffers from inaccuracy

[Package VGAM version 1.0-3 Index]