From 49b5d4ce207aa48bccab09bb4ec9dc64a05b842e Mon Sep 17 00:00:00 2001 From: Charlie Wright <80007059+wcwr@users.noreply.github.com> Date: Wed, 12 Mar 2025 10:24:37 -0500 Subject: [PATCH 1/2] Update utils.R Add alpha to logit2 function --- R/utils.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index 14218cb..505fe15 100644 --- a/R/utils.R +++ b/R/utils.R @@ -20,7 +20,10 @@ utils::globalVariables(c("channel")) # Internal functions ----------------------------------------------------------- -logit2 <- function(x) log2(x) - log2(1 - x) +logit2 <- function(x, alpha = 1e-5) { + #Protect against values exactly 0 or 1 by adding some small alpha + log2((x + alpha) / (1 - x + alpha)) +} ilogit2 <- function(x) 2^x / (1 + 2^x) From 0588d3bfdb76842b39f811b2b0323365a3531d61 Mon Sep 17 00:00:00 2001 From: Charlie Wright <80007059+wcwr@users.noreply.github.com> Date: Wed, 12 Mar 2025 10:27:28 -0500 Subject: [PATCH 2/2] Update logit2.Rd Describe alpha in logit2 function --- man/logit2.Rd | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/man/logit2.Rd b/man/logit2.Rd index 64430b4..d66bc51 100644 --- a/man/logit2.Rd +++ b/man/logit2.Rd @@ -1,23 +1,24 @@ \name{logit2} \alias{logit2} \alias{ilogit2} -\title{ - logit in base 2. -} +\title{Logit in base 2 with offset} \description{ - Utility functions for computing logit and inverse logit in base 2. + Utility functions for computing the logit and inverse logit in base 2. + \code{logit2} includes an \code{alpha} parameter to add a small offset, + which helps avoid infinite values when \code{x} is exactly 0 or 1. } \usage{ -logit2(x) -ilogit2(x) + logit2(x, alpha = 1e-5) + ilogit2(x) } \arguments{ - \item{x}{A numeric vector.} + \item{x}{A numeric vector of values (typically beta values between 0 and 1).} + \item{alpha}{A small positive numeric offset (default is \code{1e-5}) added to both the numerator and denominator in the logit transform.} } -\value{A numeric vector.} +\value{A numeric vector of transformed values.} \author{ Kasper Daniel Hansen \email{khansen@jhsph.edu}. } \examples{ -logit2(c(0.25, 0.5, 0.75)) + logit2(c(0.25, 0.5, 0.75)) }