Skip to contents

Function that shifts a value by some offset and then applies the natural logarithm to it.

Usage

log_shift(x, offset = 0, base = exp(1))

Arguments

x

vector of input values to be transformed

offset

number to add to the input value before taking the natural logarithm

base

a positive or complex number: the base with respect to which logarithms are computed. Defaults to e = exp(1).

Value

A numeric vector with transformed values

Details

The output is computed as log(x + offset)

References

Transformation of forecasts for evaluating predictive performance in an epidemiological context Nikos I. Bosse, Sam Abbott, Anne Cori, Edwin van Leeuwen, Johannes Bracher, Sebastian Funk medRxiv 2023.01.23.23284722 doi:10.1101/2023.01.23.23284722 https://www.medrxiv.org/content/10.1101/2023.01.23.23284722v1 # nolint

Examples

log_shift(1:10)
#>  [1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 1.7917595 1.9459101
#>  [8] 2.0794415 2.1972246 2.3025851
log_shift(0:9, offset = 1)
#>  [1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 1.7917595 1.9459101
#>  [8] 2.0794415 2.1972246 2.3025851

transform_forecasts(
  example_quantile[true_value > 0, ],
  fun = log_shift,
  offset = 1
 )
#>        location target_end_date target_type   true_value location_name
#>     1:       DE      2021-01-02       Cases 1.273000e+05       Germany
#>     2:       DE      2021-01-02      Deaths 4.534000e+03       Germany
#>     3:       DE      2021-01-09       Cases 1.549220e+05       Germany
#>     4:       DE      2021-01-09      Deaths 6.117000e+03       Germany
#>     5:       DE      2021-01-16       Cases 1.101830e+05       Germany
#>    ---                                                                
#> 40672:       IT      2021-07-24      Deaths 4.369448e+00         Italy
#> 40673:       IT      2021-07-24      Deaths 4.369448e+00         Italy
#> 40674:       IT      2021-07-24      Deaths 4.369448e+00         Italy
#> 40675:       IT      2021-07-24      Deaths 4.369448e+00         Italy
#> 40676:       IT      2021-07-24      Deaths 4.369448e+00         Italy
#>        forecast_date quantile prediction                model horizon   scale
#>     1:          <NA>       NA         NA                 <NA>      NA natural
#>     2:          <NA>       NA         NA                 <NA>      NA natural
#>     3:          <NA>       NA         NA                 <NA>      NA natural
#>     4:          <NA>       NA         NA                 <NA>      NA natural
#>     5:          <NA>       NA         NA                 <NA>      NA natural
#>    ---                                                                       
#> 40672:    2021-07-12    0.850   5.866468 epiforecasts-EpiNow2       2     log
#> 40673:    2021-07-12    0.900   5.986452 epiforecasts-EpiNow2       2     log
#> 40674:    2021-07-12    0.950   6.214608 epiforecasts-EpiNow2       2     log
#> 40675:    2021-07-12    0.975   6.416732 epiforecasts-EpiNow2       2     log
#> 40676:    2021-07-12    0.990   6.579251 epiforecasts-EpiNow2       2     log