log_zero_inflated: Add a defined number to a numeric and log transform it

View source: R/normalise.R

log_zero_inflatedR Documentation

Add a defined number to a numeric and log transform it

Description

Frequently, light exposure data need to be log-transformed. Because light exposure data frequently also contain many zero-values, adding a small value avoids losing those observations. Must be applied with care and reported.

exp_zero_inflated() is the reverse function to log_zero_inflated().

Usage

log_zero_inflated(x, offset = 0.1, base = 10)

exp_zero_inflated(x, offset = 0.1, base = 10)

Arguments

x

A numeric vector

offset

the amount to add to x, by default 0.1

base

The logarithmic base, by default 10

Value

a transformed numeric vector

References

Johannes Zauner, Carolina Guidolin, Manuel Spitschan (2025) How to deal with darkness: Modelling and visualization of zero-inflated personal light exposure data on a logarithmic scale. J Biol Rhythms. 2025 Oct;40(5):480-490. doi: https://doi.org/10.1177/07487304251336624

Examples

c(0, 1, 10, 100, 1000, 10000) |> log_zero_inflated()

#For use in a function
sample.data.environment |>
  dplyr::filter(Id == "Participant") |>
  dplyr::group_by(Date = lubridate::wday(Datetime, label = TRUE, week_start = 1)) |>
  dplyr::summarize(
  TAT250 = duration_above_threshold(log_zero_inflated(MEDI),
                                    Datetime,
                                    threshold = log_zero_inflated(250)
                                    )
                   )
                   

#Calling exp_zero_inflated on data transformed with log_zero_inflated yields to the original result
c(0, 1, 10, 100, 1000, 10000) |> log_zero_inflated() |> exp_zero_inflated()

LightLogR documentation built on Nov. 28, 2025, 5:09 p.m.