Learn R Programming

DOQTL (version 1.8.0)

addLogVector: Add a vector of log values.

Description

When a summation must be taken on a vector of numbers that are on the log scale, transforming them back to the non-log scale and taking the sum is slow. This function takes the exp() of the values only when neccessary.

Usage

addLogVector(x)

Arguments

x
Numeric vector containing values on a log scale to be summed on the untransformed scale.

Value

Numeric value containing the sum of the values on a log scale.

Details

This function checks to see if the difference between the maximum values and the remaining values is less than the machine precision. If it is, then the exp() is taken for those values that differ by less than the machine precision, they are summed and returned to a log scale. If the maximum value is differs from the other values by greater than the machine precision, then return the maximum value.

See Also

addLog

Examples

Run this code
  addLogVector(log(1:10))

Run the code above in your browser using DataLab