Learn R Programming

LCPA (version 1.0.0)

logit: Compute the Logistic (Sigmoid) Function

Description

This function computes the logistic (also known as sigmoid) transformation of the input. The logistic function maps real-valued numbers to the open interval (0, 1), and is widely used in machine learning, statistical modeling (e.g., logistic regression), and neural networks as an activation function or link function.

Usage

logit(x)

Value

A numeric object of the same dimension as x, where each element is the logistic transformation of the corresponding input:

  • If x = 0, returns 0.5

  • As x -> Inf, output approaches 1

  • As x -> -Inf, output approaches 0

  • NA values remain NA

Arguments

x

A numeric vector, matrix, or array. Accepts any real number, including Inf and -Inf. Missing values (NA) are preserved.

Details

The logistic function is defined as: $$ \mathrm{logit}^{-1}(x) = \frac{1}{1 + e^{-x}} $$

Note: Despite the name "logit", this function actually computes the inverse logit (i.e., the logistic function). The true logit function is the inverse: \(\log(p / (1 - p))\). However, in many applied contexts—especially in software—the term "logit" is sometimes informally used to refer to the sigmoid. For clarity, this implementation follows the conventional definition of the logistic/sigmoid function.

Examples

Run this code
logit(0)        # 0.5
logit(c(-Inf, 0, Inf))  # c(0, 0.5, 1)
logit(c(-2, -1, 0, 1, 2))

Run the code above in your browser using DataLab