Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
19 changes: 10 additions & 9 deletions man/logit2.Rd
Original file line number Diff line number Diff line change
@@ -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{[email protected]}.
}
\examples{
logit2(c(0.25, 0.5, 0.75))
logit2(c(0.25, 0.5, 0.75))
}