logit function

Logit and Inverse-Logit Functions

Logit and Inverse-Logit Functions

Transform values to and from the logit scale. logit() calculates

logit(p) invlogit(x)

Arguments

  • p: Values in the interval [0, 1]. Can be an atomic vector, a matrix, or an rvec .
  • x: Values in the interval (-Inf, Inf). Can be an atomic vector, a matrix, or an rvec .

Returns

  • A vector of doubles, if p or x is a vector.
  • A matrix of doubles, if p or x is a matrix.
  • An object of class rvec_dbl, if p or x is an rvec.

Details

x=log(p1p) x = \log \left(\frac{p}{1 - p}\right)

and invlogit() calculates

p=ex1+ex p = \frac{e^x}{1 + e^x}

To avoid overflow, invlogit()

uses p=11+exp = \frac{1}{1 + e^{-x}}

internally for xx where x>0x > 0.

In some of the demographic literature, the logit function is defined as

x=12log(p1p). x = \frac{1}{2} \log \left(\frac{p}{1 - p}\right).

logit() and invlogit() follow the conventions in statistics and machine learning, and omit the 12\frac{1}{2}.

Examples

p <- c(0.5, 1, 0.2) logit(p) invlogit(logit(p))