log1pexp {VGAM}R Documentation

Logarithms with an Unit Offset and Exponential Term

Description

Computes log(1 + exp(x)) accurately.

Usage

log1pexp(x)

Arguments

x

A vector of reals (numeric). Complex numbers not allowed since log1p does not handle these.

Details

Computes log(1 + exp(x)) accurately. An adjustment is made when x is positive and large in value.

Value

Returns log(1 + exp(x)).

See Also

log1p, exp.

Examples

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

[Package VGAM version 0.9-8 Index]