Learn R Programming

rje (version 1.12.1)

expit: Expit and Logit.

Description

Functions to take the expit and logit of numerical vectors.

Usage

expit(x)

logit(x)

Value

A real vector corresponding to the expits or logits of x

Arguments

x

vector of real numbers; for logit to return a sensible value these should be between 0 and 1.

Functions

  • logit: logit function

Warning

Choosing very large (positive or negative) values to apply to expit may result in inaccurate inversion (see example below).

Author

Robin Evans

Details

logit implements the usual logit function, which is $$logit(x) = \log\frac{x}{1-x},$$ and expit its inverse: $$expit(x) = \frac{e^x}{1+e^x}.$$ It is assumed that logit(0) = -Inf and logit(1) = Inf, and correspondingly for expit.

Examples

Run this code

x = c(5, -2, 0.1)
y = expit(x)
logit(y)

# Beware large values!
logit(expit(100))

Run the code above in your browser using DataLab