dot-logFloor: Log-transformed values, with a floor (> 0)

.logFloorR Documentation

Log-transformed values, with a floor (> 0)

Description

Avoid -Inf problems when x == 0 by setting a non-zero floor value for x. This is preferred over using some log(x + d) transformation, as the choice of d is arbitrary, and will affect model fit.

Usage

.logFloor(x, floor = 0.3)

Arguments

x

Numeric.

floor

Minimum age value boundary. Default 0.3.

Examples

## Not run: 
  x <- sample(0:400, 1e7, replace = TRUE)
  floor <- 0.3
  logFloor <- log(floor)
  microbenchmark::microbenchmark(
    log(pmax(floor, x)),
    pmax(log(floor), log(x)),
    {x[x < floor] <- floor; log(x)},
    {y <- log(x); y[is.infinite(y)] <- logFloor} ## fastest; TODO: implement? not a bottleneck
  )

## End(Not run)

PredictiveEcology/LandR documentation built on June 7, 2024, 4:16 p.m.